test: add php8.2 true, null and false types test

This commit is contained in:
Laytan Laats 2023-03-25 15:52:40 +01:00
parent 66cc411e7c
commit ce8b54eae1

View File

@ -99,3 +99,303 @@ final readonly class Boo {
suite.Run()
}
func TestNullFalseTrueTypes(t *testing.T) {
suite := tester.NewParserDumpTestSuite(t)
suite.UsePHP8()
suite.Code = `<?php
function alwaysFalse(false $a): false {}
function alwaysTrue(true $a): true {}
function alwaysNull(null $a): null {}
class Bar {
public null $nil;
public true $true;
public false $false;
public function nil(null $nil): null {}
public function true(true $true): true {}
public function false(false $false): false {}
}
`
suite.Expected = `&ast.Root{
Stmts: []ast.Vertex{
&ast.StmtFunction{
Name: &ast.Identifier{
Val: []byte("alwaysFalse"),
},
Params: []ast.Vertex{
&ast.Parameter{
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("false"),
},
},
},
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$a"),
},
},
},
},
ReturnType: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("false"),
},
},
},
Stmts: []ast.Vertex{},
},
&ast.StmtFunction{
Name: &ast.Identifier{
Val: []byte("alwaysTrue"),
},
Params: []ast.Vertex{
&ast.Parameter{
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("true"),
},
},
},
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$a"),
},
},
},
},
ReturnType: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("true"),
},
},
},
Stmts: []ast.Vertex{},
},
&ast.StmtFunction{
Name: &ast.Identifier{
Val: []byte("alwaysNull"),
},
Params: []ast.Vertex{
&ast.Parameter{
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("null"),
},
},
},
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$a"),
},
},
},
},
ReturnType: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("null"),
},
},
},
Stmts: []ast.Vertex{},
},
&ast.StmtClass{
Name: &ast.Identifier{
Val: []byte("Bar"),
},
Stmts: []ast.Vertex{
&ast.StmtPropertyList{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("null"),
},
},
},
Props: []ast.Vertex{
&ast.StmtProperty{
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$nil"),
},
},
},
},
},
&ast.StmtPropertyList{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("true"),
},
},
},
Props: []ast.Vertex{
&ast.StmtProperty{
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$true"),
},
},
},
},
},
&ast.StmtPropertyList{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("false"),
},
},
},
Props: []ast.Vertex{
&ast.StmtProperty{
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$false"),
},
},
},
},
},
&ast.StmtClassMethod{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Name: &ast.Identifier{
Val: []byte("nil"),
},
Params: []ast.Vertex{
&ast.Parameter{
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("null"),
},
},
},
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$nil"),
},
},
},
},
ReturnType: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("null"),
},
},
},
Stmt: &ast.StmtStmtList{
Stmts: []ast.Vertex{},
},
},
&ast.StmtClassMethod{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Name: &ast.Identifier{
Val: []byte("true"),
},
Params: []ast.Vertex{
&ast.Parameter{
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("true"),
},
},
},
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$true"),
},
},
},
},
ReturnType: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("true"),
},
},
},
Stmt: &ast.StmtStmtList{
Stmts: []ast.Vertex{},
},
},
&ast.StmtClassMethod{
Modifiers: []ast.Vertex{
&ast.Identifier{
Val: []byte("public"),
},
},
Name: &ast.Identifier{
Val: []byte("false"),
},
Params: []ast.Vertex{
&ast.Parameter{
Type: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("false"),
},
},
},
Var: &ast.ExprVariable{
Name: &ast.Identifier{
Val: []byte("$false"),
},
},
},
},
ReturnType: &ast.Name{
Parts: []ast.Vertex{
&ast.NamePart{
Val: []byte("false"),
},
},
},
Stmt: &ast.StmtStmtList{
Stmts: []ast.Vertex{},
},
},
},
},
},
},`
suite.Run()
}