From ddb587ac9fab515e84e0fd99e1850cca984059a8 Mon Sep 17 00:00:00 2001 From: Duologic Date: Thu, 7 Mar 2024 14:41:00 +0100 Subject: [PATCH] test(completion): quote labels --- pkg/server/completion_test.go | 77 +++++++++++++++++++++++++ pkg/server/testdata/quote_label.jsonnet | 7 +++ 2 files changed, 84 insertions(+) create mode 100644 pkg/server/testdata/quote_label.jsonnet diff --git a/pkg/server/completion_test.go b/pkg/server/completion_test.go index 92855d7..fa85eb9 100644 --- a/pkg/server/completion_test.go +++ b/pkg/server/completion_test.go @@ -586,6 +586,83 @@ func TestCompletion(t *testing.T) { }, }, }, + { + name: "quote label", + filename: "testdata/quote_label.jsonnet", + replaceString: "lib", + replaceByString: "lib.", + expected: protocol.CompletionList{ + IsIncomplete: false, + Items: []protocol.CompletionItem{ + { + Label: "1num", + Kind: protocol.FieldCompletion, + Detail: "lib['1num']", + InsertText: "['1num']", + LabelDetails: protocol.CompletionItemLabelDetails{ + Description: "string", + }, + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 0, + Character: 9, + }, + End: protocol.Position{ + Line: 0, + Character: 10, + }, + }, + NewText: "['1num']", + }, + }, + { + Label: "abc#func", + Kind: protocol.FunctionCompletion, + Detail: "lib['abc#func'](param)", + InsertText: "['abc#func'](param)", + LabelDetails: protocol.CompletionItemLabelDetails{ + Description: "function", + }, + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 0, + Character: 9, + }, + End: protocol.Position{ + Line: 0, + Character: 10, + }, + }, + NewText: "['abc#func'](param)", + }, + }, + { + Label: "abc#var", + Kind: protocol.FieldCompletion, + Detail: "lib['abc#var']", + InsertText: "['abc#var']", + LabelDetails: protocol.CompletionItemLabelDetails{ + Description: "string", + }, + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 0, + Character: 9, + }, + End: protocol.Position{ + Line: 0, + Character: 10, + }, + }, + NewText: "['abc#var']", + }, + }, + }, + }, + }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/server/testdata/quote_label.jsonnet b/pkg/server/testdata/quote_label.jsonnet new file mode 100644 index 0000000..9cde847 --- /dev/null +++ b/pkg/server/testdata/quote_label.jsonnet @@ -0,0 +1,7 @@ +local lib = { + '1num': 'val', + 'abc#func'(param=1): param, + 'abc#var': 'val', +}; + +lib