File: error_test.go

package info (click to toggle)
golang-github-tdewolff-parse 2.7.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (2)
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")
}