File: test-combinators.lua

package info (click to toggle)
vim-vimtex 2.16-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,660 kB
  • sloc: makefile: 367; python: 103
file content (28 lines) | stat: -rw-r--r-- 721 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
vim.opt.runtimepath:prepend "../.."
vim.cmd [[filetype plugin on]]

local pc = require "vimtex.parser.combinators"
local g = require "vimtex.parser.general"

-- Test operators
local concatenated = (g.letter .. g.digit):run "a4"
local added = (g.letter + g.digit):run "a4"
vim.fn.assert_equal("a4", concatenated.result)
vim.fn.assert_equal({ "a", "4" }, added.result)

-- Test recursives with lazy
local group_exc
group_exc = pc.sequence_flat {
  g.lb,
  pc.many_flat(pc.choice {
    g.letters,
    pc.lazy(function()
      return group_exc
    end),
  }),
  g.rb,
}
local group_exc_result = group_exc:run "{foo{bar}baz}more"
vim.fn.assert_equal("{foo{bar}baz}", group_exc_result.result)

vim.fn["vimtex#test#finished"]()