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

Function TestSourceInfoRenumberIDs

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

Source from the content-addressed store, hash-verified

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

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