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

Function TestSourceInfoRenumberIDs

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

Source from the content-addressed store, hash-verified

477}
478
479func TestSourceInfoRenumberIDs(t *testing.T) {
480 info := ast.NewSourceInfo(nil)
481 for old := int64(1); old <= 5; old++ {
482 info.SetOffsetRange(old, ast.OffsetRange{Start: int32(old), Stop: int32(old) + 1})
483 }
484 original := make(map[int64]ast.OffsetRange)
485 maps.Copy(original, info.OffsetRanges())
486
487 // Verify the renumbering is stable.
488 var next int64 = 101
489 idMap := make(map[int64]int64)
490 idGen := func(old int64) int64 {
491 if _, found := idMap[old]; !found {
492 idMap[old] = next
493 next = next + 1
494 }
495 return idMap[old]
496 }
497 info.RenumberIDs(idGen)
498
499 if len(info.OffsetRanges()) != 5 {
500 t.Errorf("got %d offset ranges, wanted 5", len(info.OffsetRanges()))
501 }
502
503 for old := int64(1); old <= 5; old++ {
504 want := original[old]
505 new := old + 100
506 got, found := info.GetOffsetRange(new)
507 if !found {
508 t.Errorf("offset range for ID %d not found", new)
509 }
510 if got != want {
511 t.Errorf("offset range for ID %d incorrect; got %v, want %v", new, got, want)
512 }
513 }
514}

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