php-parser/pkg/errors/error_test.go

46 lines
796 B
Go
Raw Permalink Normal View History

2018-04-09 20:26:44 +00:00
package errors_test
import (
"testing"
2019-02-25 16:11:28 +00:00
"gotest.tools/assert"
2018-04-09 20:26:44 +00:00
2023-12-09 21:36:19 +00:00
"git.maride.cc/maride/php-parser/pkg/errors"
"git.maride.cc/maride/php-parser/pkg/position"
2018-04-09 20:26:44 +00:00
)
func TestConstructor(t *testing.T) {
pos := position.NewPosition(1, 2, 3, 4, 1, 2)
2018-04-09 20:26:44 +00:00
actual := errors.NewError("message", pos)
2018-04-09 20:26:44 +00:00
expected := &errors.Error{
Msg: "message",
Pos: pos,
2018-04-09 20:26:44 +00:00
}
2019-02-25 16:11:28 +00:00
assert.DeepEqual(t, expected, actual)
2018-04-09 20:26:44 +00:00
}
func TestPrint(t *testing.T) {
pos := position.NewPosition(1, 2, 3, 4, 1, 2)
2018-04-09 20:26:44 +00:00
Error := errors.NewError("message", pos)
2018-04-09 20:26:44 +00:00
actual := Error.String()
expected := "message at line 1"
2019-02-25 16:11:28 +00:00
assert.DeepEqual(t, expected, actual)
2018-04-09 20:26:44 +00:00
}
func TestPrintWithotPos(t *testing.T) {
Error := errors.NewError("message", nil)
actual := Error.String()
expected := "message"
2019-02-25 16:11:28 +00:00
assert.DeepEqual(t, expected, actual)
}