php5 test coverage

This commit is contained in:
z7zmey 2018-02-13 19:38:37 +02:00
parent 0a34643856
commit b13d520387
6 changed files with 1026 additions and 799 deletions

10
diff
View File

@ -325,12 +325,17 @@
325 325
326 326
327 327
-328
329 329
-330
331 331
-332
333 333
334 334
335 335
336 336
-337
-338
339 339
352 352
354 354
@ -418,11 +423,6 @@
528 528
-328
-330
-332
-337
-338
-340 -340
-341 -341
-342 -342

1654
log

File diff suppressed because it is too large Load Diff

View File

@ -38,3 +38,24 @@ func TestClassConstFetch(t *testing.T) {
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php") actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestStaticClassConstFetch(t *testing.T) {
src := `<? static::bar;`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.ClassConstFetch{
Class: &node.Identifier{Value: "static"},
ConstantName: &node.Identifier{Value: "bar"},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}

View File

@ -91,3 +91,51 @@ func TestStaticCallFullyQualified(t *testing.T) {
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php") actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestStaticCallVar(t *testing.T) {
src := `<? Foo::$bar();`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Call: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
Arguments: []node.Node{},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}
func TestStaticCallVarVar(t *testing.T) {
src := `<? $foo::$bar();`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Expression{
Expr: &expr.StaticCall{
Class: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Call: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
Arguments: []node.Node{},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}

View File

@ -190,3 +190,62 @@ func TestTryCatchFinally(t *testing.T) {
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php") actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestTryCatchCatchCatch(t *testing.T) {
src := `<? try {} catch (Exception $e) {} catch (\RuntimeException $e) {} catch (namespace\AdditionException $e) {}`
expected := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Try{
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Types: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "$e"},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Types: []node.Node{
&name.FullyQualified{
Parts: []node.Node{
&name.NamePart{Value: "RuntimeException"},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "$e"},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Types: []node.Node{
&name.Relative{
Parts: []node.Node{
&name.NamePart{Value: "AdditionException"},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "$e"},
},
Stmts: []node.Node{},
},
},
},
},
}
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
actual, _, _ = php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual)
}

View File

@ -196,7 +196,7 @@ CAD;
try {} try {}
try {} catch (Exception $e) {} try {} catch (Exception $e) {}
try {} catch (Exception $e) {} catch (RuntimeException $e) {} try {} catch (Exception $e) {} catch (RuntimeException $e) {}
try {} catch (Exception $e) {} catch (RuntimeException $e) {} catch (AdditionException $e) {} try {} catch (Exception $e) {} catch (\RuntimeException $e) {} catch (namespace\AdditionException $e) {}
try {} catch (Exception $e) {} finally {} try {} catch (Exception $e) {} finally {}
unset($a, $b); unset($a, $b);
@ -275,6 +275,8 @@ CAD;
Foo::bar(); Foo::bar();
namespace\Foo::bar(); namespace\Foo::bar();
\Foo::bar(); \Foo::bar();
Foo::$bar();
$foo::$bar();
Foo::$bar; Foo::$bar;
namespace\Foo::$bar; namespace\Foo::$bar;
\Foo::$bar; \Foo::$bar;
@ -354,6 +356,7 @@ CAD;
array([0])[0][0]; array([0])[0][0];
"foo"[0]; "foo"[0];
foo[0]; foo[0];
static::foo;
` `
expectedParams := []node.Node{ expectedParams := []node.Node{
@ -1543,7 +1546,7 @@ CAD;
}, },
&stmt.Catch{ &stmt.Catch{
Types: []node.Node{ Types: []node.Node{
&name.Name{ &name.FullyQualified{
Parts: []node.Node{ Parts: []node.Node{
&name.NamePart{Value: "RuntimeException"}, &name.NamePart{Value: "RuntimeException"},
}, },
@ -1556,7 +1559,7 @@ CAD;
}, },
&stmt.Catch{ &stmt.Catch{
Types: []node.Node{ Types: []node.Node{
&name.Name{ &name.Relative{
Parts: []node.Node{ Parts: []node.Node{
&name.NamePart{Value: "AdditionException"}, &name.NamePart{Value: "AdditionException"},
}, },
@ -2254,6 +2257,24 @@ CAD;
Arguments: []node.Node{}, Arguments: []node.Node{},
}, },
}, },
&stmt.Expression{
Expr: &expr.StaticCall{
Class: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
Call: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
Arguments: []node.Node{},
},
},
&stmt.Expression{
Expr: &expr.StaticCall{
Class: &expr.Variable{VarName: &node.Identifier{Value: "$foo"}},
Call: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
Arguments: []node.Node{},
},
},
&stmt.Expression{ &stmt.Expression{
Expr: &expr.StaticPropertyFetch{ Expr: &expr.StaticPropertyFetch{
Class: &name.Name{ Class: &name.Name{
@ -2773,6 +2794,12 @@ CAD;
Dim: &scalar.Lnumber{Value: "0"}, Dim: &scalar.Lnumber{Value: "0"},
}, },
}, },
&stmt.Expression{
Expr: &expr.ClassConstFetch{
Class: &node.Identifier{Value: "static"},
ConstantName: &node.Identifier{Value: "foo"},
},
},
}, },
} }