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

Function TestSourceInfo

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

Source from the content-addressed store, hash-verified

174}
175
176func TestSourceInfo(t *testing.T) {
177 src := common.NewStringSource("a\n? b\n: c", "custom description")
178 info := ast.NewSourceInfo(src)
179 if info.Description() != "custom description" {
180 t.Errorf("Description() got %s, wanted 'custom description'", info.Description())
181 }
182 if len(info.LineOffsets()) != 3 {
183 t.Errorf("LineOffsets() got %v, wanted 3 offsets", info.LineOffsets())
184 }
185 info.SetOffsetRange(1, ast.OffsetRange{Start: 0, Stop: 1}) // a
186 info.SetOffsetRange(2, ast.OffsetRange{Start: 4, Stop: 5}) // b
187 info.SetOffsetRange(3, ast.OffsetRange{Start: 8, Stop: 9}) // c
188 if !reflect.DeepEqual(info.GetStartLocation(1), common.NewLocation(1, 0)) {
189 t.Errorf("info.GetStartLocation(1) got %v, wanted line 1, col 0", info.GetStartLocation(1))
190 }
191 if !reflect.DeepEqual(info.GetStopLocation(1), common.NewLocation(1, 1)) {
192 t.Errorf("info.GetStopLocation(1) got %v, wanted line 1, col 1", info.GetStopLocation(1))
193 }
194 if !reflect.DeepEqual(info.GetStartLocation(2), common.NewLocation(2, 2)) {
195 t.Errorf("info.GetStartLocation(2) got %v, wanted line 2, col 2", info.GetStartLocation(2))
196 }
197 if !reflect.DeepEqual(info.GetStopLocation(2), common.NewLocation(2, 3)) {
198 t.Errorf("info.GetStopLocation(2) got %v, wanted line 2, col 3", info.GetStopLocation(2))
199 }
200 if !reflect.DeepEqual(info.GetStartLocation(3), common.NewLocation(3, 2)) {
201 t.Errorf("info.GetStartLocation(3) got %v, wanted line 2, col 2", info.GetStartLocation(3))
202 }
203 if !reflect.DeepEqual(info.GetStopLocation(3), common.NewLocation(3, 3)) {
204 t.Errorf("info.GetStopLocation(3) got %v, wanted line 2, col 3", info.GetStopLocation(3))
205 }
206 if info.ComputeOffset(3, 2) != 8 {
207 t.Errorf("info.ComputeOffset(3, 2) got %d, wanted 8", info.ComputeOffset(3, 2))
208 }
209}
210
211func TestSourceInfoNilSafety(t *testing.T) {
212 info, err := ast.ProtoToSourceInfo(nil)

Callers

nothing calls this directly

Calls 9

DescriptionMethod · 0.95
LineOffsetsMethod · 0.95
SetOffsetRangeMethod · 0.95
GetStartLocationMethod · 0.95
GetStopLocationMethod · 0.95
ComputeOffsetMethod · 0.95
NewStringSourceFunction · 0.92
NewSourceInfoFunction · 0.92
NewLocationFunction · 0.92

Tested by

no test coverage detected