aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin/lsp/snippet_spec.lua
diff options
context:
space:
mode:
authorhrsh7th <hrsh7th@gmail.com>2021-09-14 20:31:41 +0900
committerGitHub <noreply@github.com>2021-09-14 04:31:41 -0700
commit516775e9d84c5eda9c1d014ff052132737361d90 (patch)
tree640be5a4d36340039e9223ce00b19489e7e4ae28 /test/functional/plugin/lsp/snippet_spec.lua
parentb8cce77702777bb876b2cef7e28662cf4539265e (diff)
downloadrneovim-516775e9d84c5eda9c1d014ff052132737361d90.tar.gz
rneovim-516775e9d84c5eda9c1d014ff052132737361d90.tar.bz2
rneovim-516775e9d84c5eda9c1d014ff052132737361d90.zip
fix(lsp): correctly parse LSP snippets #15579
Fixes #15522
Diffstat (limited to 'test/functional/plugin/lsp/snippet_spec.lua')
-rw-r--r--test/functional/plugin/lsp/snippet_spec.lua152
1 files changed, 152 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua
new file mode 100644
index 0000000000..4e127743eb
--- /dev/null
+++ b/test/functional/plugin/lsp/snippet_spec.lua
@@ -0,0 +1,152 @@
+local helpers = require('test.functional.helpers')(after_each)
+local snippet = require('vim.lsp._snippet')
+
+local eq = helpers.eq
+local exec_lua = helpers.exec_lua
+
+describe('vim.lsp._snippet', function()
+ before_each(helpers.clear)
+ after_each(helpers.clear)
+
+ local parse = function(...)
+ return exec_lua('return require("vim.lsp._snippet").parse(...)', ...)
+ end
+
+ it('should parse only text', function()
+ eq({
+ type = snippet.NodeType.SNIPPET,
+ children = {
+ {
+ type = snippet.NodeType.TEXT,
+ raw = 'TE\\$\\}XT',
+ esc = 'TE$}XT'
+ }
+ }
+ }, parse('TE\\$\\}XT'))
+ end)
+
+ it('should parse tabstop', function()
+ eq({
+ type = snippet.NodeType.SNIPPET,
+ children = {
+ {
+ type = snippet.NodeType.TABSTOP,
+ tabstop = 1,
+ },
+ {
+ type = snippet.NodeType.TABSTOP,
+ tabstop = 2,
+ }
+ }
+ }, parse('$1${2}'))
+ end)
+
+ it('should parse placeholders', function()
+ eq({
+ type = snippet.NodeType.SNIPPET,
+ children = {
+ {
+ type = snippet.NodeType.PLACEHOLDER,
+ tabstop = 1,
+ children = {
+ {
+ type = snippet.NodeType.PLACEHOLDER,
+ tabstop = 2,
+ children = {
+ {
+ type = snippet.NodeType.TEXT,
+ raw = 'TE\\$\\}XT',
+ esc = 'TE$}XT'
+ },
+ {
+ type = snippet.NodeType.TABSTOP,
+ tabstop = 3,
+ },
+ {
+ type = snippet.NodeType.TABSTOP,
+ tabstop = 1,
+ transform = {
+ type = snippet.NodeType.TRANSFORM,
+ pattern = 'regex',
+ option = 'i',
+ format = {
+ {
+ type = snippet.NodeType.FORMAT,
+ capture_index = 1,
+ modifier = 'upcase'
+ }
+ }
+ },
+ },
+ {
+ type = snippet.NodeType.TEXT,
+ raw = 'TE\\$\\}XT',
+ esc = 'TE$}XT'
+ },
+ }
+ }
+ }
+ },
+ }
+ }, parse('${1:${2:TE\\$\\}XT$3${1/regex/${1:/upcase}/i}TE\\$\\}XT}}'))
+ end)
+
+ it('should parse variables', function()
+ eq({
+ type = snippet.NodeType.SNIPPET,
+ children = {
+ {
+ type = snippet.NodeType.VARIABLE,
+ name = 'VAR',
+ },
+ {
+ type = snippet.NodeType.VARIABLE,
+ name = 'VAR',
+ },
+ {
+ type = snippet.NodeType.VARIABLE,
+ name = 'VAR',
+ children = {
+ {
+ type = snippet.NodeType.TABSTOP,
+ tabstop = 1,
+ }
+ }
+ },
+ {
+ type = snippet.NodeType.VARIABLE,
+ name = 'VAR',
+ transform = {
+ type = snippet.NodeType.TRANSFORM,
+ pattern = 'regex',
+ format = {
+ {
+ type = snippet.NodeType.FORMAT,
+ capture_index = 1,
+ modifier = 'upcase',
+ }
+ }
+ }
+ },
+ }
+ }, parse('$VAR${VAR}${VAR:$1}${VAR/regex/${1:/upcase}/}'))
+ end)
+
+ it('should parse choice', function()
+ eq({
+ type = snippet.NodeType.SNIPPET,
+ children = {
+ {
+ type = snippet.NodeType.CHOICE,
+ tabstop = 1,
+ items = {
+ ',',
+ '|'
+ }
+ }
+ }
+ }, parse('${1|\\,,\\||}'))
+ end)
+
+end)
+