2018-03-18 20:27:34 +00:00
|
|
|
package printer_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
"github.com/z7zmey/php-parser/meta"
|
|
|
|
|
2018-03-18 20:27:34 +00:00
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
|
|
"github.com/z7zmey/php-parser/node/expr"
|
|
|
|
"github.com/z7zmey/php-parser/node/expr/assign"
|
|
|
|
"github.com/z7zmey/php-parser/node/expr/binary"
|
|
|
|
"github.com/z7zmey/php-parser/node/expr/cast"
|
|
|
|
"github.com/z7zmey/php-parser/node/name"
|
|
|
|
"github.com/z7zmey/php-parser/node/scalar"
|
2018-03-19 20:50:07 +00:00
|
|
|
"github.com/z7zmey/php-parser/node/stmt"
|
2018-03-18 20:27:34 +00:00
|
|
|
"github.com/z7zmey/php-parser/printer"
|
|
|
|
)
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintFile(t *testing.T) {
|
2018-04-05 21:59:22 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-05-02 09:14:24 +00:00
|
|
|
p.Print(&node.Root{
|
2018-04-05 21:59:22 +00:00
|
|
|
Stmts: []node.Node{
|
2018-04-05 22:12:54 +00:00
|
|
|
&stmt.Namespace{
|
|
|
|
NamespaceName: &name.Name{
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{Value: "Foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Class{
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
|
|
|
|
ClassName: &name.Name{
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{Value: "Bar"},
|
|
|
|
},
|
|
|
|
},
|
2018-05-12 20:10:01 +00:00
|
|
|
Extends: &stmt.ClassExtends{
|
|
|
|
ClassName: &name.Name{
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{Value: "Baz"},
|
|
|
|
},
|
2018-04-05 22:12:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.ClassMethod{
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
MethodName: &node.Identifier{Value: "greet"},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Echo{
|
|
|
|
Exprs: []node.Node{
|
|
|
|
&scalar.String{Value: "'Hello world'"},
|
|
|
|
},
|
2018-04-05 22:12:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-05 21:59:22 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `namespaceFooabstractclassBarextendsBaz{publicfunctiongreet(){'Hello world'}}`
|
2018-04-05 21:59:22 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintFileInlineHtml(t *testing.T) {
|
2018-04-05 21:59:22 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-05-02 09:14:24 +00:00
|
|
|
p.Print(&node.Root{
|
2018-04-05 21:59:22 +00:00
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.InlineHtml{Value: "<div>HTML</div>"},
|
|
|
|
&stmt.Expression{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "<?php ",
|
|
|
|
TokenName: meta.NodeStart,
|
|
|
|
},
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Expr: &expr.Variable{
|
2018-10-24 14:04:13 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
VarName: &node.Identifier{
|
|
|
|
Value: "a",
|
2018-04-05 21:59:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `<div>HTML</div><?php $a`
|
2018-04-05 21:59:22 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 20:27:34 +00:00
|
|
|
// node
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintIdentifier(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
n := &node.Identifier{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 09:31:17 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "test",
|
|
|
|
}
|
|
|
|
p.Print(n)
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
if o.String() != ` test` {
|
2018-03-18 20:27:34 +00:00
|
|
|
t.Errorf("TestPrintIdentifier is failed\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintParameter(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&node.Parameter{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EllipsisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ByRef: false,
|
|
|
|
Variadic: true,
|
|
|
|
VariableType: &name.FullyQualified{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:32:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
DefaultValue: &scalar.String{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "'default'",
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " \\ Foo ...$var = 'default'"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNullable(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&node.Nullable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 09:56:50 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Expr: &node.Parameter{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: false,
|
|
|
|
VariableType: &name.FullyQualified{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:32:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Value: "var",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DefaultValue: &scalar.String{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "'default'",
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " ? \\Foo & $var = 'default'"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintArgument(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&node.Argument{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EllipsisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
IsReference: false,
|
|
|
|
Variadic: true,
|
2018-07-02 17:48:55 +00:00
|
|
|
Expr: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Value: "var",
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " ... $var"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintArgumentByRef(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&node.Argument{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
IsReference: true,
|
|
|
|
Variadic: false,
|
2018-07-02 17:48:55 +00:00
|
|
|
Expr: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{
|
|
|
|
Value: "var",
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " & $var"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// name
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNameNamePart(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&name.NamePart{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.CommentType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: "/*comment*/",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.NsSeparatorToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Value: "foo",
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " /*comment*/ foo "
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNameName(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&name.Name{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.CommentType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: "/*comment*/",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.NsSeparatorToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
&name.NamePart{
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " /*comment*/ Foo \\Bar"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNameFullyQualified(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&name.FullyQualified{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:32:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
&name.NamePart{
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " \\Foo\\Bar"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNameRelative(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&name.Relative{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:32:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.NsSeparatorToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
&name.NamePart{
|
|
|
|
Value: "Bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := " namespace \\Foo\\Bar"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scalar
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarLNumber(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&scalar.Lnumber{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:43:04 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "1",
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := " 1"
|
|
|
|
actual := o.String()
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarDNumber(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&scalar.Dnumber{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:43:04 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: ".1",
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := " .1"
|
|
|
|
actual := o.String()
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarString(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&scalar.String{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "'hello world'",
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` 'hello world'`
|
2018-04-03 16:59:20 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
2018-03-18 20:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarEncapsedStringPart(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&scalar.EncapsedStringPart{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:46:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "hello world",
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
if o.String() != ` hello world` {
|
2018-03-18 20:27:34 +00:00
|
|
|
t.Errorf("TestPrintScalarEncapsedStringPart is failed\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarEncapsed(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&scalar.Encapsed{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:50:40 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Parts: []node.Node{
|
|
|
|
&scalar.EncapsedStringPart{Value: "hello "},
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
&scalar.EncapsedStringPart{Value: " world"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
if o.String() != ` "hello $var world"` {
|
2018-03-18 20:27:34 +00:00
|
|
|
t.Errorf("TestPrintScalarEncapsed is failed\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarHeredoc(t *testing.T) {
|
2018-04-05 21:39:04 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 21:39:04 +00:00
|
|
|
p.Print(&scalar.Heredoc{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:52:44 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-05 21:39:04 +00:00
|
|
|
Label: "LBL",
|
|
|
|
Parts: []node.Node{
|
|
|
|
&scalar.EncapsedStringPart{Value: "hello "},
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-14 15:00:48 +00:00
|
|
|
&scalar.EncapsedStringPart{Value: " world"},
|
2018-04-05 21:39:04 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` <<<LBL
|
2018-07-29 08:44:38 +00:00
|
|
|
hello $var world
|
2018-04-05 21:39:04 +00:00
|
|
|
LBL`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarNowdoc(t *testing.T) {
|
2018-04-05 21:39:04 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 21:39:04 +00:00
|
|
|
p.Print(&scalar.Heredoc{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:52:44 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-05 21:39:04 +00:00
|
|
|
Label: "'LBL'",
|
|
|
|
Parts: []node.Node{
|
2018-07-14 15:00:48 +00:00
|
|
|
&scalar.EncapsedStringPart{Value: "hello world"},
|
2018-04-05 21:39:04 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` <<<'LBL'
|
2018-04-05 21:39:04 +00:00
|
|
|
hello world
|
|
|
|
LBL`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintScalarMagicConstant(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&scalar.MagicConstant{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:54:42 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "__DIR__",
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
if o.String() != ` __DIR__` {
|
2018-03-18 20:27:34 +00:00
|
|
|
t.Errorf("TestPrintScalarMagicConstant is failed\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssign(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Assign{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Expression: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expected := `$a = $b`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintReference(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 09:03:32 +00:00
|
|
|
p.Print(&assign.Reference{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Expression: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a = & $b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignBitwiseAnd(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.BitwiseAnd{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AndEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Expression: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expected := `$a &= $b`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignBitwiseOr(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.BitwiseOr{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OrEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a |=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignBitwiseXor(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.BitwiseXor{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.XorEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ^=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignConcat(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Concat{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ConcatEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a .=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignDiv(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Div{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DivEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a /=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignMinus(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Minus{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.MinusEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a -=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignMod(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Mod{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ModEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a %=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignMul(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Mul{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.MulEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a *=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignPlus(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Plus{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PlusEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a +=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignPow(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.Pow{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PowEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a **=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignShiftLeft(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.ShiftLeft{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SlEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a <<=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAssignShiftRight(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&assign.ShiftRight{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SrEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expression: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a >>=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// binary
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryBitwiseAnd(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.BitwiseAnd{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a &$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryBitwiseOr(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.BitwiseOr{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.VerticalBarToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a |$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryBitwiseXor(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.BitwiseXor{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CaretToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ^$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryBooleanAnd(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.BooleanAnd{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.BooleanAndToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := `$a &&$b`
|
|
|
|
actual := o.String()
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryBooleanOr(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.BooleanOr{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.BooleanOrToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ||$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryCoalesce(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Coalesce{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CoalesceToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ??$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryConcat(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Concat{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DotToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a .$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryDiv(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Div{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SlashToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a /$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryEqual(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Equal{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IsEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ==$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryGreaterOrEqual(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.GreaterOrEqual{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IsGreaterOrEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a >=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryGreater(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Greater{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.GreaterToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a >$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryIdentical(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Identical{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IsIdenticalToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ===$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryLogicalAnd(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.LogicalAnd{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.LogicalAndToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a and$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryLogicalOr(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.LogicalOr{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.LogicalOrToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a or$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryLogicalXor(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.LogicalXor{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.LogicalXorToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a xor$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryMinus(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Minus{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.MinusToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a -$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryMod(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Mod{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PercentToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a %$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryMul(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Mul{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AsteriskToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a *$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryNotEqual(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.NotEqual{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IsNotEqualToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "!=",
|
|
|
|
TokenName: meta.IsNotEqualToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a !=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryNotIdentical(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.NotIdentical{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IsNotIdenticalToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a !==$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryPlus(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Plus{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PlusToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a +$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryPow(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Pow{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PowToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a **$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryShiftLeft(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.ShiftLeft{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SlToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a <<$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinaryShiftRight(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.ShiftRight{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SrToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a >>$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinarySmallerOrEqual(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.SmallerOrEqual{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IsSmallerOrEqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a <=$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinarySmaller(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Smaller{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.LessToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a <$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBinarySpaceship(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&binary.Spaceship{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SpaceshipToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Left: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Right: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a <=>$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// cast
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintArray(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.Array{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(array)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (array)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintBool(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.Bool{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(bool)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (bool)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintDouble(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.Double{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(float)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (float)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintInt(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.Int{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(int)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (int)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintObject(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.Object{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(object)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (object)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintString(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.String{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(string)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (string)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintUnset(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-05 08:59:29 +00:00
|
|
|
p.Print(&cast.Unset{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(unset)",
|
2018-10-25 11:04:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` (unset)$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// expr
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprArrayDimFetch(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ArrayDimFetch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenSquareBracket,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "[",
|
|
|
|
TokenName: meta.OpenSquareBracket,
|
|
|
|
},
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseSquareBracket,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "]",
|
|
|
|
TokenName: meta.CloseSquareBracket,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
|
|
|
Dim: &scalar.Lnumber{Value: "1"},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$var [1 ]`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprArrayItemWithKey(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ArrayItem{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DoubleArrowToken,
|
|
|
|
},
|
|
|
|
},
|
2018-05-14 15:09:11 +00:00
|
|
|
Key: &scalar.String{Value: "'Hello'"},
|
2018-07-02 17:48:55 +00:00
|
|
|
Val: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "world"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expected := `'Hello' => $world`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprArrayItem(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Reference{Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "world"},
|
|
|
|
}},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expected := `&$world`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprArray(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Array{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:13:36 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Items: []node.Node{
|
|
|
|
&expr.ArrayItem{
|
2018-05-14 15:09:11 +00:00
|
|
|
Key: &scalar.String{Value: "'Hello'"},
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "world"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
2018-05-14 15:09:11 +00:00
|
|
|
Key: &scalar.Lnumber{Value: "2"},
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Reference{Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
}},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` array ('Hello'=>$world,2=>&$var,$var )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprBitwiseNot(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.BitwiseNot{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:15:54 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` ~$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprBooleanNot(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.BooleanNot{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:16:46 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` !$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprClassConstFetch(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ClassConstFetch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PaamayimNekudotayimToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Class: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
ConstantName: &node.Identifier{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 09:31:17 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "CONST",
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$var :: CONST`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprClone(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Clone{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:19:45 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` clone$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprClosureUse(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ClosureUse{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:22:34 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-05-25 06:38:44 +00:00
|
|
|
Uses: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Reference{Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "foo"},
|
|
|
|
}},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "bar"},
|
|
|
|
},
|
2018-05-25 06:38:44 +00:00
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` use (&$foo,$bar )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprClosure(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Closure{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:29:27 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.FunctionToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-04-02 20:57:22 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Static: true,
|
|
|
|
ReturnsRef: true,
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: false,
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ClosureUse: &expr.ClosureUse{
|
|
|
|
Uses: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Reference{Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ReturnType: &name.FullyQualified{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Parts: []node.Node{&name.NamePart{Value: "Foo"}},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` static function & (&$var )use(&$a,$b) :\Foo {$a }`
|
2018-07-02 17:48:55 +00:00
|
|
|
actual := o.String()
|
2018-03-18 20:27:34 +00:00
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprConstFetch(t *testing.T) {
|
2018-03-20 17:48:55 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ConstFetch{
|
2018-03-20 17:48:55 +00:00
|
|
|
Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}},
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := "null"
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintEmpty(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Empty{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 08:50:21 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` empty ($var )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrettyPrinterrorSuppress(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.ErrorSuppress{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 08:53:54 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` @$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintEval(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Eval{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 08:55:59 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` eval ($var )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExit(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Exit{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 08:58:21 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-09 21:51:02 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-09 21:51:02 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-09 21:51:02 +00:00
|
|
|
Die: false,
|
2018-07-02 17:48:55 +00:00
|
|
|
Expr: &expr.Variable{
|
2018-10-24 14:04:13 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` exit $var `
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
2018-07-09 21:51:02 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrinterPrintDie(t *testing.T) {
|
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Exit{
|
|
|
|
Die: true,
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-09 21:51:02 +00:00
|
|
|
Value: " ",
|
2018-10-26 08:58:21 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-09 21:51:02 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-09 21:51:02 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-09 21:51:02 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Expr: &expr.Variable{
|
2018-10-24 14:04:13 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-09 21:51:02 +00:00
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` die $var `
|
2018-07-09 21:51:02 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
2018-03-18 20:27:34 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintFunctionCall(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.FunctionCall{
|
2018-10-24 14:04:13 +00:00
|
|
|
Function: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
|
|
|
&node.Argument{
|
|
|
|
IsReference: true,
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
|
|
|
&node.Argument{
|
|
|
|
Variadic: true,
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$var (&$a,...$b,$c )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintInclude(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Include{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:01:47 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Expr: &scalar.String{Value: "'path'"},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` include'path'`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintIncludeOnce(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.IncludeOnce{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:02:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
}, Expr: &scalar.String{Value: "'path'"},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` include_once'path'`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintInstanceOf(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.InstanceOf{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.InstanceofToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Class: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$var instanceofFoo`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintIsset(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Isset{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:03:45 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Variables: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` isset ($a,$b )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintList(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.List{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:06:16 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Items: []node.Node{
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
|
|
|
Val: &expr.List{
|
|
|
|
Items: []node.Node{
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` list ($a,list($b,$c) )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintMethodCall(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.MethodCall{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ObjectOperatorToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "foo"},
|
|
|
|
},
|
|
|
|
Method: &node.Identifier{Value: "bar"},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$foo ->bar ($a,$b )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNew(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.New{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:08:07 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Class: &name.Name{
|
|
|
|
Parts: []node.Node{
|
|
|
|
&name.NamePart{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:08:39 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "Foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` new Foo ($a,$b )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPostDec(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.PostDec{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DecToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$var --`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPostInc(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.PostInc{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.IncToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$var ++`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPreDec(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.PreDec{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:11:37 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` --$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPreInc(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.PreInc{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:11:37 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` ++$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPrint(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Print{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-26 09:31:30 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Expr: &expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-07-29 08:44:38 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` print $var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPropertyFetch(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.PropertyFetch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ObjectOperatorToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "foo"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Property: &node.Identifier{Value: "bar"},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$foo ->bar`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprReference(t *testing.T) {
|
2018-05-14 15:09:11 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-05-14 15:09:11 +00:00
|
|
|
p.Print(&expr.Reference{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:28:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "foo"},
|
|
|
|
},
|
2018-05-14 15:09:11 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` &$foo`
|
2018-05-14 15:09:11 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintRequire(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Require{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:30:32 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Expr: &scalar.String{Value: "'path'"},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` require'path'`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintRequireOnce(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.RequireOnce{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:30:32 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Expr: &scalar.String{Value: "'path'"},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` require_once'path'`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintShellExec(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ShellExec{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:32:54 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Parts: []node.Node{
|
|
|
|
&scalar.EncapsedStringPart{Value: "hello "},
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "world"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
&scalar.EncapsedStringPart{Value: "!"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := " `hello $world!`"
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExprShortArray(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ShortArray{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:38:06 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseSquareBracket,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Items: []node.Node{
|
|
|
|
&expr.ArrayItem{
|
2018-04-03 16:59:20 +00:00
|
|
|
Key: &scalar.String{Value: "'Hello'"},
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "world"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
2018-05-14 15:09:11 +00:00
|
|
|
Key: &scalar.Lnumber{Value: "2"},
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Reference{Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
}},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` ['Hello'=>$world,2=>&$var,$var ]`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintShortList(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.ShortList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:38:06 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseSquareBracket,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Items: []node.Node{
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
|
|
|
Val: &expr.List{
|
|
|
|
Items: []node.Node{
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
&expr.ArrayItem{
|
2018-10-24 14:04:13 +00:00
|
|
|
Val: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` [$a,list($b,$c) ]`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStaticCall(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.StaticCall{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PaamayimNekudotayimToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
Class: &node.Identifier{Value: "Foo"},
|
|
|
|
Call: &node.Identifier{Value: "bar"},
|
2018-04-29 16:58:49 +00:00
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
Arguments: []node.Node{
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-29 16:58:49 +00:00
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `Foo ::bar ($a,$b )`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStaticPropertyFetch(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.StaticPropertyFetch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PaamayimNekudotayimToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Class: &node.Identifier{Value: "Foo"},
|
|
|
|
Property: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "bar"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `Foo ::$bar`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintTernary(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Ternary{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.QuestionMarkToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Condition: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
IfFalse: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ? :$b`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintTernaryFull(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Ternary{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.QuestionMarkToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Condition: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
IfTrue: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
|
|
|
IfFalse: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a ?$b :$c`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintUnaryMinus(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.UnaryMinus{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:41:52 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` -$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintUnaryPlus(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.UnaryPlus{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:43:55 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` +$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintVariable(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&expr.Variable{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
VarName: &expr.Variable{
|
2018-10-24 14:04:13 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
|
|
|
})
|
2018-03-18 20:27:34 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` $$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintYieldFrom(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.YieldFrom{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:45:47 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` yield from$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintYield(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Yield{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:47:32 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Value: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` yield$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintYieldFull(t *testing.T) {
|
2018-03-18 20:27:34 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&expr.Yield{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:47:32 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DoubleArrowToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Key: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "k"},
|
|
|
|
},
|
|
|
|
Value: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-03-18 20:27:34 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` yield$k =>$var`
|
2018-03-18 20:27:34 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 20:50:07 +00:00
|
|
|
|
|
|
|
// stmt
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltElseIf(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.AltElseIf{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:50:48 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` elseif ($a ) :$b`
|
2018-04-02 19:50:36 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltElseIfEmpty(t *testing.T) {
|
2018-04-02 19:50:36 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.AltElseIf{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:50:48 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-02 19:50:36 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` elseif ($a ) :`
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltElse(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.AltElse{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:52:27 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` else :$b`
|
2018-04-02 19:50:36 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltElseEmpty(t *testing.T) {
|
2018-04-02 19:50:36 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.AltElse{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:52:27 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-02 19:50:36 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := ` else :`
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltFor(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.AltFor{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:54:59 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ForInitSemicolonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ForCondSemicolonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EndforToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Init: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Cond: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Loop: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "d"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` for ($a ;$b ;$c ) :$d endfor `
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltForeach(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.AltForeach{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:57:15 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AsToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DoubleArrowToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EndforeachToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
|
|
|
Key: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "key"},
|
|
|
|
},
|
|
|
|
Variable: &expr.Reference{Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "val"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "d"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` foreach ($var as$key =>&$val ) :$d endforeach `
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltIf(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.AltIf{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:01:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EndifToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "d"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ElseIf: []node.Node{
|
|
|
|
&stmt.AltElseIf{
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
&stmt.AltElseIf{
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Else: &stmt.AltElse{
|
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` if ($a ) :$delseif($b):$belseif($c):else:$b endif `
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtAltSwitch(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.AltSwitch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:01:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EndswitchToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
CaseList: &stmt.CaseList{
|
|
|
|
Cases: []node.Node{
|
|
|
|
&stmt.Case{
|
|
|
|
Cond: &scalar.String{Value: "'a'"},
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Case{
|
|
|
|
Cond: &scalar.String{Value: "'b'"},
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` switch ($var ) :case'a':$acase'b':$b endswitch `
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintAltWhile(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.AltWhile{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:04:44 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EndwhileToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` while ($a ) :$b endwhile `
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtBreak(t *testing.T) {
|
2018-03-20 10:21:21 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Break{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:06:34 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Expr: &scalar.Lnumber{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-07-29 08:44:38 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "1",
|
|
|
|
},
|
2018-03-20 10:21:21 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := " break 1 "
|
2018-03-20 10:21:21 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtCase(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Case{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:08:09 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` case$a:$a`
|
2018-04-02 19:50:36 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtCaseEmpty(t *testing.T) {
|
2018-04-02 19:50:36 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Case{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:08:09 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-02 19:50:36 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := " case$a:"
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtCatch(t *testing.T) {
|
2018-03-20 10:21:21 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Catch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:10:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Exception"}}},
|
|
|
|
&name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "RuntimeException"}}},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "e"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-03-20 10:21:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` catch (Exception|\RuntimeException$e ) {$a }`
|
2018-03-20 10:21:21 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtClassMethod(t *testing.T) {
|
2018-03-20 17:48:55 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.ClassMethod{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.FunctionToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-20 17:48:55 +00:00
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
ReturnsRef: true,
|
|
|
|
MethodName: &node.Identifier{Value: "foo"},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
ByRef: true,
|
|
|
|
VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-20 17:48:55 +00:00
|
|
|
DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Variadic: true,
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-20 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
ReturnType: &name.Name{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Parts: []node.Node{&name.NamePart{Value: "void"}},
|
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
2018-06-03 06:35:44 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-06-03 06:35:44 +00:00
|
|
|
},
|
2018-03-20 17:48:55 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `public function &foo (?int&$a=null,...$b ) :void {$a }`
|
2018-03-20 17:48:55 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
2018-06-30 21:05:59 +00:00
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-07-29 08:44:38 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtAbstractClassMethod(t *testing.T) {
|
2018-06-30 21:05:59 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-06-30 21:05:59 +00:00
|
|
|
p.Print(&stmt.ClassMethod{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.FunctionToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-06-30 21:05:59 +00:00
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
ReturnsRef: true,
|
|
|
|
MethodName: &node.Identifier{Value: "foo"},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
ByRef: true,
|
|
|
|
VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-06-30 21:05:59 +00:00
|
|
|
DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}},
|
|
|
|
},
|
|
|
|
&node.Parameter{
|
|
|
|
Variadic: true,
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-06-30 21:05:59 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
ReturnType: &name.Name{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Parts: []node.Node{&name.NamePart{Value: "void"}},
|
|
|
|
},
|
|
|
|
Stmt: &stmt.Nop{},
|
2018-06-30 21:05:59 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `public function &foo (?int&$a=null,...$b ) :void`
|
2018-06-30 21:05:59 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
2018-03-20 17:48:55 +00:00
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtClass(t *testing.T) {
|
2018-03-20 18:06:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Class{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ClassToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
|
|
|
|
ClassName: &node.Identifier{Value: "Foo"},
|
|
|
|
Extends: &stmt.ClassExtends{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ExtendsToken,
|
2018-05-12 20:10:01 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
},
|
|
|
|
Implements: &stmt.ClassImplements{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ImplementsToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
InterfaceNames: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.ClassConstList{
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
|
|
|
Expr: &scalar.String{Value: "'bar'"},
|
2018-03-20 18:06:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `abstract classFoo extendsBar implementsBaz,Quuz {publicconstFOO='bar' }`
|
2018-03-20 18:06:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtAnonymousClass(t *testing.T) {
|
2018-03-20 18:06:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Class{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ClassToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
|
|
|
|
ArgumentList: &node.ArgumentList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
2018-05-12 20:10:01 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Arguments: []node.Node{
|
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
&node.Argument{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Extends: &stmt.ClassExtends{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ExtendsToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
},
|
|
|
|
Implements: &stmt.ClassImplements{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ImplementsToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InterfaceNames: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.ClassConstList{
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
|
|
|
Expr: &scalar.String{Value: "'bar'"},
|
2018-03-20 18:06:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `abstract class ($a,$b ) extendsBar implementsBaz,Quuz {publicconstFOO='bar' }`
|
2018-03-20 18:06:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtClassConstList(t *testing.T) {
|
2018-03-20 18:37:55 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.ClassConstList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ConstToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-03-20 18:37:55 +00:00
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
2018-04-03 16:59:20 +00:00
|
|
|
Expr: &scalar.String{Value: "'a'"},
|
2018-03-20 18:37:55 +00:00
|
|
|
},
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "BAR"},
|
2018-04-03 16:59:20 +00:00
|
|
|
Expr: &scalar.String{Value: "'b'"},
|
2018-03-20 18:37:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `public constFOO='a',BAR='b' `
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrinterPrintStmtConstList(t *testing.T) {
|
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.ConstList{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: " ",
|
2018-10-29 11:25:46 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
|
|
|
Expr: &scalar.String{Value: "'a'"},
|
|
|
|
},
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "BAR"},
|
|
|
|
Expr: &scalar.String{Value: "'b'"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := ` constFOO='a',BAR='b' `
|
2018-03-20 18:37:55 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtConstant(t *testing.T) {
|
2018-03-20 10:21:21 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Constant{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-20 10:21:21 +00:00
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
2018-04-03 16:59:20 +00:00
|
|
|
Expr: &scalar.String{Value: "'BAR'"},
|
2018-03-20 10:21:21 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := "FOO ='BAR'"
|
2018-03-20 10:21:21 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtContinue(t *testing.T) {
|
2018-03-20 18:37:55 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Continue{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:27:30 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Expr: &scalar.Lnumber{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-07-29 08:44:38 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Value: "1",
|
|
|
|
},
|
2018-03-20 18:37:55 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` continue 1 `
|
2018-03-20 18:37:55 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDeclareStmts(t *testing.T) {
|
2018-03-28 20:44:02 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Declare{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:29:04 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
|
|
|
Expr: &scalar.String{Value: "'bar'"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
2018-03-28 20:44:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` declare (FOO='bar' ){}`
|
2018-03-28 20:44:02 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDeclareExpr(t *testing.T) {
|
2018-03-28 20:44:02 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Declare{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:29:04 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
2018-03-28 20:44:02 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
|
|
|
Expr: &scalar.String{Value: "'bar'"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}},
|
2018-03-28 20:44:02 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` declare (FOO='bar' )'bar'`
|
2018-03-28 20:44:02 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDeclareNop(t *testing.T) {
|
2018-03-28 20:44:02 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Declare{
|
2018-03-28 20:44:02 +00:00
|
|
|
Consts: []node.Node{
|
|
|
|
&stmt.Constant{
|
|
|
|
ConstantName: &node.Identifier{Value: "FOO"},
|
2018-04-03 16:59:20 +00:00
|
|
|
Expr: &scalar.String{Value: "'bar'"},
|
2018-03-28 20:44:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmt: &stmt.Nop{},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `declare(FOO='bar')`
|
2018-03-28 20:44:02 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
2018-03-28 21:04:09 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDefalut(t *testing.T) {
|
2018-03-28 21:04:09 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Default{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:30:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-28 21:04:09 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-03-28 21:04:09 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` default:$a`
|
2018-04-02 19:50:36 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDefalutEmpty(t *testing.T) {
|
2018-04-02 19:50:36 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Default{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:30:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-02 19:50:36 +00:00
|
|
|
Stmts: []node.Node{},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` default:`
|
2018-03-28 21:04:09 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDo_Expression(t *testing.T) {
|
2018-03-28 21:04:09 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Do{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:31:44 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.WhileToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-03-28 21:04:09 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Cond: &scalar.Lnumber{Value: "1"},
|
|
|
|
Stmt: &stmt.Expression{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-03-28 21:04:09 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` do$a while (1 ) `
|
2018-03-28 21:04:09 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtDo_StmtList(t *testing.T) {
|
2018-03-28 21:04:09 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Do{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:31:44 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.WhileToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Cond: &scalar.Lnumber{Value: "1"},
|
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-03-28 21:04:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` do{$a} while (1 ) `
|
2018-03-28 21:04:09 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
2018-03-31 11:08:56 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtEcho(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Echo{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "echo",
|
2018-10-29 11:36:03 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-29 08:44:38 +00:00
|
|
|
},
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:36:03 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-03-31 11:08:56 +00:00
|
|
|
Exprs: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-31 11:08:56 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `echo $a,$b `
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtElseIfStmts(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.ElseIf{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:50:48 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-31 11:08:56 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` elseif ($a ){}`
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtElseIfExpr(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.ElseIf{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:50:48 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-03 16:59:20 +00:00
|
|
|
Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}},
|
2018-03-31 11:08:56 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` elseif ($a )'bar'`
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtElseIfNop(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.ElseIf{
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-31 11:08:56 +00:00
|
|
|
Stmt: &stmt.Nop{},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `elseif($a)`
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtElseStmts(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Else{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:52:27 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-03-31 11:08:56 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` else{}`
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtElseExpr(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Else{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:52:27 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-03 16:59:20 +00:00
|
|
|
Stmt: &stmt.Expression{Expr: &scalar.String{Value: "'bar'"}},
|
2018-03-31 11:08:56 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` else'bar'`
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtElseNop(t *testing.T) {
|
2018-03-31 11:08:56 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Else{
|
2018-03-31 11:08:56 +00:00
|
|
|
Stmt: &stmt.Nop{},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `else`
|
2018-03-31 11:08:56 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
2018-03-28 20:44:02 +00:00
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintExpression(t *testing.T) {
|
2018-03-19 20:50:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Expression{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-03-19 20:50:07 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `$a `
|
2018-03-19 20:50:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtFinally(t *testing.T) {
|
2018-03-31 11:49:29 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Finally{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:38:02 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-03 16:20:55 +00:00
|
|
|
Stmts: []node.Node{
|
2018-07-02 17:48:55 +00:00
|
|
|
&stmt.Nop{},
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` finally { }`
|
2018-03-31 11:49:29 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtFor(t *testing.T) {
|
2018-03-31 11:49:29 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.For{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:54:59 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ForInitSemicolonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ForCondSemicolonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-03-31 11:49:29 +00:00
|
|
|
Init: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
|
|
|
Cond: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "d"},
|
|
|
|
},
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
|
|
|
Loop: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "e"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "f"},
|
|
|
|
},
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` for ($a,$b ;$c,$d ;$e,$f ){}`
|
2018-03-31 11:49:29 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtForeach(t *testing.T) {
|
2018-03-31 11:49:29 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Foreach{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 10:57:15 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AsToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.DoubleArrowToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Key: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "k"},
|
|
|
|
},
|
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "v"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
|
|
|
},
|
|
|
|
},
|
2018-03-31 11:49:29 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` foreach ($a as$k =>$v ){}`
|
2018-03-31 11:49:29 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 12:58:45 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtFunction(t *testing.T) {
|
2018-03-31 11:49:29 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Function{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:42:50 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AmpersandToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ReturnsRef: true,
|
|
|
|
FunctionName: &node.Identifier{Value: "foo"},
|
|
|
|
Params: []node.Node{
|
|
|
|
&node.Parameter{
|
|
|
|
ByRef: true,
|
|
|
|
Variadic: false,
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
ReturnType: &name.FullyQualified{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Parts: []node.Node{&name.NamePart{Value: "Foo"}},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
2018-03-31 11:49:29 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` function &foo (&$var ) :\Foo { }`
|
2018-03-31 11:49:29 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtGlobal(t *testing.T) {
|
2018-04-01 12:58:45 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Global{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:44:46 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 12:58:45 +00:00
|
|
|
Vars: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-01 12:58:45 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` global$a,$b `
|
2018-04-01 12:58:45 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtGoto(t *testing.T) {
|
2018-04-01 12:58:45 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Goto{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:45:50 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 12:58:45 +00:00
|
|
|
Label: &node.Identifier{Value: "FOO"},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` gotoFOO `
|
2018-04-01 12:58:45 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtGroupUse(t *testing.T) {
|
2018-04-01 12:58:45 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.GroupUse{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:22:34 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.NsSeparatorToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 12:58:45 +00:00
|
|
|
UseType: &node.Identifier{Value: "function"},
|
|
|
|
Prefix: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
UseList: []node.Node{
|
|
|
|
&stmt.Use{
|
|
|
|
Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
Alias: &node.Identifier{Value: "Baz"},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
|
|
|
Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` usefunctionFoo \ {BarasBaz,Quuz } `
|
2018-04-01 12:58:45 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintHaltCompiler(t *testing.T) {
|
2018-04-01 12:58:45 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.HaltCompiler{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.HaltCompilerToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
})
|
2018-04-01 12:58:45 +00:00
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` __halt_compiler ( ) `
|
2018-04-01 12:58:45 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintIfExpression(t *testing.T) {
|
2018-04-01 14:07:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.If{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:01:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.Expression{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
ElseIf: []node.Node{
|
|
|
|
&stmt.ElseIf{
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Expression{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "d"},
|
|
|
|
},
|
2018-04-01 14:07:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
&stmt.ElseIf{
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "e"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.Nop{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Else: &stmt.Else{
|
|
|
|
Stmt: &stmt.Expression{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "f"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 14:07:07 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` if ($a )$belseif($c){$d}elseif($e)else$f`
|
2018-04-01 14:07:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintIfStmtList(t *testing.T) {
|
2018-04-01 14:07:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.If{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:01:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Expression{
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-01 14:07:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` if ($a ){$b}`
|
2018-04-01 14:07:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintIfNop(t *testing.T) {
|
2018-04-01 14:07:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.If{
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-01 14:07:07 +00:00
|
|
|
Stmt: &stmt.Nop{},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `if($a)`
|
2018-04-01 14:07:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintInlineHtml(t *testing.T) {
|
2018-04-01 14:07:07 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.InlineHtml{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.InlineHTMLToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-01 14:07:07 +00:00
|
|
|
Value: "test",
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` test`
|
2018-04-01 14:07:07 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintInterface(t *testing.T) {
|
2018-04-01 21:28:01 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Interface{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.InterfaceToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InterfaceName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Extends: &stmt.InterfaceExtends{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ExtendsToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
InterfaceNames: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.ClassMethod{
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
MethodName: &node.Identifier{Value: "foo"},
|
|
|
|
Params: []node.Node{},
|
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-04-01 21:28:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` interfaceFoo extendsBar,Baz {publicfunctionfoo(){$a} }`
|
2018-04-01 21:28:01 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintLabel(t *testing.T) {
|
2018-04-01 21:28:01 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Label{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ColonToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-01 21:28:01 +00:00
|
|
|
LabelName: &node.Identifier{Value: "FOO"},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `FOO :`
|
2018-04-01 21:28:01 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNamespace(t *testing.T) {
|
2018-04-01 21:28:01 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Namespace{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:32:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 21:28:01 +00:00
|
|
|
NamespaceName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` namespaceFoo `
|
2018-04-01 21:28:01 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNamespaceWithStmts(t *testing.T) {
|
2018-04-01 21:28:01 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Namespace{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 10:32:18 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NamespaceName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-04-01 21:28:01 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` namespaceFoo {$a }`
|
2018-04-01 21:28:01 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintNop(t *testing.T) {
|
2018-03-28 20:44:02 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Nop{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-07-29 08:44:38 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2018-03-28 20:44:02 +00:00
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` `
|
2018-03-28 20:44:02 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 12:58:45 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintPropertyList(t *testing.T) {
|
2018-04-01 21:43:27 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.PropertyList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 21:43:27 +00:00
|
|
|
Modifiers: []node.Node{
|
|
|
|
&node.Identifier{Value: "public"},
|
|
|
|
&node.Identifier{Value: "static"},
|
|
|
|
},
|
|
|
|
Properties: []node.Node{
|
|
|
|
&stmt.Property{
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-01 21:43:27 +00:00
|
|
|
},
|
|
|
|
&stmt.Property{
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-01 21:43:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `publicstatic$a,$b `
|
2018-04-01 21:43:27 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintProperty(t *testing.T) {
|
2018-04-01 21:43:27 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Property{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expr: &scalar.Lnumber{Value: "1"},
|
2018-04-01 21:43:27 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a =1`
|
2018-04-01 21:43:27 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintReturn(t *testing.T) {
|
2018-04-01 21:43:27 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Return{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ReturnToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 21:43:27 +00:00
|
|
|
Expr: &scalar.Lnumber{Value: "1"},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` return1 `
|
2018-04-01 21:43:27 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStaticVar(t *testing.T) {
|
2018-04-01 21:59:31 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.StaticVar{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.EqualToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Expr: &scalar.Lnumber{Value: "1"},
|
2018-04-01 21:59:31 +00:00
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `$a =1`
|
2018-04-01 21:59:31 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStatic(t *testing.T) {
|
2018-04-01 21:59:31 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Static{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:29:27 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 21:59:31 +00:00
|
|
|
Vars: []node.Node{
|
|
|
|
&stmt.StaticVar{
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-04-01 21:59:31 +00:00
|
|
|
},
|
|
|
|
&stmt.StaticVar{
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-01 21:59:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` static$a,$b `
|
2018-04-01 21:59:31 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtList(t *testing.T) {
|
2018-04-01 21:59:31 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.StmtList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-01 21:59:31 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-04-01 21:59:31 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` {$a$b }`
|
2018-04-01 21:59:31 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtListNested(t *testing.T) {
|
2018-04-01 21:59:31 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-03 16:20:55 +00:00
|
|
|
p.Print(&stmt.StmtList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-03 16:20:55 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
&stmt.StmtList{
|
2018-04-01 21:59:31 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
&stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "c"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-01 21:59:31 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` {$a{$b{$c}} }`
|
2018-04-03 16:20:55 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtSwitch(t *testing.T) {
|
2018-04-03 16:20:55 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Switch{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:01:41 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
CaseList: &stmt.CaseList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Cases: []node.Node{
|
|
|
|
&stmt.Case{
|
|
|
|
Cond: &scalar.String{Value: "'a'"},
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&stmt.Case{
|
|
|
|
Cond: &scalar.String{Value: "'b'"},
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-04-01 21:59:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` switch ($var ) {case'a':$acase'b':$b }`
|
2018-04-01 21:59:31 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtThrow(t *testing.T) {
|
2018-04-01 22:29:24 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Throw{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.ThrowToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "var"},
|
|
|
|
},
|
2018-04-01 22:29:24 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` throw$var `
|
2018-04-01 22:29:24 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTraitMethodRef(t *testing.T) {
|
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.TraitMethodRef{
|
|
|
|
Method: &node.Identifier{Value: "a"},
|
|
|
|
})
|
|
|
|
|
|
|
|
expected := `a`
|
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-07-29 08:44:38 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTraitMethodRefFull(t *testing.T) {
|
2018-04-01 22:29:24 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.TraitMethodRef{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.PaamayimNekudotayimToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-01 22:29:24 +00:00
|
|
|
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Method: &node.Identifier{Value: "a"},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `Foo ::a`
|
2018-04-01 22:29:24 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTraitUseAlias(t *testing.T) {
|
2018-04-01 22:29:24 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.TraitUseAlias{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AsToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 22:29:24 +00:00
|
|
|
Ref: &stmt.TraitMethodRef{
|
|
|
|
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Method: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Modifier: &node.Identifier{Value: "public"},
|
|
|
|
Alias: &node.Identifier{Value: "b"},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `Foo::a aspublicb `
|
2018-04-01 22:29:24 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTraitUsePrecedence(t *testing.T) {
|
2018-04-01 22:29:24 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.TraitUsePrecedence{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.InsteadofToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-01 22:29:24 +00:00
|
|
|
Ref: &stmt.TraitMethodRef{
|
|
|
|
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Method: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
Insteadof: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := `Foo::a insteadofBar,Baz `
|
2018-04-01 22:29:24 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTraitUse(t *testing.T) {
|
2018-04-01 22:29:24 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.TraitUse{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:22:34 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-01 22:29:24 +00:00
|
|
|
Traits: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
TraitAdaptationList: &stmt.Nop{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-01 22:29:24 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` useFoo,Bar `
|
2018-04-01 22:29:24 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTraitAdaptations(t *testing.T) {
|
2018-04-01 22:29:24 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.TraitUse{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:22:34 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Traits: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
|
|
|
},
|
|
|
|
TraitAdaptationList: &stmt.TraitAdaptationList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Adaptations: []node.Node{
|
|
|
|
&stmt.TraitUseAlias{
|
|
|
|
Ref: &stmt.TraitMethodRef{
|
|
|
|
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Method: &node.Identifier{Value: "a"},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Alias: &node.Identifier{Value: "b"},
|
2018-04-01 22:29:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` useFoo,Bar {Foo::aasb }`
|
2018-04-01 22:29:24 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintTrait(t *testing.T) {
|
2018-04-02 09:41:47 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Trait{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.TraitToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TraitName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
2018-04-02 09:41:47 +00:00
|
|
|
Stmts: []node.Node{
|
2018-07-02 17:48:55 +00:00
|
|
|
&stmt.ClassMethod{
|
|
|
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
|
|
MethodName: &node.Identifier{Value: "foo"},
|
|
|
|
Params: []node.Node{},
|
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` traitFoo {publicfunctionfoo(){$a} }`
|
2018-04-02 09:41:47 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtTry(t *testing.T) {
|
2018-04-02 09:41:47 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.Try{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.TryToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenCurlyBracesToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseCurlyBracesToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
Catches: []node.Node{
|
|
|
|
&stmt.Catch{
|
|
|
|
Types: []node.Node{
|
|
|
|
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Exception"}}},
|
|
|
|
&name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "RuntimeException"}}},
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Variable: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "e"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
}},
|
2018-04-02 09:41:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Finally: &stmt.Finally{
|
|
|
|
Stmts: []node.Node{
|
|
|
|
&stmt.Nop{},
|
|
|
|
},
|
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` try {$a }catch(Exception|\RuntimeException$e){$b}finally{}`
|
2018-04-02 09:41:47 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtUnset(t *testing.T) {
|
2018-04-02 09:41:47 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Unset{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.UnsetToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
Vars: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
|
|
|
&expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "b"},
|
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` unset ($a,$b ) `
|
2018-04-02 09:41:47 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintStmtUseList(t *testing.T) {
|
2018-04-02 09:41:47 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.UseList{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-25 11:22:34 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "",
|
|
|
|
TokenName: meta.SemiColonToken,
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
UseType: &node.Identifier{Value: "function"},
|
|
|
|
Uses: []node.Node{
|
|
|
|
&stmt.Use{
|
|
|
|
Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Alias: &node.Identifier{Value: "Bar"},
|
|
|
|
},
|
|
|
|
&stmt.Use{
|
|
|
|
Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` usefunctionFooasBar,Baz `
|
2018-04-02 09:41:47 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintUse(t *testing.T) {
|
2018-04-01 12:58:45 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
2018-04-02 20:57:22 +00:00
|
|
|
p.Print(&stmt.Use{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.AsToken,
|
|
|
|
},
|
|
|
|
},
|
2018-04-01 12:58:45 +00:00
|
|
|
UseType: &node.Identifier{Value: "function"},
|
|
|
|
Use: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
|
|
|
Alias: &node.Identifier{Value: "Bar"},
|
|
|
|
})
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
expected := `functionFoo asBar`
|
2018-04-01 12:58:45 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 09:41:47 +00:00
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
func TestPrinterPrintWhileStmtList(t *testing.T) {
|
2018-04-02 09:41:47 +00:00
|
|
|
o := bytes.NewBufferString("")
|
|
|
|
|
2018-07-02 17:48:55 +00:00
|
|
|
p := printer.NewPrinter(o)
|
|
|
|
p.Print(&stmt.While{
|
2018-07-29 08:44:38 +00:00
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
2018-10-29 11:04:44 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-04-02 09:41:47 +00:00
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
},
|
2018-07-29 08:44:38 +00:00
|
|
|
&meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
2018-07-02 17:48:55 +00:00
|
|
|
Value: " ",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
2018-04-03 16:20:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-24 14:04:13 +00:00
|
|
|
Cond: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
},
|
2018-07-02 17:48:55 +00:00
|
|
|
Stmt: &stmt.StmtList{
|
|
|
|
Stmts: []node.Node{
|
2018-10-24 14:04:13 +00:00
|
|
|
&stmt.Expression{Expr: &expr.Variable{
|
|
|
|
Meta: meta.Collection{
|
|
|
|
&meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "$",
|
2018-10-24 19:32:35 +00:00
|
|
|
TokenName: meta.NodeStart,
|
2018-10-24 14:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
VarName: &node.Identifier{Value: "a"},
|
|
|
|
}},
|
2018-07-02 17:48:55 +00:00
|
|
|
},
|
|
|
|
},
|
2018-04-02 09:41:47 +00:00
|
|
|
})
|
|
|
|
|
2018-07-29 08:44:38 +00:00
|
|
|
expected := ` while ($a ){$a}`
|
2018-04-02 09:41:47 +00:00
|
|
|
actual := o.String()
|
|
|
|
|
|
|
|
if expected != actual {
|
|
|
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
|
|
}
|
|
|
|
}
|