-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy patherror_test.go
37 lines (28 loc) · 1.01 KB
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package parse
import (
"bytes"
"testing"
"github.com/tdewolff/test"
)
func TestError(t *testing.T) {
err := NewError(bytes.NewBufferString("buffer"), 3, "message")
line, column, context := err.Position()
test.T(t, line, 1, "line")
test.T(t, column, 4, "column")
test.T(t, "\n"+context, "\n 1: buffer\n ^", "context")
test.T(t, err.Error(), "message on line 1 and column 4\n 1: buffer\n ^", "error")
}
func TestErrorLexer(t *testing.T) {
l := NewInputString("buffer")
l.Move(3)
err := NewErrorLexer(l, "message")
line, column, context := err.Position()
test.T(t, line, 1, "line")
test.T(t, column, 4, "column")
test.T(t, "\n"+context, "\n 1: buffer\n ^", "context")
test.T(t, err.Error(), "message on line 1 and column 4\n 1: buffer\n ^", "error")
}
func TestErrorMessages(t *testing.T) {
err := NewError(bytes.NewBufferString("buffer"), 3, "message %d", 5)
test.T(t, err.Error(), "message 5 on line 1 and column 4\n 1: buffer\n ^", "error")
}