remove kylelemons/godebug
This commit is contained in:
parent
a6519f4a2c
commit
32d9c634d1
@ -3,6 +3,7 @@ branches:
|
|||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
before_script:
|
before_script:
|
||||||
|
- go get -u gotest.tools/assert
|
||||||
- go get -u golang.org/x/tools/cmd/goyacc
|
- go get -u golang.org/x/tools/cmd/goyacc
|
||||||
- go get -u github.com/pkg/profile
|
- go get -u github.com/pkg/profile
|
||||||
- go get -u github.com/cznic/golex/lex
|
- go get -u github.com/cznic/golex/lex
|
||||||
|
@ -1,29 +1,14 @@
|
|||||||
package errors_test
|
package errors_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/position"
|
"gotest.tools/assert"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/errors"
|
"github.com/z7zmey/php-parser/errors"
|
||||||
|
"github.com/z7zmey/php-parser/position"
|
||||||
"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) {
|
func TestConstructor(t *testing.T) {
|
||||||
pos := position.NewPosition(1, 2, 3, 4)
|
pos := position.NewPosition(1, 2, 3, 4)
|
||||||
|
|
||||||
@ -34,7 +19,7 @@ func TestConstructor(t *testing.T) {
|
|||||||
Pos: pos,
|
Pos: pos,
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrint(t *testing.T) {
|
func TestPrint(t *testing.T) {
|
||||||
@ -46,7 +31,7 @@ func TestPrint(t *testing.T) {
|
|||||||
|
|
||||||
expected := "message at line 1"
|
expected := "message at line 1"
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintWithotPos(t *testing.T) {
|
func TestPrintWithotPos(t *testing.T) {
|
||||||
@ -56,5 +41,5 @@ func TestPrintWithotPos(t *testing.T) {
|
|||||||
|
|
||||||
expected := "message"
|
expected := "message"
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package scalar_test
|
package scalar_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kylelemons/godebug/pretty"
|
"gotest.tools/assert"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/node"
|
"github.com/z7zmey/php-parser/node"
|
||||||
"github.com/z7zmey/php-parser/node/scalar"
|
"github.com/z7zmey/php-parser/node/scalar"
|
||||||
"github.com/z7zmey/php-parser/walker"
|
"github.com/z7zmey/php-parser/walker"
|
||||||
@ -70,31 +70,25 @@ func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
|
|||||||
|
|
||||||
func TestNameVisitorDisableChildren(t *testing.T) {
|
func TestNameVisitorDisableChildren(t *testing.T) {
|
||||||
for _, tt := range nameNodesTests {
|
for _, tt := range nameNodesTests {
|
||||||
v := &visitorMock{false, nil}
|
v := &visitorMock{false, []string{}}
|
||||||
tt.node.Walk(v)
|
tt.node.Walk(v)
|
||||||
|
|
||||||
expected := []string{}
|
expected := []string{}
|
||||||
actual := v.visitedKeys
|
actual := v.visitedKeys
|
||||||
|
|
||||||
diff := pretty.Compare(expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
if diff != "" {
|
|
||||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNameVisitor(t *testing.T) {
|
func TestNameVisitor(t *testing.T) {
|
||||||
for _, tt := range nameNodesTests {
|
for _, tt := range nameNodesTests {
|
||||||
v := &visitorMock{true, nil}
|
v := &visitorMock{true, []string{}}
|
||||||
tt.node.Walk(v)
|
tt.node.Walk(v)
|
||||||
|
|
||||||
expected := tt.expectedVisitedKeys
|
expected := tt.expectedVisitedKeys
|
||||||
actual := v.visitedKeys
|
actual := v.visitedKeys
|
||||||
|
|
||||||
diff := pretty.Compare(expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
if diff != "" {
|
|
||||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,9 +99,6 @@ func TestNameAttributes(t *testing.T) {
|
|||||||
expected := tt.expectedAttributes
|
expected := tt.expectedAttributes
|
||||||
actual := tt.node.Attributes()
|
actual := tt.node.Attributes()
|
||||||
|
|
||||||
diff := pretty.Compare(expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
if diff != "" {
|
|
||||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,30 +2,14 @@ package scanner_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/freefloating"
|
"github.com/z7zmey/php-parser/freefloating"
|
||||||
"github.com/z7zmey/php-parser/position"
|
"github.com/z7zmey/php-parser/position"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/scanner"
|
"github.com/z7zmey/php-parser/scanner"
|
||||||
|
"gotest.tools/assert"
|
||||||
"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")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type lval struct {
|
type lval struct {
|
||||||
Tkn *scanner.Token
|
Tkn *scanner.Token
|
||||||
}
|
}
|
||||||
@ -427,7 +411,7 @@ func TestTokens(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSingleQuoteStringTokens(t *testing.T) {
|
func TestSingleQuoteStringTokens(t *testing.T) {
|
||||||
@ -474,7 +458,7 @@ func TestSingleQuoteStringTokens(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTeplateStringTokens(t *testing.T) {
|
func TestTeplateStringTokens(t *testing.T) {
|
||||||
@ -563,7 +547,7 @@ func TestTeplateStringTokens(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackquoteStringTokens(t *testing.T) {
|
func TestBackquoteStringTokens(t *testing.T) {
|
||||||
@ -649,7 +633,7 @@ func TestBackquoteStringTokens(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHereDocTokens(t *testing.T) {
|
func TestHereDocTokens(t *testing.T) {
|
||||||
@ -744,7 +728,7 @@ CAT;
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHereDocTokens2(t *testing.T) {
|
func TestHereDocTokens2(t *testing.T) {
|
||||||
@ -816,7 +800,7 @@ CAT
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHereDocTokens3(t *testing.T) {
|
func TestHereDocTokens3(t *testing.T) {
|
||||||
@ -855,7 +839,7 @@ CAT;
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInlineHtmlNopTokens(t *testing.T) {
|
func TestInlineHtmlNopTokens(t *testing.T) {
|
||||||
@ -888,7 +872,7 @@ func TestInlineHtmlNopTokens(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringTokensAfterVariable(t *testing.T) {
|
func TestStringTokensAfterVariable(t *testing.T) {
|
||||||
@ -925,8 +909,8 @@ func TestStringTokensAfterVariable(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
assertEqual(t, expectedTokens, actualTokens)
|
assert.DeepEqual(t, expectedTokens, actualTokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSlashAfterVariable(t *testing.T) {
|
func TestSlashAfterVariable(t *testing.T) {
|
||||||
@ -959,8 +943,8 @@ func TestSlashAfterVariable(t *testing.T) {
|
|||||||
actual = append(actual, scanner.LexerToken(token).String())
|
actual = append(actual, scanner.LexerToken(token).String())
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
assertEqual(t, expectedTokens, actualTokens)
|
assert.DeepEqual(t, expectedTokens, actualTokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommentEnd(t *testing.T) {
|
func TestCommentEnd(t *testing.T) {
|
||||||
@ -992,7 +976,7 @@ func TestCommentEnd(t *testing.T) {
|
|||||||
|
|
||||||
actual := lexer.FreeFloating
|
actual := lexer.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommentNewLine(t *testing.T) {
|
func TestCommentNewLine(t *testing.T) {
|
||||||
@ -1024,7 +1008,7 @@ func TestCommentNewLine(t *testing.T) {
|
|||||||
|
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommentNewLine1(t *testing.T) {
|
func TestCommentNewLine1(t *testing.T) {
|
||||||
@ -1056,7 +1040,7 @@ func TestCommentNewLine1(t *testing.T) {
|
|||||||
|
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommentNewLine2(t *testing.T) {
|
func TestCommentNewLine2(t *testing.T) {
|
||||||
@ -1088,7 +1072,7 @@ func TestCommentNewLine2(t *testing.T) {
|
|||||||
|
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommentWithPhpEndTag(t *testing.T) {
|
func TestCommentWithPhpEndTag(t *testing.T) {
|
||||||
@ -1121,7 +1105,7 @@ func TestCommentWithPhpEndTag(t *testing.T) {
|
|||||||
|
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInlineComment(t *testing.T) {
|
func TestInlineComment(t *testing.T) {
|
||||||
@ -1154,7 +1138,7 @@ func TestInlineComment(t *testing.T) {
|
|||||||
|
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInlineComment2(t *testing.T) {
|
func TestInlineComment2(t *testing.T) {
|
||||||
@ -1187,7 +1171,7 @@ func TestInlineComment2(t *testing.T) {
|
|||||||
|
|
||||||
actual := lexer.FreeFloating
|
actual := lexer.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyInlineComment(t *testing.T) {
|
func TestEmptyInlineComment(t *testing.T) {
|
||||||
@ -1225,7 +1209,7 @@ func TestEmptyInlineComment(t *testing.T) {
|
|||||||
|
|
||||||
actual := lexer.FreeFloating
|
actual := lexer.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyInlineComment2(t *testing.T) {
|
func TestEmptyInlineComment2(t *testing.T) {
|
||||||
@ -1258,7 +1242,7 @@ func TestEmptyInlineComment2(t *testing.T) {
|
|||||||
|
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
|
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMethodCallTokens(t *testing.T) {
|
func TestMethodCallTokens(t *testing.T) {
|
||||||
@ -1283,7 +1267,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1294,7 +1278,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1305,7 +1289,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1316,7 +1300,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1327,7 +1311,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1338,7 +1322,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1349,7 +1333,7 @@ func TestMethodCallTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestYieldFromTokens(t *testing.T) {
|
func TestYieldFromTokens(t *testing.T) {
|
||||||
@ -1374,7 +1358,7 @@ func TestYieldFromTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual := lv.Tkn.FreeFloating
|
actual := lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = []freefloating.String{
|
expected = []freefloating.String{
|
||||||
{
|
{
|
||||||
@ -1385,7 +1369,7 @@ func TestYieldFromTokens(t *testing.T) {
|
|||||||
}
|
}
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.FreeFloating
|
actual = lv.Tkn.FreeFloating
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIgnoreControllCharacters(t *testing.T) {
|
func TestIgnoreControllCharacters(t *testing.T) {
|
||||||
@ -1397,12 +1381,12 @@ func TestIgnoreControllCharacters(t *testing.T) {
|
|||||||
expected := "echo"
|
expected := "echo"
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual := lv.Tkn.Value
|
actual := lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = "$b"
|
expected = "$b"
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.Value
|
actual = lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) {
|
func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) {
|
||||||
@ -1414,25 +1398,25 @@ func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) {
|
|||||||
expected := "\""
|
expected := "\""
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual := lv.Tkn.Value
|
actual := lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = "$a"
|
expected = "$a"
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.Value
|
actual = lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = "["
|
expected = "["
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.Value
|
actual = lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = "test"
|
expected = "test"
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.Value
|
actual = lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
|
|
||||||
expected = "]"
|
expected = "]"
|
||||||
lexer.Lex(lv)
|
lexer.Lex(lv)
|
||||||
actual = lv.Tkn.Value
|
actual = lv.Tkn.Value
|
||||||
assertEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,18 @@
|
|||||||
package visitor_test
|
package visitor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kylelemons/godebug/pretty"
|
"gotest.tools/assert"
|
||||||
"github.com/z7zmey/php-parser/node/scalar"
|
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/node/expr"
|
|
||||||
"github.com/z7zmey/php-parser/visitor"
|
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/node/stmt"
|
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/node"
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
"github.com/z7zmey/php-parser/node/expr"
|
||||||
"github.com/z7zmey/php-parser/node/name"
|
"github.com/z7zmey/php-parser/node/name"
|
||||||
|
"github.com/z7zmey/php-parser/node/scalar"
|
||||||
|
"github.com/z7zmey/php-parser/node/stmt"
|
||||||
|
"github.com/z7zmey/php-parser/visitor"
|
||||||
)
|
)
|
||||||
|
|
||||||
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 TestResolveStaticCall(t *testing.T) {
|
func TestResolveStaticCall(t *testing.T) {
|
||||||
nameAB := &name.Name{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}}
|
nameAB := &name.Name{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}}
|
||||||
nameBC := &name.Name{Parts: []node.Node{&name.NamePart{Value: "B"}, &name.NamePart{Value: "C"}}}
|
nameBC := &name.Name{Parts: []node.Node{&name.NamePart{Value: "B"}, &name.NamePart{Value: "C"}}}
|
||||||
@ -56,7 +41,7 @@ func TestResolveStaticCall(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveStaticPropertyFetch(t *testing.T) {
|
func TestResolveStaticPropertyFetch(t *testing.T) {
|
||||||
@ -86,7 +71,7 @@ func TestResolveStaticPropertyFetch(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveClassConstFetch(t *testing.T) {
|
func TestResolveClassConstFetch(t *testing.T) {
|
||||||
@ -116,7 +101,7 @@ func TestResolveClassConstFetch(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveNew(t *testing.T) {
|
func TestResolveNew(t *testing.T) {
|
||||||
@ -146,7 +131,7 @@ func TestResolveNew(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveInstanceOf(t *testing.T) {
|
func TestResolveInstanceOf(t *testing.T) {
|
||||||
@ -176,7 +161,7 @@ func TestResolveInstanceOf(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveInstanceCatch(t *testing.T) {
|
func TestResolveInstanceCatch(t *testing.T) {
|
||||||
@ -223,7 +208,7 @@ func TestResolveInstanceCatch(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveFunctionCall(t *testing.T) {
|
func TestResolveFunctionCall(t *testing.T) {
|
||||||
@ -254,7 +239,7 @@ func TestResolveFunctionCall(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveConstFetch(t *testing.T) {
|
func TestResolveConstFetch(t *testing.T) {
|
||||||
@ -284,7 +269,7 @@ func TestResolveConstFetch(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveGroupUse(t *testing.T) {
|
func TestResolveGroupUse(t *testing.T) {
|
||||||
@ -341,7 +326,7 @@ func TestResolveGroupUse(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveTraitUse(t *testing.T) {
|
func TestResolveTraitUse(t *testing.T) {
|
||||||
@ -407,7 +392,7 @@ func TestResolveTraitUse(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveClassName(t *testing.T) {
|
func TestResolveClassName(t *testing.T) {
|
||||||
@ -442,7 +427,7 @@ func TestResolveClassName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveInterfaceName(t *testing.T) {
|
func TestResolveInterfaceName(t *testing.T) {
|
||||||
@ -475,7 +460,7 @@ func TestResolveInterfaceName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveTraitName(t *testing.T) {
|
func TestResolveTraitName(t *testing.T) {
|
||||||
@ -498,7 +483,7 @@ func TestResolveTraitName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveFunctionName(t *testing.T) {
|
func TestResolveFunctionName(t *testing.T) {
|
||||||
@ -536,7 +521,7 @@ func TestResolveFunctionName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveMethodName(t *testing.T) {
|
func TestResolveMethodName(t *testing.T) {
|
||||||
@ -569,7 +554,7 @@ func TestResolveMethodName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
methodNode.Walk(nsResolver)
|
methodNode.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveClosureName(t *testing.T) {
|
func TestResolveClosureName(t *testing.T) {
|
||||||
@ -600,7 +585,7 @@ func TestResolveClosureName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
closureNode.Walk(nsResolver)
|
closureNode.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveConstantsName(t *testing.T) {
|
func TestResolveConstantsName(t *testing.T) {
|
||||||
@ -639,7 +624,7 @@ func TestResolveConstantsName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveNamespaces(t *testing.T) {
|
func TestResolveNamespaces(t *testing.T) {
|
||||||
@ -717,7 +702,7 @@ func TestResolveNamespaces(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveStaticCallDinamicClassName(t *testing.T) {
|
func TestResolveStaticCallDinamicClassName(t *testing.T) {
|
||||||
@ -736,7 +721,7 @@ func TestResolveStaticCallDinamicClassName(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDoNotResolveReservedConstants(t *testing.T) {
|
func TestDoNotResolveReservedConstants(t *testing.T) {
|
||||||
@ -792,7 +777,7 @@ func TestDoNotResolveReservedConstants(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDoNotResolveReservedNames(t *testing.T) {
|
func TestDoNotResolveReservedNames(t *testing.T) {
|
||||||
@ -914,7 +899,7 @@ func TestDoNotResolveReservedNames(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDoNotResolveReservedSpecialNames(t *testing.T) {
|
func TestDoNotResolveReservedSpecialNames(t *testing.T) {
|
||||||
@ -987,5 +972,5 @@ func TestDoNotResolveReservedSpecialNames(t *testing.T) {
|
|||||||
nsResolver := visitor.NewNamespaceResolver()
|
nsResolver := visitor.NewNamespaceResolver()
|
||||||
ast.Walk(nsResolver)
|
ast.Walk(nsResolver)
|
||||||
|
|
||||||
assertEqual(t, expected, nsResolver.ResolvedNames)
|
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user