1package lsp
 2
 3import (
 4	"context"
 5	"testing"
 6
 7	"github.com/charmbracelet/crush/internal/config"
 8	"github.com/charmbracelet/crush/internal/env"
 9)
10
11func TestClient(t *testing.T) {
12	ctx := context.Background()
13
14	// Create a simple config for testing
15	cfg := config.LSPConfig{
16		Command:   "$THE_CMD", // Use echo as a dummy command that won't fail
17		Args:      []string{"hello"},
18		FileTypes: []string{"go"},
19		Env:       map[string]string{},
20	}
21
22	// Test creating a powernap client - this will likely fail with echo
23	// but we can still test the basic structure
24	client, err := New(ctx, "test", cfg, config.NewEnvironmentVariableResolver(env.NewFromMap(map[string]string{
25		"THE_CMD": "echo",
26	})))
27	if err != nil {
28		// Expected to fail with echo command, skip the rest
29		t.Skipf("Powernap client creation failed as expected with dummy command: %v", err)
30		return
31	}
32
33	// If we get here, test basic interface methods
34	if client.GetName() != "test" {
35		t.Errorf("Expected name 'test', got '%s'", client.GetName())
36	}
37
38	if !client.HandlesFile("test.go") {
39		t.Error("Expected client to handle .go files")
40	}
41
42	if client.HandlesFile("test.py") {
43		t.Error("Expected client to not handle .py files")
44	}
45
46	// Test server state
47	client.SetServerState(StateReady)
48	if client.GetServerState() != StateReady {
49		t.Error("Expected server state to be StateReady")
50	}
51
52	// Clean up - expect this to fail with echo command
53	if err := client.Close(t.Context()); err != nil {
54		// Expected to fail with echo command
55		t.Logf("Close failed as expected with dummy command: %v", err)
56	}
57}