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) {
|
2018-04-15 19:56:20 +00:00
|
|
|
pos := position.NewPosition(1, 2, 3, 4)
|
2018-04-09 20:26:44 +00:00
|
|
|
|
2018-11-05 14:56:27 +00:00
|
|
|
actual := errors.NewError("message", pos)
|
2018-04-09 20:26:44 +00:00
|
|
|
|
|
|
|
expected := &errors.Error{
|
|
|
|
Msg: "message",
|
2018-04-15 19:56:20 +00:00
|
|
|
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) {
|
2018-04-15 19:56:20 +00:00
|
|
|
pos := position.NewPosition(1, 2, 3, 4)
|
2018-04-09 20:26:44 +00:00
|
|
|
|
2018-11-05 14:56:27 +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
|
|
|
}
|
2018-11-05 14:56:27 +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)
|
2018-11-05 14:56:27 +00:00
|
|
|
}
|