TestStringSource_LocationOffset make sure that the offsets accurately reflect the location of a character in source.
(t *testing.T)
| 58 | // TestStringSource_LocationOffset make sure that the offsets accurately reflect |
| 59 | // the location of a character in source. |
| 60 | func 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. |
| 90 | func TestStringSource_SnippetMultiline(t *testing.T) { |
nothing calls this directly
no test coverage detected