php-parser/pkg/errors/error_test.go

46 lines
770 B
Go
Raw 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
"github.com/z7zmey/php-parser/errors"
2019-02-25 16:11:28 +00:00
"github.com/z7zmey/php-parser/position"
2018-04-09 20:26:44 +00:00
)
func TestConstructor(t *testing.T) {
pos := position.NewPosition(1, 2, 3, 4)
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)
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)
}