From c628b01a1a62df007ab85e8a9f733b9ff917dd89 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 2 Nov 2024 09:42:33 +0100 Subject: [PATCH] fix: fix hover test with result nil --- internal/handler/hover_main_test.go | 7 +++-- internal/util/goccy_yaml_test.go | 45 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 internal/util/goccy_yaml_test.go diff --git a/internal/handler/hover_main_test.go b/internal/handler/hover_main_test.go index bcbcfd5..54bda92 100644 --- a/internal/handler/hover_main_test.go +++ b/internal/handler/hover_main_test.go @@ -202,10 +202,11 @@ func TestHoverMain(t *testing.T) { }, }) assert.Equal(t, tt.expectedError, err) - if result == nil { - t.Fatal("Result is nil") + if tt.expected == "" { + assert.Nil(t, result) + } else { + assert.Equal(t, tt.expected, strings.ReplaceAll(result.Contents.Value, "\r\n", "\n")) } - assert.Equal(t, tt.expected, strings.ReplaceAll(result.Contents.Value, "\r\n", "\n")) }) } } diff --git a/internal/util/goccy_yaml_test.go b/internal/util/goccy_yaml_test.go new file mode 100644 index 0000000..411f5bf --- /dev/null +++ b/internal/util/goccy_yaml_test.go @@ -0,0 +1,45 @@ +package util + +import ( + "testing" + + "github.com/goccy/go-yaml/lexer" + "github.com/goccy/go-yaml/parser" +) + +var brokenYaml = ` +this: isSomeYmal +imCurrentlyTypinghere: dsa +baz: + imCurrentlyTypinghere + isNested: Yaml +baz2: + with: Brokf +` + +func TestLexer(t *testing.T) { + got := lexer.Tokenize(brokenYaml) + + for _, token := range got { + t.Log(token.Type, token.Position.String()) + } + + t.Log(got) + t.Fail() +} + +func TestParser(t *testing.T) { + tokens := lexer.Tokenize(brokenYaml) + got, err := parser.Parse(tokens, parser.ParseComments) + if got == nil { + t.Fatal(err) + } + + nodes := got.Docs + + for _, node := range nodes { + t.Log(node.Type(), node.String()) + } + + t.Fail() +}