diff options
Diffstat (limited to 'tests/indent')
| -rw-r--r-- | tests/indent/common.lua | 32 | ||||
| -rw-r--r-- | tests/indent/typst/call.typ | 14 | ||||
| -rw-r--r-- | tests/indent/typst/for.typ | 8 | ||||
| -rw-r--r-- | tests/indent/typst/if.typ | 15 | ||||
| -rw-r--r-- | tests/indent/typst/let.typ | 13 | ||||
| -rw-r--r-- | tests/indent/typst/set.typ | 9 | ||||
| -rw-r--r-- | tests/indent/typst/show.typ | 7 | ||||
| -rw-r--r-- | tests/indent/typst_spec.lua | 12 |
8 files changed, 95 insertions, 15 deletions
diff --git a/tests/indent/common.lua b/tests/indent/common.lua index 6add58c7f..ccc126870 100644 --- a/tests/indent/common.lua +++ b/tests/indent/common.lua @@ -2,12 +2,10 @@ local M = {} local assert = require('luassert') local say = require('say') -local scan_dir = require('plenary.scandir').scan_dir -local Path = require('plenary.path') M.XFAIL = 'xfail' -local function same_indent(state, arguments) +local function same_indent(_, arguments) local before = arguments[1] local after = arguments[2] @@ -166,7 +164,7 @@ Runner.__index = Runner function Runner:new(it, base_dir, buf_opts) local runner = {} runner.it = it - runner.base_dir = Path:new(base_dir) + runner.base_dir = base_dir runner.buf_opts = buf_opts return setmetatable(runner, self) end @@ -175,19 +173,23 @@ function Runner:whole_file(dirs, opts) opts = opts or {} local expected_failures = opts.expected_failures or {} expected_failures = vim.tbl_map(function(f) - return Path:new(f):make_relative(self.base_dir.filename) + return vim.fs.normalize(vim.fs.joinpath(self.base_dir, f)) end, expected_failures) dirs = type(dirs) == 'table' and dirs or { dirs } dirs = vim.tbl_map(function(dir) - dir = self.base_dir / Path:new(dir) - assert.is.same(1, vim.fn.isdirectory(dir.filename)) - return dir.filename + dir = vim.fs.normalize(vim.fs.joinpath(self.base_dir, dir)) + assert.is.same(1, vim.fn.isdirectory(dir)) + return dir end, dirs) - local files = vim.iter(vim.tbl_map(scan_dir, dirs)):flatten():totable() - for _, file in ipairs(files) do - local relpath = Path:new(file):make_relative(self.base_dir.filename) - self.it(relpath, function() - M.indent_whole_file(file, self.buf_opts, vim.tbl_contains(expected_failures, relpath)) + local scandir = function(dir) + return vim.fs.find(function() + return true + end, { path = dir, limit = math.huge }) + end + local files = vim.iter(dirs):map(scandir):flatten() + for _, file in files:enumerate() do + self.it(file, function() + M.indent_whole_file(file, self.buf_opts, vim.tbl_contains(expected_failures, file)) end) end end @@ -195,8 +197,8 @@ end function Runner:new_line(file, spec, title, xfail) title = title and title or tostring(spec.on_line) self.it(string.format('%s[%s]', file, title), function() - local path = self.base_dir / file - M.indent_new_line(path.filename, spec, self.buf_opts, xfail) + local path = vim.fs.joinpath(self.base_dir, file) + M.indent_new_line(path, spec, self.buf_opts, xfail) end) end diff --git a/tests/indent/typst/call.typ b/tests/indent/typst/call.typ new file mode 100644 index 000000000..f0a64c97a --- /dev/null +++ b/tests/indent/typst/call.typ @@ -0,0 +1,14 @@ +#foo( + arg1, + arg2, +) + +#bar[ + content here +] + +#baz( + inner( + nested, + ), +) diff --git a/tests/indent/typst/for.typ b/tests/indent/typst/for.typ new file mode 100644 index 000000000..95fe60e9a --- /dev/null +++ b/tests/indent/typst/for.typ @@ -0,0 +1,8 @@ +#for x in (1, 2, 3) { + x +} + +#for x in (1, 2, 3) { + let y = x + 1 + y +} diff --git a/tests/indent/typst/if.typ b/tests/indent/typst/if.typ new file mode 100644 index 000000000..41bbaa4c1 --- /dev/null +++ b/tests/indent/typst/if.typ @@ -0,0 +1,15 @@ +#if true { + "this is one leve" +} + +#set page(header: { + if true { + "this is internal on level" + } +}) + +#if true { + if false { + "this is it" + } +} diff --git a/tests/indent/typst/let.typ b/tests/indent/typst/let.typ new file mode 100644 index 000000000..fa0c374c6 --- /dev/null +++ b/tests/indent/typst/let.typ @@ -0,0 +1,13 @@ +#let foo( + x, + y, +) = x + y + +#let bar = { + let x = 1 + x +} + +#let baz(x) = { + x + 1 +} diff --git a/tests/indent/typst/set.typ b/tests/indent/typst/set.typ new file mode 100644 index 000000000..861b2f95e --- /dev/null +++ b/tests/indent/typst/set.typ @@ -0,0 +1,9 @@ +#set text( + size: 12pt, + font: "Arial", +) + +#set page( + width: 210mm, + height: 297mm, +) diff --git a/tests/indent/typst/show.typ b/tests/indent/typst/show.typ new file mode 100644 index 000000000..3947b66c6 --- /dev/null +++ b/tests/indent/typst/show.typ @@ -0,0 +1,7 @@ +#show heading: it => { + it +} + +#show link: it => { + underline(it) +} diff --git a/tests/indent/typst_spec.lua b/tests/indent/typst_spec.lua new file mode 100644 index 000000000..81540405f --- /dev/null +++ b/tests/indent/typst_spec.lua @@ -0,0 +1,12 @@ +local Runner = require('tests.indent.common').Runner + +local run = Runner:new(it, 'tests/indent/typst', { + tabstop = 4, + shiftwidth = 4, + softtabstop = 4, + expandtab = false, +}) + +describe('indent typst:', function() + run:whole_file('.') +end) |
