1package lsp
2
3import (
4 "context"
5 "testing"
6
7 "github.com/charmbracelet/crush/internal/config"
8)
9
10func TestPowernapClient(t *testing.T) {
11 ctx := context.Background()
12
13 // Create a simple config for testing
14 var cfg config.Config
15 lspCfg := config.LSPConfig{
16 Command: "echo", // 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, &cfg, "test", lspCfg)
25 if err != nil {
26 // Expected to fail with echo command, skip the rest
27 t.Skipf("Powernap client creation failed as expected with dummy command: %v", err)
28 return
29 }
30
31 // If we get here, test basic interface methods
32 if client.GetName() != "test" {
33 t.Errorf("Expected name 'test', got '%s'", client.GetName())
34 }
35
36 if !client.HandlesFile("test.go") {
37 t.Error("Expected client to handle .go files")
38 }
39
40 if client.HandlesFile("test.py") {
41 t.Error("Expected client to not handle .py files")
42 }
43
44 // Test server state
45 client.SetServerState(StateReady)
46 if client.GetServerState() != StateReady {
47 t.Error("Expected server state to be StateReady")
48 }
49
50 // Clean up - expect this to fail with echo command
51 if err := client.Close(t.Context()); err != nil {
52 // Expected to fail with echo command
53 t.Logf("Close failed as expected with dummy command: %v", err)
54 }
55}