aboutsummaryrefslogtreecommitdiff
path: root/test/functional/script/luacats_grammar_spec.lua
diff options
context:
space:
mode:
authorJames Trew <66286082+jamestrew@users.noreply.github.com>2024-10-03 10:45:51 +0000
committerGitHub <noreply@github.com>2024-10-03 03:45:51 -0700
commit385fbfb3e739b457027b469782678f86eefdf7fc (patch)
tree8e604da45cc3f172e60904631da5d16c64debee5 /test/functional/script/luacats_grammar_spec.lua
parentc6abc97006eee7fc89baefad2e1bddb248187f2e (diff)
downloadrneovim-385fbfb3e739b457027b469782678f86eefdf7fc.tar.gz
rneovim-385fbfb3e739b457027b469782678f86eefdf7fc.tar.bz2
rneovim-385fbfb3e739b457027b469782678f86eefdf7fc.zip
docs: improve luacats support #30580
Some composite/compound types even as basic as `(string|number)[]` are not currently supported by the luacats LPEG grammar used by gen_vimdoc. It would be parsed & rendered as just `string|number`. Changeset adds better support for these types.
Diffstat (limited to 'test/functional/script/luacats_grammar_spec.lua')
-rw-r--r--test/functional/script/luacats_grammar_spec.lua118
1 files changed, 118 insertions, 0 deletions
diff --git a/test/functional/script/luacats_grammar_spec.lua b/test/functional/script/luacats_grammar_spec.lua
index 9c6417f7bf..8bc55879d4 100644
--- a/test/functional/script/luacats_grammar_spec.lua
+++ b/test/functional/script/luacats_grammar_spec.lua
@@ -166,4 +166,122 @@ describe('luacats grammar', function()
name = 'type',
type = '[number,string,"good"|"bad"]',
})
+
+ test('@class vim.diagnostic.JumpOpts', {
+ kind = 'class',
+ name = 'vim.diagnostic.JumpOpts',
+ })
+
+ test('@class vim.diagnostic.JumpOpts : vim.diagnostic.GetOpts', {
+ kind = 'class',
+ name = 'vim.diagnostic.JumpOpts',
+ parent = 'vim.diagnostic.GetOpts',
+ })
+
+ test('@param opt? { cmd?: string[] } Options', {
+ kind = 'param',
+ name = 'opt?',
+ type = '{ cmd?: string[] }',
+ desc = 'Options',
+ })
+
+ ---@type [string, string?][]
+ local test_cases = {
+ { 'foo' },
+ { 'foo ', 'foo' }, -- trims whitespace
+ { 'true' },
+ { 'vim.type' },
+ { 'vim-type' },
+ { 'vim_type' },
+ { 'foo.bar-baz_baz' },
+ { '`ABC`' },
+ { '42' },
+ { '-42' },
+ { '(foo)', 'foo' }, -- removes unnecessary parens
+ { 'true?' },
+ { '(true)?' },
+ { 'string[]' },
+ { 'string|number' },
+ { '(string)[]' },
+ { '(string|number)[]' },
+ { 'coalesce??', 'coalesce?' }, -- removes unnecessary ?
+ { 'number?|string' },
+ { "'foo'|'bar'|'baz'" },
+ { '"foo"|"bar"|"baz"' },
+ { '(number)?|string' }, --
+ { 'number[]|string' },
+ { 'string[]?' },
+ { 'foo?[]' },
+ { 'vim.type?|string? ', 'vim.type?|string?' },
+ { 'number[][]' },
+ { 'number[][][]' },
+ { 'number[][]?' },
+ { 'string|integer[][]?' },
+
+ -- tuples
+ { '[string]' },
+ { '[1]' },
+ { '[string, number]' },
+ { '[string, number]?' },
+ { '[string, number][]' },
+ { '[string, number]|string' },
+ { '[string|number, number?]' },
+ { 'string|[string, number]' },
+ { '(true)?|[foo]' },
+ { '[fun(a: string):boolean]' },
+
+ -- dict
+ { '{[string]:string}' },
+ { '{ [ string ] : string }' },
+ { '{ [ string|any ] : string }' },
+ { '{[string]: string, [number]: boolean}' },
+
+ -- key-value table
+ { 'table<string,any>' },
+ { 'table' },
+ { 'string|table|boolean' },
+ { 'string|table|(boolean)' },
+
+ -- table literal
+ { '{foo: number}' },
+ { '{foo: string, bar: [number, boolean]?}' },
+ { 'boolean|{reverse?:boolean}' },
+ { '{ cmd?: string[] }' },
+
+ -- function
+ { 'fun(a: string, b:foo|bar): string' },
+ { 'fun(a?: string): string' },
+ { 'fun(a?: string): number?,string?' },
+ { '(fun(a: string, b:foo|bar): string)?' },
+ { 'fun(a: string, b:foo|bar): string, string' },
+ { 'fun(a: string, b:foo|bar)' },
+ { 'fun(_, foo, bar): string' },
+ { 'fun(...): number' },
+ { 'fun( ... ): number' },
+ { 'fun(...:number): number' },
+ { 'fun( ... : number): number' },
+
+ -- generics
+ { 'elem_or_list<string>' },
+ {
+ 'elem_or_list<fun(client: vim.lsp.Client, initialize_result: lsp.InitializeResult)>',
+ nil,
+ },
+ }
+
+ for _, tc in ipairs(test_cases) do
+ local ty, exp_ty = tc[1], tc[2]
+ if exp_ty == nil then
+ exp_ty = ty
+ end
+
+ local var, desc = 'x', 'some desc'
+ local param = string.format('@param %s %s %s', var, ty, desc)
+ test(param, {
+ kind = 'param',
+ name = var,
+ type = exp_ty,
+ desc = desc,
+ })
+ end
end)