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

Function TestNewSourceInfoRelative

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

Source from the content-addressed store, hash-verified

354}
355
356func TestNewSourceInfoRelative(t *testing.T) {
357 sourceInfo := ast.NewSourceInfo(
358 mockRelativeSource(t,
359 "\n \n a || b ?\n cond1 :\n cond2",
360 []int32{1, 2, 13, 25},
361 common.NewLocation(2, 1)))
362 tests := []struct {
363 loc common.Location
364 offset int32
365 }{
366 // All locations specify a line number starting at 1
367 // The location of line 2, offset 1 is the same as the
368 // relative offset at location 1, 0 (offset 2)
369 {loc: common.NewLocation(1, 0), offset: 2},
370 // Equivalent to line 3, column 4
371 {loc: common.NewLocation(2, 3), offset: 6},
372 // Equivalent to line 4, column 2
373 {loc: common.NewLocation(3, 1), offset: 15},
374 }
375 for _, tst := range tests {
376 gotOffset := sourceInfo.ComputeOffset(int32(tst.loc.Line()), int32(tst.loc.Column()))
377 if gotOffset != tst.offset {
378 t.Errorf("ComputeOffset() got %v, wanted %v", gotOffset, tst.offset)
379 }
380 }
381}
382
383func TestMaxID(t *testing.T) {
384 checked := mustTypeCheck(t, `has({'a':'key'}.key)`)

Callers

nothing calls this directly

Calls 6

ComputeOffsetMethod · 0.95
NewSourceInfoFunction · 0.92
NewLocationFunction · 0.92
mockRelativeSourceFunction · 0.85
LineMethod · 0.65
ColumnMethod · 0.65

Tested by

no test coverage detected