Return tests
This commit is contained in:
		
							parent
							
								
									76d23a199c
								
							
						
					
					
						commit
						ff0651a102
					
				| @ -1,6 +1,7 @@ | |||||||
| package stmt_test | package stmt_test | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/z7zmey/php-parser/node/scalar" | ||||||
| 	"github.com/z7zmey/php-parser/node/name" | 	"github.com/z7zmey/php-parser/node/name" | ||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"testing" | 	"testing" | ||||||
| @ -32,8 +33,31 @@ func TestSimpleFunction(t *testing.T) { | |||||||
| 	assertEqual(t, expected, actual) | 	assertEqual(t, expected, actual) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func TestFunctionReturn(t *testing.T) { | ||||||
|  | 	src := `<? function foo() {return;}` | ||||||
|  | 
 | ||||||
|  | 	expected := &stmt.StmtList{ | ||||||
|  | 		Stmts: []node.Node{ | ||||||
|  | 			&stmt.Function{ | ||||||
|  | 				ReturnsRef: false, | ||||||
|  | 				PhpDocComment: "", | ||||||
|  | 				FunctionName: &node.Identifier{Value: "foo"}, | ||||||
|  | 				Stmts: []node.Node{ | ||||||
|  | 					&stmt.Return{}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	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 TestRefFunction(t *testing.T) { | func TestRefFunction(t *testing.T) { | ||||||
| 	src := `<? function &foo() {}` | 	src := `<? function &foo() {return 1;}` | ||||||
| 
 | 
 | ||||||
| 	expected := &stmt.StmtList{ | 	expected := &stmt.StmtList{ | ||||||
| 		Stmts: []node.Node{ | 		Stmts: []node.Node{ | ||||||
| @ -41,7 +65,11 @@ func TestRefFunction(t *testing.T) { | |||||||
| 				ReturnsRef: true, | 				ReturnsRef: true, | ||||||
| 				PhpDocComment: "", | 				PhpDocComment: "", | ||||||
| 				FunctionName: &node.Identifier{Value: "foo"}, | 				FunctionName: &node.Identifier{Value: "foo"}, | ||||||
| 				Stmts: []node.Node{}, | 				Stmts: []node.Node{ | ||||||
|  | 					&stmt.Return{ | ||||||
|  | 						Expr: &scalar.Lnumber{Value: "1"}, | ||||||
|  | 					}, | ||||||
|  | 				}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user