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-03-31 14:50:08 +00:00
|
|
|
"github.com/laytan/php-parser/pkg/errors"
|
|
|
|
"github.com/laytan/php-parser/pkg/position"
|
2018-04-09 20:26:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConstructor(t *testing.T) {
|
2023-03-26 00:54:00 +00:00
|
|
|
pos := position.NewPosition(1, 2, 3, 4, 1, 2)
|
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) {
|
2023-03-26 00:54:00 +00:00
|
|
|
pos := position.NewPosition(1, 2, 3, 4, 1, 2)
|
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
|
|
|
}
|