scanner.NewToken returns pointer, and scanner.Token saves position as position.Position
This commit is contained in:
@@ -10,19 +10,14 @@ import (
|
||||
// Error parsing error
|
||||
type Error struct {
|
||||
Msg string
|
||||
Pos position.Position
|
||||
Pos *position.Position
|
||||
}
|
||||
|
||||
// NewError creates and returns new Error
|
||||
func NewError(msg string, t scanner.Token) *Error {
|
||||
func NewError(msg string, t *scanner.Token) *Error {
|
||||
return &Error{
|
||||
Msg: msg,
|
||||
Pos: position.Position{
|
||||
StartLine: t.StartLine,
|
||||
EndLine: t.EndLine,
|
||||
StartPos: t.StartPos,
|
||||
EndPos: t.EndPos,
|
||||
},
|
||||
Pos: t.Position(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,37 +26,22 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
|
||||
}
|
||||
|
||||
func TestConstructor(t *testing.T) {
|
||||
token := scanner.Token{
|
||||
Value: "test",
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
}
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
token := scanner.NewToken([]byte(`test`), pos)
|
||||
|
||||
actual := errors.NewError("message", token)
|
||||
|
||||
expected := &errors.Error{
|
||||
Msg: "message",
|
||||
Pos: position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
},
|
||||
Pos: pos,
|
||||
}
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
token := scanner.Token{
|
||||
Value: "test",
|
||||
StartLine: 1,
|
||||
EndLine: 2,
|
||||
StartPos: 3,
|
||||
EndPos: 4,
|
||||
}
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
token := scanner.NewToken([]byte(`test`), pos)
|
||||
|
||||
Error := errors.NewError("message", token)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user