ConstExprParserTest: improve readability

This commit is contained in:
Jan Tvrdik 2018-04-12 11:48:46 +02:00
parent 7ab7c78f55
commit f69d70526a

View File

@ -32,7 +32,14 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
/** /**
* @dataProvider provideParseData * @dataProvider provideTrueNodeParseData
* @dataProvider provideFalseNodeParseData
* @dataProvider provideNullNodeParseData
* @dataProvider provideIntegerNodeParseData
* @dataProvider provideFloatNodeParseData
* @dataProvider provideStringNodeParseData
* @dataProvider provideArrayNodeParseData
* @dataProvider provideFetchNodeParseData
* @param string $input * @param string $input
* @param ConstExprNode $expectedExpr * @param ConstExprNode $expectedExpr
* @param int $nextTokenType * @param int $nextTokenType
@ -48,130 +55,193 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
} }
public function provideParseData(): array public function provideTrueNodeParseData(): iterable
{ {
return [ yield [
[
'true', 'true',
new ConstExprTrueNode(), new ConstExprTrueNode(),
], ];
[
'True', yield [
'TRUE',
new ConstExprTrueNode(), new ConstExprTrueNode(),
], ];
[
yield [
'tRUe',
new ConstExprTrueNode(),
];
}
public function provideFalseNodeParseData(): iterable
{
yield [
'false', 'false',
new ConstExprFalseNode(), new ConstExprFalseNode(),
], ];
[
'False', yield [
'FALSE',
new ConstExprFalseNode(), new ConstExprFalseNode(),
], ];
[
yield [
'fALse',
new ConstExprFalseNode(),
];
}
public function provideNullNodeParseData(): iterable
{
yield [
'null', 'null',
new ConstExprNullNode(), new ConstExprNullNode(),
], ];
[
'Null', yield [
'NULL',
new ConstExprNullNode(), new ConstExprNullNode(),
], ];
[
yield [
'nULl',
new ConstExprNullNode(),
];
}
public function provideIntegerNodeParseData(): iterable
{
yield [
'123', '123',
new ConstExprIntegerNode('123'), new ConstExprIntegerNode('123'),
], ];
[
yield [
'0b0110101', '0b0110101',
new ConstExprIntegerNode('0b0110101'), new ConstExprIntegerNode('0b0110101'),
], ];
[
yield [
'0o777', '0o777',
new ConstExprIntegerNode('0o777'), new ConstExprIntegerNode('0o777'),
], ];
[
yield [
'0x7Fb4', '0x7Fb4',
new ConstExprIntegerNode('0x7Fb4'), new ConstExprIntegerNode('0x7Fb4'),
], ];
[
yield [
'-0O777', '-0O777',
new ConstExprIntegerNode('-0O777'), new ConstExprIntegerNode('-0O777'),
], ];
[
yield [
'-0X7Fb4', '-0X7Fb4',
new ConstExprIntegerNode('-0X7Fb4'), new ConstExprIntegerNode('-0X7Fb4'),
], ];
[ }
public function provideFloatNodeParseData(): iterable
{
yield [
'123.4', '123.4',
new ConstExprFloatNode('123.4'), new ConstExprFloatNode('123.4'),
], ];
[
yield [
'.123', '.123',
new ConstExprFloatNode('.123'), new ConstExprFloatNode('.123'),
], ];
[
yield [
'123.', '123.',
new ConstExprFloatNode('123.'), new ConstExprFloatNode('123.'),
], ];
[
yield [
'123e4', '123e4',
new ConstExprFloatNode('123e4'), new ConstExprFloatNode('123e4'),
], ];
[
yield [
'123E4',
new ConstExprFloatNode('123E4'),
];
yield [
'12.3e4', '12.3e4',
new ConstExprFloatNode('12.3e4'), new ConstExprFloatNode('12.3e4'),
], ];
[
yield [
'-123', '-123',
new ConstExprIntegerNode('-123'), new ConstExprIntegerNode('-123'),
], ];
[
yield [
'-123.4', '-123.4',
new ConstExprFloatNode('-123.4'), new ConstExprFloatNode('-123.4'),
], ];
[
yield [
'-.123', '-.123',
new ConstExprFloatNode('-.123'), new ConstExprFloatNode('-.123'),
], ];
[
yield [
'-123.', '-123.',
new ConstExprFloatNode('-123.'), new ConstExprFloatNode('-123.'),
], ];
[
yield [
'-123e-4', '-123e-4',
new ConstExprFloatNode('-123e-4'), new ConstExprFloatNode('-123e-4'),
], ];
[
yield [
'-12.3e-4', '-12.3e-4',
new ConstExprFloatNode('-12.3e-4'), new ConstExprFloatNode('-12.3e-4'),
], ];
[ }
public function provideStringNodeParseData(): iterable
{
yield [
'"foo"', '"foo"',
new ConstExprStringNode('"foo"'), new ConstExprStringNode('"foo"'),
], ];
[
yield [
'"Foo \\n\\"\\r Bar"',
new ConstExprStringNode('"Foo \\n\\"\\r Bar"'),
];
yield [
'\'bar\'', '\'bar\'',
new ConstExprStringNode('\'bar\''), new ConstExprStringNode('\'bar\''),
], ];
[
'GLOBAL_CONSTANT', yield [
new ConstFetchNode('', 'GLOBAL_CONSTANT'), '\'Foo \\\' Bar\'',
], new ConstExprStringNode('\'Foo \\\' Bar\''),
[ ];
'Foo\\Bar\\GLOBAL_CONSTANT', }
new ConstFetchNode('', 'Foo\\Bar\\GLOBAL_CONSTANT'),
],
[ public function provideArrayNodeParseData(): iterable
'Foo\\Bar::CLASS_CONSTANT', {
new ConstFetchNode('Foo\\Bar', 'CLASS_CONSTANT'), yield [
],
[
'self::CLASS_CONSTANT',
new ConstFetchNode('self', 'CLASS_CONSTANT'),
],
[
'[]', '[]',
new ConstExprArrayNode([]), new ConstExprArrayNode([]),
], ];
[
yield [
'[123]', '[123]',
new ConstExprArrayNode([ new ConstExprArrayNode([
new ConstExprArrayItemNode( new ConstExprArrayItemNode(
@ -179,8 +249,9 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
new ConstExprIntegerNode('123') new ConstExprIntegerNode('123')
), ),
]), ]),
], ];
[
yield [
'[1, 2, 3]', '[1, 2, 3]',
new ConstExprArrayNode([ new ConstExprArrayNode([
new ConstExprArrayItemNode( new ConstExprArrayItemNode(
@ -196,8 +267,9 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
new ConstExprIntegerNode('3') new ConstExprIntegerNode('3')
), ),
]), ]),
], ];
[
yield [
'[1, 2, 3, ]', '[1, 2, 3, ]',
new ConstExprArrayNode([ new ConstExprArrayNode([
new ConstExprArrayItemNode( new ConstExprArrayItemNode(
@ -213,8 +285,9 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
new ConstExprIntegerNode('3') new ConstExprIntegerNode('3')
), ),
]), ]),
], ];
[
yield [
'[1 => 2]', '[1 => 2]',
new ConstExprArrayNode([ new ConstExprArrayNode([
new ConstExprArrayItemNode( new ConstExprArrayItemNode(
@ -222,8 +295,9 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
new ConstExprIntegerNode('2') new ConstExprIntegerNode('2')
), ),
]), ]),
], ];
[
yield [
'[1 => 2, 3]', '[1 => 2, 3]',
new ConstExprArrayNode([ new ConstExprArrayNode([
new ConstExprArrayItemNode( new ConstExprArrayItemNode(
@ -235,8 +309,9 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
new ConstExprIntegerNode('3') new ConstExprIntegerNode('3')
), ),
]), ]),
], ];
[
yield [
'[1, [2, 3]]', '[1, [2, 3]]',
new ConstExprArrayNode([ new ConstExprArrayNode([
new ConstExprArrayItemNode( new ConstExprArrayItemNode(
@ -257,7 +332,30 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
]) ])
), ),
]), ]),
], ];
}
public function provideFetchNodeParseData(): iterable
{
yield [
'GLOBAL_CONSTANT',
new ConstFetchNode('', 'GLOBAL_CONSTANT'),
];
yield [
'Foo\\Bar\\GLOBAL_CONSTANT',
new ConstFetchNode('', 'Foo\\Bar\\GLOBAL_CONSTANT'),
];
yield [
'Foo\\Bar::CLASS_CONSTANT',
new ConstFetchNode('Foo\\Bar', 'CLASS_CONSTANT'),
];
yield [
'self::CLASS_CONSTANT',
new ConstFetchNode('self', 'CLASS_CONSTANT'),
]; ];
} }