| 1 |
package parse |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/tdewolff/test" |
| 8 |
) |
| 9 |
|
| 10 |
func TestError(t *testing.T) { |
| 11 |
err := NewError(bytes.NewBufferString("buffer"), 3, "message") |
| 12 |
|
| 13 |
line, column, context := err.Position() |
| 14 |
test.T(t, line, 1, "line") |
| 15 |
test.T(t, column, 4, "column") |
| 16 |
test.T(t, "\n"+context, "\n 1: buffer\n ^", "context") |
| 17 |
|
| 18 |
test.T(t, err.Error(), "message on line 1 and column 4\n 1: buffer\n ^", "error") |
| 19 |
} |
| 20 |
|
| 21 |
func TestErrorLexer(t *testing.T) { |
| 22 |
l := NewInputString("buffer") |
| 23 |
l.Move(3) |
| 24 |
err := NewErrorLexer(l, "message") |
| 25 |
|
| 26 |
line, column, context := err.Position() |
| 27 |
test.T(t, line, 1, "line") |
| 28 |
test.T(t, column, 4, "column") |
| 29 |
test.T(t, "\n"+context, "\n 1: buffer\n ^", "context") |
| 30 |
|
| 31 |
test.T(t, err.Error(), "message on line 1 and column 4\n 1: buffer\n ^", "error") |
| 32 |
} |
| 33 |
|
| 34 |
func TestErrorMessages(t *testing.T) { |
| 35 |
err := NewError(bytes.NewBufferString("buffer"), 3, "message %d", 5) |
| 36 |
test.T(t, err.Error(), "message 5 on line 1 and column 4\n 1: buffer\n ^", "error") |
| 37 |
} |