MCPcopy
hub / github.com/MadAppGang/dingo / TestTranslatePositionDingoToGo

Function TestTranslatePositionDingoToGo

pkg/lsp/translator_test.go:62–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestTranslatePositionDingoToGo(t *testing.T) {
63 // Create source files
64 // Dingo:
65 // Line 1: "x := 10\n" (bytes 0-7)
66 // Line 2: "y := 20\n" (bytes 8-15)
67 // Go:
68 // Line 1: "x := 10\n" (bytes 0-7)
69 // Line 2: "y := 20\n" (bytes 8-15)
70 dingoSrc := "x := 10\ny := 20\n"
71 goSrc := "x := 10\ny := 20\n"
72
73 mappings := []sourcemap.LineMapping{
74 {DingoLine: 1, GoLineStart: 1, GoLineEnd: 1, Kind: "identity"},
75 {DingoLine: 2, GoLineStart: 2, GoLineEnd: 2, Kind: "identity"},
76 }
77
78 reader := createMockReader(t, dingoSrc, goSrc, mappings)
79 defer reader.Close()
80
81 goPath := "/test/file.go"
82 dingoPath := "/test/file.dingo"
83
84 cache := &mockSourceMapGetter{
85 readers: map[string]*dmap.Reader{
86 goPath: reader,
87 },
88 }
89
90 translator := NewTranslator(cache)
91
92 // Test translating first line from Dingo to Go
93 // Position in Dingo: line 1 (0-indexed=0), column 5 (0-indexed)
94 dingoURI := lspuri.File(dingoPath)
95 dingoPos := protocol.Position{Line: 0, Character: 5}
96
97 newURI, newPos, err := translator.TranslatePosition(dingoURI, dingoPos, DingoToGo)
98 if err != nil {
99 t.Fatalf("TranslatePosition failed: %v", err)
100 }
101
102 // Should return Go URI
103 expectedURI := lspuri.File(goPath)
104 if newURI != expectedURI {
105 t.Errorf("URI: got %s, want %s", newURI, expectedURI)
106 }
107
108 // Position should be within first line (mapped range)
109 if newPos.Line != 0 {
110 t.Errorf("Line: got %d, want 0", newPos.Line)
111 }
112}
113
114func TestTranslatePositionGoToDingo(t *testing.T) {
115 dingoSrc := "x := 10\ny := 20\n"

Callers

nothing calls this directly

Calls 7

TranslatePositionMethod · 0.95
createMockReaderFunction · 0.85
NewTranslatorFunction · 0.85
FileMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected