diff options
author | Dan Willemsen <dwillemsen@google.com> | 2023-03-15 13:19:36 -0400 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2023-03-15 14:18:08 -0400 |
commit | 09c5a32afc5b66f28f166a68afe1fc71afbf9b73 (patch) | |
tree | 194d7b0e539d014393564a256bec571e18d6533a /gopls/internal/lsp/snippet/snippet_builder_test.go | |
parent | f10932f763d058b0dcb3acfb795c869996fef47b (diff) | |
parent | 031fc75960d487b0b15db12fb328676236a3a39c (diff) | |
download | golang-x-tools-master.tar.gz |
Not using external_updater this time to switch to the new upstream tags.
Test: treehugger
Change-Id: I31488b4958a366ed7f183bb387d3e1446acc13ae
Diffstat (limited to 'gopls/internal/lsp/snippet/snippet_builder_test.go')
-rw-r--r-- | gopls/internal/lsp/snippet/snippet_builder_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gopls/internal/lsp/snippet/snippet_builder_test.go b/gopls/internal/lsp/snippet/snippet_builder_test.go new file mode 100644 index 000000000..bc814b16d --- /dev/null +++ b/gopls/internal/lsp/snippet/snippet_builder_test.go @@ -0,0 +1,62 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package snippet + +import ( + "testing" +) + +func TestSnippetBuilder(t *testing.T) { + expect := func(expected string, fn func(*Builder)) { + t.Helper() + + var b Builder + fn(&b) + if got := b.String(); got != expected { + t.Errorf("got %q, expected %q", got, expected) + } + } + + expect("", func(b *Builder) {}) + + expect(`hi { \} \$ | " , / \\`, func(b *Builder) { + b.WriteText(`hi { } $ | " , / \`) + }) + + expect("${1:}", func(b *Builder) { + b.WritePlaceholder(nil) + }) + + expect("hi ${1:there}", func(b *Builder) { + b.WriteText("hi ") + b.WritePlaceholder(func(b *Builder) { + b.WriteText("there") + }) + }) + + expect(`${1:id=${2:{your id\}}}`, func(b *Builder) { + b.WritePlaceholder(func(b *Builder) { + b.WriteText("id=") + b.WritePlaceholder(func(b *Builder) { + b.WriteText("{your id}") + }) + }) + }) + + expect(`${1|one,{ \} \$ \| " \, / \\,three|}`, func(b *Builder) { + b.WriteChoice([]string{"one", `{ } $ | " , / \`, "three"}) + }) + + expect("$0 hello", func(b *Builder) { + b.WriteFinalTabstop() + b.WriteText(" hello") + }) + + expect(`prepended \$5 ${1:} hello`, func(b *Builder) { + b.WritePlaceholder(nil) + b.WriteText(" hello") + b.PrependText("prepended $5 ") + }) +} |