fix dumper test fail related to map order

This commit is contained in:
z7zmey 2018-02-27 23:57:33 +02:00
parent e19df2783d
commit 4e1382cf71
2 changed files with 32 additions and 17 deletions

View File

@ -29,12 +29,14 @@ func (d Dumper) EnterNode(w walker.Walkable) bool {
fmt.Printf(" %v", *p)
}
if a := n.Attributes(); len(a) > 0 {
fmt.Printf(" %v", a)
for key, attr := range a {
fmt.Printf("\n%v\"%v\": %v;", d.Indent+" ", key, attr)
}
}
fmt.Println()
if c := d.Comments[n]; len(c) > 0 {
fmt.Printf("%vComments:\n", d.Indent+" ")
fmt.Printf("%v\"Comments\":\n", d.Indent+" ")
for _, cc := range c {
fmt.Printf("%v%q\n", d.Indent+" ", cc)
}

View File

@ -30,50 +30,63 @@ func ExampleDumper() {
}
nodes.Walk(dumper)
// Output:
// Unordered output:
//| *stmt.StmtList Pos{Line: 3-11 Pos: 10-143}
//| "Stmts":
//| *stmt.Namespace Pos{Line: 3-11 Pos: 10-143}
//| "NamespaceName":
//| *name.Name Pos{Line: 3-3 Pos: 20-22}
//| "Parts":
//| *name.NamePart Pos{Line: 3-3 Pos: 20-22} map[Value:Foo]
//| *name.NamePart Pos{Line: 3-3 Pos: 20-22}
//| "Value": Foo;
//| "Stmts":
//| *stmt.Class Pos{Line: 4-10 Pos: 29-139} map[PhpDocComment:]
//| *stmt.Class Pos{Line: 4-10 Pos: 29-139}
//| "PhpDocComment": ;
//| "ClassName":
//| *node.Identifier Pos{Line: 4-4 Pos: 35-37} map[Value:Bar]
//| *node.Identifier Pos{Line: 4-4 Pos: 35-37}
//| "Value": Bar;
//| "Stmts":
//| *stmt.ClassMethod Pos{Line: 5-9 Pos: 45-134} map[ReturnsRef:false PhpDocComment:]
//| *stmt.ClassMethod Pos{Line: 5-9 Pos: 45-134}
//| "ReturnsRef": false;
//| "PhpDocComment": ;
//| "MethodName":
//| *node.Identifier Pos{Line: 5-5 Pos: 61-72} map[Value:FunctionName]
//| *node.Identifier Pos{Line: 5-5 Pos: 61-72}
//| "Value": FunctionName;
//| "Modifiers":
//| *node.Identifier Pos{Line: 5-5 Pos: 45-50} map[Value:public]
//| *node.Identifier Pos{Line: 5-5 Pos: 45-50}
//| "Value": public;
//| "Params":
//| *node.Parameter Pos{Line: 5-5 Pos: 74-89} map[ByRef:false Variadic:false]
//| *node.Parameter Pos{Line: 5-5 Pos: 74-89}
//| "ByRef": false;
//| "Variadic": false;
//| "VariableType":
//| *name.Name Pos{Line: 5-5 Pos: 74-77}
//| "Parts":
//| *name.NamePart Pos{Line: 5-5 Pos: 74-77} map[Value:Type]
//| *name.NamePart Pos{Line: 5-5 Pos: 74-77}
//| "Value": Type;
//| "Variable":
//| *expr.Variable Pos{Line: 5-5 Pos: 79-82}
//| "VarName":
//| *node.Identifier Pos{Line: 5-5 Pos: 79-82} map[Value:$var]
//| *node.Identifier Pos{Line: 5-5 Pos: 79-82}
//| "Value": $var;
//| "DefaultValue":
//| *expr.ConstFetch Pos{Line: 5-5 Pos: 86-89}
//| "Constant":
//| *name.Name Pos{Line: 5-5 Pos: 86-89}
//| "Parts":
//| *name.NamePart Pos{Line: 5-5 Pos: 86-89} map[Value:null]
//| *name.NamePart Pos{Line: 5-5 Pos: 86-89}
//| "Value": null;
//| "Stmts":
//| *stmt.Expression Pos{Line: 8-8 Pos: 124-128}
//| Comments:
//| "Comments":
//| "// some comment\n"
//| "Expr":
//| *expr.Variable Pos{Line: 8-8 Pos: 124-127}
//| Comments:
//| "Comments":
//| "// some comment\n"
//| "VarName":
//| *node.Identifier Pos{Line: 8-8 Pos: 124-127} map[Value:$var]
//| Comments:
//| *node.Identifier Pos{Line: 8-8 Pos: 124-127}
//| "Value": $var;
//| "Comments":
//| "// some comment\n"
}