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

Function TestReaderGoLineToDingoLine

pkg/sourcemap/dmap/reader_test.go:230–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

228}
229
230func TestReaderGoLineToDingoLine(t *testing.T) {
231 dingoSrc := []byte("let x = 10\nlet y = 20\n")
232 goSrc := []byte("x := 10\ny := 20\n")
233
234 mappings := []sourcemap.LineMapping{
235 {DingoLine: 1, GoLineStart: 1, GoLineEnd: 1, Kind: "identifier"},
236 {DingoLine: 2, GoLineStart: 2, GoLineEnd: 2, Kind: "identifier"},
237 }
238
239 data := createTestDmap(t, dingoSrc, goSrc, mappings)
240 reader, err := OpenBytes(data)
241 if err != nil {
242 t.Fatalf("OpenBytes failed: %v", err)
243 }
244 defer reader.Close()
245
246 tests := []struct {
247 name string
248 goLine int
249 wantDingo int
250 }{
251 {"line 1", 1, 1},
252 {"line 2", 2, 2},
253 // Line 0 is invalid (1-indexed), should clamp to first line
254 {"unmapped line 0", 0, 1},
255 // Line 100 is beyond file (3 lines), should clamp using proportional mapping
256 {"unmapped line 100", 100, 3},
257 }
258
259 for _, tt := range tests {
260 t.Run(tt.name, func(t *testing.T) {
261 dingoLine, _ := reader.GoLineToDingoLine(tt.goLine)
262
263 if dingoLine != tt.wantDingo {
264 t.Errorf("GoLineToDingoLine(%d) = %d, want %d",
265 tt.goLine, dingoLine, tt.wantDingo)
266 }
267 })
268 }
269}
270
271func TestReaderMultipleKinds(t *testing.T) {
272 dingoSrc := []byte("let x = 10\nmatch y { A => 1 }\n")

Callers

nothing calls this directly

Calls 7

createTestDmapFunction · 0.85
OpenBytesFunction · 0.85
GoLineToDingoLineMethod · 0.80
FatalfMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected