Merge pull request #113 from z7zmey/feature-111

[#111] cover by a unit test a property type name resolving
This commit is contained in:
Vadym Slizov 2020-07-26 14:43:40 +02:00 committed by GitHub
commit 234d258436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -974,3 +974,55 @@ func TestDoNotResolveReservedSpecialNames(t *testing.T) {
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
}
func TestResolvePropertyTypeName(t *testing.T) {
nameSimple := &name.Name{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}}
nameRelative := &name.Relative{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}}
nameFullyQualified := &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}}
propertyNodeSimple := &stmt.PropertyList{
Type: nameSimple,
}
propertyNodeRelative := &stmt.PropertyList{
Type: nameRelative,
}
propertyNodeFullyQualified := &stmt.PropertyList{
Type: nameFullyQualified,
}
classNode := &stmt.Class{
ClassName: &node.Identifier{Value: "Bar"},
Stmts: []node.Node{
propertyNodeSimple,
propertyNodeRelative,
propertyNodeFullyQualified,
},
}
ast := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Namespace{
NamespaceName: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
},
classNode,
},
}
expected := map[node.Node]string{
nameSimple: "Foo\\A\\B",
nameRelative: "Foo\\A\\B",
nameFullyQualified: "A\\B",
classNode: "Foo\\Bar",
}
nsResolver := visitor.NewNamespaceResolver()
ast.Walk(nsResolver)
assert.DeepEqual(t, expected, nsResolver.ResolvedNames)
}