diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-01 11:28:30 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-01 21:06:35 +0100 |
commit | 1d18eb0574a57c3e9f468659d076a666a3dd76f2 (patch) | |
tree | 8536aa6e8e2fc496b3b2d7b66a2e5f0110e625a6 /common/herrors/error_locator_test.go | |
parent | 33a7b36fd42ee31dd79115ec6639bed24247332f (diff) |
Add file (line/col) info to ref/relref errors
See #5371
Diffstat (limited to 'common/herrors/error_locator_test.go')
-rw-r--r-- | common/herrors/error_locator_test.go | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/common/herrors/error_locator_test.go b/common/herrors/error_locator_test.go index 84c0faf89..2d007016d 100644 --- a/common/herrors/error_locator_test.go +++ b/common/herrors/error_locator_test.go @@ -21,18 +21,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestCreateFileLogFormatter(t *testing.T) { - assert := require.New(t) - - ctx := ErrorContext{Filename: "/my/file.txt", LineNumber: 12, ColumnNumber: 13} - - assert.Equal("/my/file.txt|13|12", createFileLogFormatter(":file|:col|:line")(ctx)) - assert.Equal("13|/my/file.txt|12", createFileLogFormatter(":col|:file|:line")(ctx)) - assert.Equal("好:13", createFileLogFormatter("好::col")(ctx)) - assert.Equal("\"/my/file.txt:12:13\"", createFileLogFormatter("")(ctx)) - -} - func TestErrorLocator(t *testing.T) { assert := require.New(t) @@ -53,8 +41,9 @@ LINE 8 location := locateErrorInString(lines, lineMatcher) assert.Equal([]string{"LINE 3", "LINE 4", "This is THEONE", "LINE 6", "LINE 7"}, location.Lines) - assert.Equal(5, location.LineNumber) - assert.Equal(2, location.Pos) + pos := location.Position() + assert.Equal(5, pos.LineNumber) + assert.Equal(2, location.LinesPos) assert.Equal([]string{"This is THEONE"}, locateErrorInString(`This is THEONE`, lineMatcher).Lines) @@ -62,32 +51,32 @@ LINE 8 This is THEONE L2 `, lineMatcher) - assert.Equal(2, location.LineNumber) - assert.Equal(1, location.Pos) + assert.Equal(2, location.Position().LineNumber) + assert.Equal(1, location.LinesPos) assert.Equal([]string{"L1", "This is THEONE", "L2", ""}, location.Lines) location = locateErrorInString(`This is THEONE L2 `, lineMatcher) - assert.Equal(0, location.Pos) + assert.Equal(0, location.LinesPos) assert.Equal([]string{"This is THEONE", "L2", ""}, location.Lines) location = locateErrorInString(`L1 This THEONE `, lineMatcher) assert.Equal([]string{"L1", "This THEONE", ""}, location.Lines) - assert.Equal(1, location.Pos) + assert.Equal(1, location.LinesPos) location = locateErrorInString(`L1 L2 This THEONE `, lineMatcher) assert.Equal([]string{"L1", "L2", "This THEONE", ""}, location.Lines) - assert.Equal(2, location.Pos) + assert.Equal(2, location.LinesPos) location = locateErrorInString("NO MATCH", lineMatcher) - assert.Equal(-1, location.LineNumber) - assert.Equal(-1, location.Pos) + assert.Equal(-1, location.Position().LineNumber) + assert.Equal(-1, location.LinesPos) assert.Equal(0, len(location.Lines)) lineMatcher = func(m LineMatcher) bool { @@ -106,8 +95,8 @@ I J`, lineMatcher) assert.Equal([]string{"D", "E", "F", "G", "H"}, location.Lines) - assert.Equal(6, location.LineNumber) - assert.Equal(2, location.Pos) + assert.Equal(6, location.Position().LineNumber) + assert.Equal(2, location.LinesPos) // Test match EOF lineMatcher = func(m LineMatcher) bool { @@ -120,8 +109,8 @@ C `, lineMatcher) assert.Equal([]string{"B", "C", ""}, location.Lines) - assert.Equal(4, location.LineNumber) - assert.Equal(2, location.Pos) + assert.Equal(4, location.Position().LineNumber) + assert.Equal(2, location.LinesPos) offsetMatcher := func(m LineMatcher) bool { return m.Offset == 1 @@ -134,7 +123,7 @@ D E`, offsetMatcher) assert.Equal([]string{"A", "B", "C", "D"}, location.Lines) - assert.Equal(2, location.LineNumber) - assert.Equal(1, location.Pos) + assert.Equal(2, location.Position().LineNumber) + assert.Equal(1, location.LinesPos) } |