Files
MonocoEditor-With-Lsp-Backend/backend/internal/lsp/client_test.go
meowrain 3284ce07c7 feat: enhance API and session management with Nacos and Redis integration
- Add Nacos registry for service registration and deregistration.
- Implement Redis registry for session management with heartbeat and session claiming.
- Improve completion service with session handling and request validation.
- Enhance WebSocket handling for completion requests with JSON-RPC support.
- Add tests for new registry implementations and completion manager functionalities.
- Refactor existing code for better readability and maintainability.
2026-02-15 17:46:34 +08:00

51 lines
1.2 KiB
Go

package lsp
import (
"path/filepath"
"testing"
)
func TestNormalizeURIRebasesRelativeFileURI(t *testing.T) {
workspace, err := filepath.Abs(filepath.Join("testdata", "ws"))
if err != nil {
t.Fatalf("filepath.Abs() error = %v", err)
}
client := &Client{workspaceDir: workspace}
got, err := client.normalizeURI("file:///main.go")
if err != nil {
t.Fatalf("normalizeURI() error = %v", err)
}
want, err := pathToURI(filepath.Join(workspace, "main.go"))
if err != nil {
t.Fatalf("pathToURI() error = %v", err)
}
if got != want {
t.Fatalf("normalizeURI() = %q, want %q", got, want)
}
}
// 绝对 file URI 不应被重写。
func TestNormalizeURIKeepsAbsoluteFileURI(t *testing.T) {
workspace, err := filepath.Abs(filepath.Join("testdata", "ws"))
if err != nil {
t.Fatalf("filepath.Abs() error = %v", err)
}
client := &Client{workspaceDir: workspace}
absPath := filepath.Join(workspace, "demo.go")
uri, err := pathToURI(absPath)
if err != nil {
t.Fatalf("pathToURI() error = %v", err)
}
got, err := client.normalizeURI(uri)
if err != nil {
t.Fatalf("normalizeURI() error = %v", err)
}
if got != uri {
t.Fatalf("normalizeURI() = %q, want %q", got, uri)
}
}