string test

This commit is contained in:
vadim 2017-12-04 19:50:22 +02:00
parent 8dfa107bc4
commit e31ec50c78

View File

@ -10,7 +10,7 @@ import (
"github.com/z7zmey/php-parser/token" "github.com/z7zmey/php-parser/token"
) )
func TestNewNodeScalarString(t *testing.T) { func TestDoubleQuotedScalarString(t *testing.T) {
src := `<? "test";` src := `<? "test";`
strToken := token.NewToken([]byte("\"test\""), 1, 1) strToken := token.NewToken([]byte("\"test\""), 1, 1)
@ -20,6 +20,103 @@ func TestNewNodeScalarString(t *testing.T) {
node := parser.Parse(bytes.NewBufferString(src), "test.php") node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" { if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("post-AddCrew diff: (-expected +actual)\n%s", diff) t.Errorf("diff: (-expected +actual)\n%s", diff)
}
}
func TestMultilineDoubleQuotedScalarString(t *testing.T) {
src := `<? "
test
";`
strToken := token.NewToken([]byte("\"\n\ttest\n\t\""), 1, 3)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
}
}
func TestSingleQuotedScalarString(t *testing.T) {
src := `<? '$test';`
strToken := token.NewToken([]byte("'$test'"), 1, 1)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
}
}
func TestMultilineSingleQuotedScalarString(t *testing.T) {
src := `<? '
$test
';`
strToken := token.NewToken([]byte("'\n\t$test\n\t'"), 1, 3)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
}
}
func TestPlainHeredocScalarString(t *testing.T) {
src := `<? <<<CAD
hello
CAD;
`
strToken := token.NewToken([]byte("\thello\n"), 2, 3)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
}
}
func TestHeredocScalarString(t *testing.T) {
src := `<? <<<"CAD"
hello
CAD;
`
strToken := token.NewToken([]byte("\thello\n"), 2, 3)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
}
}
func TestNowdocScalarString(t *testing.T) {
src := `<? <<<'CAD'
hello $world
CAD;
`
strToken := token.NewToken([]byte("\thello $world\n"), 2, 3)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if diff := pretty.Compare(expected, node); diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
} }
} }