diff options
author | Maria José Solano <majosolano99@gmail.com> | 2023-10-14 00:06:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 09:06:40 +0200 |
commit | ee156ca60ede95c95160cb8dff0197d40cb1a491 (patch) | |
tree | cc2049fa17b7d12145a528bff49532571bd8b6bd /test/functional/plugin/lsp/snippet_spec.lua | |
parent | 8ee8112b92425cec6c8b3053e73a858148c3b9fe (diff) | |
download | rneovim-ee156ca60ede95c95160cb8dff0197d40cb1a491.tar.gz rneovim-ee156ca60ede95c95160cb8dff0197d40cb1a491.tar.bz2 rneovim-ee156ca60ede95c95160cb8dff0197d40cb1a491.zip |
fix(lsp): refactor escaping snippet text (#25611)
Diffstat (limited to 'test/functional/plugin/lsp/snippet_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp/snippet_spec.lua | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua index 13df861b91..ba8bc7fe04 100644 --- a/test/functional/plugin/lsp/snippet_spec.lua +++ b/test/functional/plugin/lsp/snippet_spec.lua @@ -1,5 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local snippet = require('vim.lsp._snippet_grammar') +local type = snippet.NodeType local eq = helpers.eq local exec_lua = helpers.exec_lua @@ -15,28 +16,28 @@ describe('vim.lsp._snippet_grammar', function() it('parses only text', function() eq({ - { type = snippet.NodeType.Text, data = { text = 'TE$}XT' } }, + { type = type.Text, data = { text = 'TE$}XT' } }, }, parse('TE\\$\\}XT')) end) it('parses tabstops', function() eq({ - { type = snippet.NodeType.Tabstop, data = { tabstop = 1 } }, - { type = snippet.NodeType.Tabstop, data = { tabstop = 2 } }, + { type = type.Tabstop, data = { tabstop = 1 } }, + { type = type.Tabstop, data = { tabstop = 2 } }, }, parse('$1${2}')) end) it('parses nested placeholders', function() eq({ { - type = snippet.NodeType.Placeholder, + type = type.Placeholder, data = { tabstop = 1, value = { - type = snippet.NodeType.Placeholder, + type = type.Placeholder, data = { tabstop = 2, - value = { type = snippet.NodeType.Tabstop, data = { tabstop = 3 } }, + value = { type = type.Tabstop, data = { tabstop = 3 } }, }, }, }, @@ -46,24 +47,24 @@ describe('vim.lsp._snippet_grammar', function() it('parses variables', function() eq({ - { type = snippet.NodeType.Variable, data = { name = 'VAR' } }, - { type = snippet.NodeType.Variable, data = { name = 'VAR' } }, + { type = type.Variable, data = { name = 'VAR' } }, + { type = type.Variable, data = { name = 'VAR' } }, { - type = snippet.NodeType.Variable, + type = type.Variable, data = { name = 'VAR', - default = { type = snippet.NodeType.Tabstop, data = { tabstop = 1 } }, + default = { type = type.Tabstop, data = { tabstop = 1 } }, }, }, { - type = snippet.NodeType.Variable, + type = type.Variable, data = { name = 'VAR', regex = 'regex', options = '', format = { { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, modifier = 'upcase' }, }, }, @@ -75,7 +76,7 @@ describe('vim.lsp._snippet_grammar', function() it('parses choice', function() eq({ { - type = snippet.NodeType.Choice, + type = type.Choice, data = { tabstop = 1, values = { ',', '|' } }, }, }, parse('${1|\\,,\\||}')) @@ -85,30 +86,30 @@ describe('vim.lsp._snippet_grammar', function() eq( { { - type = snippet.NodeType.Variable, + type = type.Variable, data = { name = 'VAR', regex = 'regex', options = '', format = { { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, modifier = 'upcase' }, }, { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, if_text = 'if_text' }, }, { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, else_text = 'else_text' }, }, { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, if_text = 'if_text', else_text = 'else_text' }, }, { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, else_text = 'else_text' }, }, }, @@ -124,24 +125,24 @@ describe('vim.lsp._snippet_grammar', function() it('parses empty strings', function() eq({ { - type = snippet.NodeType.Placeholder, + type = type.Placeholder, data = { tabstop = 1, - value = { type = snippet.NodeType.Text, data = { text = '' } }, + value = { type = type.Text, data = { text = '' } }, }, }, { - type = snippet.NodeType.Text, + type = type.Text, data = { text = ' ' }, }, { - type = snippet.NodeType.Variable, + type = type.Variable, data = { name = 'VAR', regex = 'erg', format = { { - type = snippet.NodeType.Format, + type = type.Format, data = { capture = 1, if_text = '' }, }, }, @@ -150,4 +151,21 @@ describe('vim.lsp._snippet_grammar', function() }, }, parse('${1:} ${VAR/erg/${1:+}/g}')) end) + + it('parses closing curly brace as text', function() + eq( + { + { type = type.Text, data = { text = 'function ' } }, + { type = type.Tabstop, data = { tabstop = 1 } }, + { type = type.Text, data = { text = '() {\n ' } }, + { type = type.Tabstop, data = { tabstop = 0 } }, + { type = type.Text, data = { text = '\n}' } }, + }, + parse(table.concat({ + 'function $1() {', + ' $0', + '}', + }, '\n')) + ) + end) end) |