scanner.NewToken returns pointer, and scanner.Token saves position as position.Position

This commit is contained in:
z7zmey
2018-04-15 22:56:20 +03:00
parent bc15825663
commit 435dc5c706
14 changed files with 137 additions and 136 deletions

View File

@@ -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(),
}
}

View File

@@ -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)