clerk/internal/lsp/config_test.go (view raw)
| 1 | package lsp |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "go.lsp.dev/protocol" |
| 7 | ) |
| 8 | |
| 9 | func TestConfig_Merge(t *testing.T) { |
| 10 | tests := map[string]struct { |
| 11 | in string |
| 12 | cfg, want Config |
| 13 | }{ |
| 14 | "if not set, uses default": {`{"semanticHighlighting": true}`, Config{}, Config{SemanticHighlighting: true}}, |
| 15 | "empty object keeps defaults": {`{}`, DefaultConfig, Config{SemanticHighlighting: true}}, |
| 16 | "nil settings keep defaults": {"", DefaultConfig, Config{SemanticHighlighting: true}}, |
| 17 | |
| 18 | "disables provided option": {`{"semanticHighlighting": false}`, DefaultConfig, Config{SemanticHighlighting: false}}, |
| 19 | "snake_case key": {`{"semantic_highlighting": false}`, DefaultConfig, Config{SemanticHighlighting: false}}, |
| 20 | "kebab-case key": {`{"semantic-highlighting": false}`, DefaultConfig, Config{SemanticHighlighting: false}}, |
| 21 | |
| 22 | "malformed settings ignored": {`{`, DefaultConfig, DefaultConfig}, |
| 23 | "non-object settings ignored": {`"clerk"`, DefaultConfig, DefaultConfig}, |
| 24 | "unknown fields ignored": {`{"lint": true}`, DefaultConfig, DefaultConfig}, |
| 25 | } |
| 26 | for name, tt := range tests { |
| 27 | t.Run(name, func(t *testing.T) { |
| 28 | tt.cfg.merge(protocol.LSPAny(tt.in)) |
| 29 | if tt.cfg != tt.want { |
| 30 | t.Errorf("merge(%q) = %+v, want %+v", tt.in, tt.cfg, tt.want) |
| 31 | } |
| 32 | }) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestServer_Intialize_config(t *testing.T) { |
| 37 | srv := NewServer("test") |
| 38 | res, err := srv.server.Initialize(t.Context(), &protocol.InitializeParams{ |
| 39 | InitializationOptions: protocol.LSPAny(`{"semanticHighlighting": false}`), |
| 40 | }) |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | if srv.server.semanticHighlightingEnabled() { |
| 45 | t.Error("semanticHighlighting=false in initializationOptions not applied") |
| 46 | } |
| 47 | if res.Capabilities.SemanticTokensProvider == nil { |
| 48 | t.Error("SemanticTokensProvider must always be advertised") |
| 49 | } |
| 50 | } |