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,216 +55,307 @@ class ConstExprParserTest extends \PHPUnit\Framework\TestCase
} }
public function provideParseData(): array public function provideTrueNodeParseData(): iterable
{ {
return [ yield [
[ 'true',
'true', new ConstExprTrueNode(),
new ConstExprTrueNode(), ];
],
[ yield [
'True', 'TRUE',
new ConstExprTrueNode(), new ConstExprTrueNode(),
], ];
[
'false', yield [
new ConstExprFalseNode(), 'tRUe',
], new ConstExprTrueNode(),
[ ];
'False', }
new ConstExprFalseNode(),
],
[ public function provideFalseNodeParseData(): iterable
'null', {
new ConstExprNullNode(), yield [
], 'false',
[ new ConstExprFalseNode(),
'Null', ];
new ConstExprNullNode(),
], yield [
[ 'FALSE',
'123', new ConstExprFalseNode(),
new ConstExprIntegerNode('123'), ];
],
[ yield [
'0b0110101', 'fALse',
new ConstExprIntegerNode('0b0110101'), new ConstExprFalseNode(),
], ];
[ }
'0o777',
new ConstExprIntegerNode('0o777'),
], public function provideNullNodeParseData(): iterable
[ {
'0x7Fb4', yield [
new ConstExprIntegerNode('0x7Fb4'), 'null',
], new ConstExprNullNode(),
[ ];
'-0O777',
new ConstExprIntegerNode('-0O777'), yield [
], 'NULL',
[ new ConstExprNullNode(),
'-0X7Fb4', ];
new ConstExprIntegerNode('-0X7Fb4'),
], yield [
[ 'nULl',
'123.4', new ConstExprNullNode(),
new ConstExprFloatNode('123.4'), ];
], }
[
'.123',
new ConstExprFloatNode('.123'), public function provideIntegerNodeParseData(): iterable
], {
[ yield [
'123.', '123',
new ConstExprFloatNode('123.'), new ConstExprIntegerNode('123'),
], ];
[
'123e4', yield [
new ConstExprFloatNode('123e4'), '0b0110101',
], new ConstExprIntegerNode('0b0110101'),
[ ];
'12.3e4',
new ConstExprFloatNode('12.3e4'), yield [
], '0o777',
[ new ConstExprIntegerNode('0o777'),
'-123', ];
new ConstExprIntegerNode('-123'),
], yield [
[ '0x7Fb4',
'-123.4', new ConstExprIntegerNode('0x7Fb4'),
new ConstExprFloatNode('-123.4'), ];
],
[ yield [
'-.123', '-0O777',
new ConstExprFloatNode('-.123'), new ConstExprIntegerNode('-0O777'),
], ];
[
'-123.', yield [
new ConstExprFloatNode('-123.'), '-0X7Fb4',
], new ConstExprIntegerNode('-0X7Fb4'),
[ ];
'-123e-4', }
new ConstExprFloatNode('-123e-4'),
],
[ public function provideFloatNodeParseData(): iterable
'-12.3e-4', {
new ConstExprFloatNode('-12.3e-4'), yield [
], '123.4',
[ new ConstExprFloatNode('123.4'),
'"foo"', ];
new ConstExprStringNode('"foo"'),
], yield [
[ '.123',
'\'bar\'', new ConstExprFloatNode('.123'),
new ConstExprStringNode('\'bar\''), ];
],
[ yield [
'GLOBAL_CONSTANT', '123.',
new ConstFetchNode('', 'GLOBAL_CONSTANT'), new ConstExprFloatNode('123.'),
], ];
[
'Foo\\Bar\\GLOBAL_CONSTANT', yield [
new ConstFetchNode('', 'Foo\\Bar\\GLOBAL_CONSTANT'), '123e4',
], new ConstExprFloatNode('123e4'),
[ ];
'Foo\\Bar::CLASS_CONSTANT',
new ConstFetchNode('Foo\\Bar', 'CLASS_CONSTANT'), yield [
], '123E4',
[ new ConstExprFloatNode('123E4'),
'self::CLASS_CONSTANT', ];
new ConstFetchNode('self', 'CLASS_CONSTANT'),
], yield [
[ '12.3e4',
'[]', new ConstExprFloatNode('12.3e4'),
new ConstExprArrayNode([]), ];
],
[ yield [
'[123]', '-123',
new ConstExprArrayNode([ new ConstExprIntegerNode('-123'),
new ConstExprArrayItemNode( ];
null,
new ConstExprIntegerNode('123') yield [
), '-123.4',
]), new ConstExprFloatNode('-123.4'),
], ];
[
'[1, 2, 3]', yield [
new ConstExprArrayNode([ '-.123',
new ConstExprArrayItemNode( new ConstExprFloatNode('-.123'),
null, ];
new ConstExprIntegerNode('1')
), yield [
new ConstExprArrayItemNode( '-123.',
null, new ConstExprFloatNode('-123.'),
new ConstExprIntegerNode('2') ];
),
new ConstExprArrayItemNode( yield [
null, '-123e-4',
new ConstExprIntegerNode('3') new ConstExprFloatNode('-123e-4'),
), ];
]),
], yield [
[ '-12.3e-4',
'[1, 2, 3, ]', new ConstExprFloatNode('-12.3e-4'),
new ConstExprArrayNode([ ];
new ConstExprArrayItemNode( }
null,
new ConstExprIntegerNode('1')
), public function provideStringNodeParseData(): iterable
new ConstExprArrayItemNode( {
null, yield [
new ConstExprIntegerNode('2') '"foo"',
), new ConstExprStringNode('"foo"'),
new ConstExprArrayItemNode( ];
null,
new ConstExprIntegerNode('3') yield [
), '"Foo \\n\\"\\r Bar"',
]), new ConstExprStringNode('"Foo \\n\\"\\r Bar"'),
], ];
[
'[1 => 2]', yield [
new ConstExprArrayNode([ '\'bar\'',
new ConstExprArrayItemNode( new ConstExprStringNode('\'bar\''),
new ConstExprIntegerNode('1'), ];
new ConstExprIntegerNode('2')
), yield [
]), '\'Foo \\\' Bar\'',
], new ConstExprStringNode('\'Foo \\\' Bar\''),
[ ];
'[1 => 2, 3]', }
new ConstExprArrayNode([
new ConstExprArrayItemNode(
new ConstExprIntegerNode('1'), public function provideArrayNodeParseData(): iterable
new ConstExprIntegerNode('2') {
), yield [
new ConstExprArrayItemNode( '[]',
null, new ConstExprArrayNode([]),
new ConstExprIntegerNode('3') ];
),
]), yield [
], '[123]',
[ new ConstExprArrayNode([
'[1, [2, 3]]', new ConstExprArrayItemNode(
new ConstExprArrayNode([ null,
new ConstExprArrayItemNode( new ConstExprIntegerNode('123')
null, ),
new ConstExprIntegerNode('1') ]),
), ];
new ConstExprArrayItemNode(
null, yield [
new ConstExprArrayNode([ '[1, 2, 3]',
new ConstExprArrayItemNode( new ConstExprArrayNode([
null, new ConstExprArrayItemNode(
new ConstExprIntegerNode('2') null,
), new ConstExprIntegerNode('1')
new ConstExprArrayItemNode( ),
null, new ConstExprArrayItemNode(
new ConstExprIntegerNode('3') null,
), new ConstExprIntegerNode('2')
]) ),
), new ConstExprArrayItemNode(
]), null,
], new ConstExprIntegerNode('3')
),
]),
];
yield [
'[1, 2, 3, ]',
new ConstExprArrayNode([
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('1')
),
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('2')
),
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('3')
),
]),
];
yield [
'[1 => 2]',
new ConstExprArrayNode([
new ConstExprArrayItemNode(
new ConstExprIntegerNode('1'),
new ConstExprIntegerNode('2')
),
]),
];
yield [
'[1 => 2, 3]',
new ConstExprArrayNode([
new ConstExprArrayItemNode(
new ConstExprIntegerNode('1'),
new ConstExprIntegerNode('2')
),
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('3')
),
]),
];
yield [
'[1, [2, 3]]',
new ConstExprArrayNode([
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('1')
),
new ConstExprArrayItemNode(
null,
new ConstExprArrayNode([
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('2')
),
new ConstExprArrayItemNode(
null,
new ConstExprIntegerNode('3')
),
])
),
]),
];
}
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'),
]; ];
} }