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	var cfg config.Config
16	lspCfg := config.LSPConfig{
17		Command:   "$THE_CMD", // Use echo as a dummy command that won't fail
18		Args:      []string{"hello"},
19		FileTypes: []string{"go"},
20		Env:       map[string]string{},
21	}
22
23	// Test creating a powernap client - this will likely fail with echo
24	// but we can still test the basic structure
25	client, err := New(ctx, &cfg, "test", lspCfg, config.NewEnvironmentVariableResolver(env.NewFromMap(map[string]string{
26		"THE_CMD": "echo",
27	})))
28	if err != nil {
29		// Expected to fail with echo command, skip the rest
30		t.Skipf("Powernap client creation failed as expected with dummy command: %v", err)
31		return
32	}
33
34	// If we get here, test basic interface methods
35	if client.GetName() != "test" {
36		t.Errorf("Expected name 'test', got '%s'", client.GetName())
37	}
38
39	if !client.HandlesFile("test.go") {
40		t.Error("Expected client to handle .go files")
41	}
42
43	if client.HandlesFile("test.py") {
44		t.Error("Expected client to not handle .py files")
45	}
46
47	// Test server state
48	client.SetServerState(StateReady)
49	if client.GetServerState() != StateReady {
50		t.Error("Expected server state to be StateReady")
51	}
52
53	// Clean up - expect this to fail with echo command
54	if err := client.Close(t.Context()); err != nil {
55		// Expected to fail with echo command
56		t.Logf("Close failed as expected with dummy command: %v", err)
57	}
58}