@@ -1920,6 +1920,7 @@ public function dataLinesAndIndexes(): iterable
1920
1920
static function (TypeNode $ typeNode ): TypeNode {
1921
1921
return $ typeNode ;
1922
1922
},
1923
+ 'int | object{foo: int}[] ' ,
1923
1924
1 ,
1924
1925
1 ,
1925
1926
0 ,
@@ -1929,6 +1930,7 @@ static function (TypeNode $typeNode): TypeNode {
1929
1930
static function (UnionTypeNode $ typeNode ): TypeNode {
1930
1931
return $ typeNode ->types [0 ];
1931
1932
},
1933
+ 'int ' ,
1932
1934
1 ,
1933
1935
1 ,
1934
1936
0 ,
@@ -1938,6 +1940,7 @@ static function (UnionTypeNode $typeNode): TypeNode {
1938
1940
static function (UnionTypeNode $ typeNode ): TypeNode {
1939
1941
return $ typeNode ->types [1 ];
1940
1942
},
1943
+ 'object{foo: int}[] ' ,
1941
1944
1 ,
1942
1945
1 ,
1943
1946
4 ,
@@ -1953,6 +1956,7 @@ static function (UnionTypeNode $typeNode): TypeNode {
1953
1956
static function (TypeNode $ typeNode ): TypeNode {
1954
1957
return $ typeNode ;
1955
1958
},
1959
+ 'int | object{foo: int}[] ' ,
1956
1960
1 ,
1957
1961
1 ,
1958
1962
0 ,
@@ -1962,6 +1966,7 @@ static function (TypeNode $typeNode): TypeNode {
1962
1966
static function (UnionTypeNode $ typeNode ): TypeNode {
1963
1967
return $ typeNode ->types [0 ];
1964
1968
},
1969
+ 'int ' ,
1965
1970
1 ,
1966
1971
1 ,
1967
1972
0 ,
@@ -1971,6 +1976,7 @@ static function (UnionTypeNode $typeNode): TypeNode {
1971
1976
static function (UnionTypeNode $ typeNode ): TypeNode {
1972
1977
return $ typeNode ->types [1 ];
1973
1978
},
1979
+ 'object{foo: int}[] ' ,
1974
1980
1 ,
1975
1981
1 ,
1976
1982
4 ,
@@ -1989,6 +1995,10 @@ static function (UnionTypeNode $typeNode): TypeNode {
1989
1995
static function (TypeNode $ typeNode ): TypeNode {
1990
1996
return $ typeNode ;
1991
1997
},
1998
+ 'array{
1999
+ a: int,
2000
+ b: string
2001
+ } ' ,
1992
2002
1 ,
1993
2003
4 ,
1994
2004
0 ,
@@ -2000,19 +2010,27 @@ static function (TypeNode $typeNode): TypeNode {
2000
2010
2001
2011
/**
2002
2012
* @dataProvider dataLinesAndIndexes
2003
- * @param list<array{callable(TypeNode): TypeNode, int, int, int, int}> $assertions
2013
+ * @param list<array{callable(TypeNode): TypeNode, string, int, int, int, int}> $assertions
2004
2014
*/
2005
2015
public function testLinesAndIndexes (string $ input , array $ assertions ): void
2006
2016
{
2007
- $ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ input ));
2017
+ $ tokensArray = $ this ->lexer ->tokenize ($ input );
2018
+ $ tokens = new TokenIterator ($ tokensArray );
2008
2019
$ typeParser = new TypeParser (new ConstExprParser (true , true ), true , [
2009
2020
'lines ' => true ,
2010
2021
'indexes ' => true ,
2011
2022
]);
2012
2023
$ typeNode = $ typeParser ->parse ($ tokens );
2013
2024
2014
- foreach ($ assertions as [$ callable , $ startLine , $ endLine , $ startIndex , $ endIndex ]) {
2025
+ foreach ($ assertions as [$ callable , $ expectedContent , $ startLine , $ endLine , $ startIndex , $ endIndex ]) {
2015
2026
$ typeToAssert = $ callable ($ typeNode );
2027
+
2028
+ $ content = '' ;
2029
+ for ($ i = $ startIndex ; $ i <= $ endIndex ; $ i ++) {
2030
+ $ content .= $ tokensArray [$ i ][Lexer::VALUE_OFFSET ];
2031
+ }
2032
+
2033
+ $ this ->assertSame ($ expectedContent , $ content );
2016
2034
$ this ->assertSame ($ startLine , $ typeToAssert ->getAttribute (Attribute::START_LINE ));
2017
2035
$ this ->assertSame ($ endLine , $ typeToAssert ->getAttribute (Attribute::END_LINE ));
2018
2036
$ this ->assertSame ($ startIndex , $ typeToAssert ->getAttribute (Attribute::START_INDEX ));
0 commit comments