php-parser/errors/error_test.go

61 lines
1.1 KiB
Go
Raw Normal View History

2018-04-09 20:26:44 +00:00
package errors_test
import (
"reflect"
"testing"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/errors"
"github.com/kylelemons/godebug/pretty"
)
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
diff := pretty.Compare(expected, actual)
if diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
} else {
t.Errorf("expected and actual are not equal\n")
}
}
}
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
}
assertEqual(t, expected, actual)
}
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"
assertEqual(t, expected, actual)
}
func TestPrintWithotPos(t *testing.T) {
Error := errors.NewError("message", nil)
actual := Error.String()
expected := "message"
assertEqual(t, expected, actual)
}