MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestSourceInfoRenumberIDs

Function TestSourceInfoRenumberIDs

common/ast/ast_test.go:460–495  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

458}
459
460func TestSourceInfoRenumberIDs(t *testing.T) {
461 info := ast.NewSourceInfo(nil)
462 for old := int64(1); old <= 5; old++ {
463 info.SetOffsetRange(old, ast.OffsetRange{Start: int32(old), Stop: int32(old) + 1})
464 }
465 original := make(map[int64]ast.OffsetRange)
466 maps.Copy(original, info.OffsetRanges())
467
468 // Verify the renumbering is stable.
469 var next int64 = 101
470 idMap := make(map[int64]int64)
471 idGen := func(old int64) int64 {
472 if _, found := idMap[old]; !found {
473 idMap[old] = next
474 next = next + 1
475 }
476 return idMap[old]
477 }
478 info.RenumberIDs(idGen)
479
480 if len(info.OffsetRanges()) != 5 {
481 t.Errorf("got %d offset ranges, wanted 5", len(info.OffsetRanges()))
482 }
483
484 for old := int64(1); old <= 5; old++ {
485 want := original[old]
486 new := old + 100
487 got, found := info.GetOffsetRange(new)
488 if !found {
489 t.Errorf("offset range for ID %d not found", new)
490 }
491 if got != want {
492 t.Errorf("offset range for ID %d incorrect; got %v, want %v", new, got, want)
493 }
494 }
495}

Callers

nothing calls this directly

Calls 6

SetOffsetRangeMethod · 0.95
OffsetRangesMethod · 0.95
RenumberIDsMethod · 0.95
GetOffsetRangeMethod · 0.95
NewSourceInfoFunction · 0.92
CopyMethod · 0.65

Tested by

no test coverage detected