update tests

This commit is contained in:
z7zmey
2018-04-09 23:26:44 +03:00
parent 83a1400a4f
commit 6ff2beafa3
76 changed files with 603 additions and 532 deletions

68
errors/error_test.go Normal file
View File

@@ -0,0 +1,68 @@
package errors_test
import (
"reflect"
"testing"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/token"
"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) {
token := token.Token{
Value: "test",
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
}
actual := errors.NewError("message", token)
expected := &errors.Error{
Msg: "message",
Pos: position.Position{
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
},
}
assertEqual(t, expected, actual)
}
func TestPrint(t *testing.T) {
token := token.Token{
Value: "test",
StartLine: 1,
EndLine: 2,
StartPos: 3,
EndPos: 4,
}
Error := errors.NewError("message", token)
actual := Error.String()
expected := "message at line 1"
assertEqual(t, expected, actual)
}