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

Function TestStringSource_LocationOffset

common/source_test.go:60–87  ·  view source on GitHub ↗

TestStringSource_LocationOffset make sure that the offsets accurately reflect the location of a character in source.

(t *testing.T)

Source from the content-addressed store, hash-verified

58// TestStringSource_LocationOffset make sure that the offsets accurately reflect
59// the location of a character in source.
60func TestStringSource_LocationOffset(t *testing.T) {
61 contents := "c.d &&\n\t b.c.arg(10) &&\n\t test(10)"
62 source := NewStringSource(contents, "offset-test")
63 expectedLineOffsets := []int32{7, 24, 35}
64 if len(expectedLineOffsets) != len(source.LineOffsets()) {
65 t.Errorf("Got list of size '%d', wanted size '%d'",
66 len(source.LineOffsets()), len(expectedLineOffsets))
67 } else {
68 for i, val := range expectedLineOffsets {
69 if val != source.LineOffsets()[i] {
70 t.Errorf("Got %d, wanted line %d offset of %d, ",
71 val, source.LineOffsets()[i], i)
72 }
73 }
74 }
75 // Ensure that selecting a set of characters across multiple lines works as
76 // expected.
77 charStart, _ := source.LocationOffset(NewLocation(1, 2))
78 charEnd, _ := source.LocationOffset(NewLocation(3, 2))
79 if string(contents[charStart:charEnd]) != "d &&\n\t b.c.arg(10) &&\n\t " {
80 t.Errorf(unexpectedValue, t.Name(),
81 string(contents[charStart:charEnd]),
82 "d &&\n\t b.c.arg(10) &&\n\t ")
83 }
84 if _, found := source.LocationOffset(NewLocation(4, 0)); found {
85 t.Error("Character offset was out of range of source, but still found.")
86 }
87}
88
89// TestStringSource_SnippetMultiline snippets of text from a multiline source.
90func TestStringSource_SnippetMultiline(t *testing.T) {

Callers

nothing calls this directly

Calls 6

NewStringSourceFunction · 0.85
NewLocationFunction · 0.85
LineOffsetsMethod · 0.65
LocationOffsetMethod · 0.65
NameMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected