Skip to content

Commit d1917d2

Browse files
committed
Add missing test cases for comments on ORDER by and in expressions
Signed-off-by: William Desportes <[email protected]>
1 parent 0f8b275 commit d1917d2

4 files changed

Lines changed: 35 additions & 1 deletion

File tree

tests/Components/ExpressionArrayTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,27 @@ public function testParse2()
3232
$this->assertCount(1, $component);
3333
$this->assertEquals('(expr)', $component[0]->expr);
3434
}
35+
36+
public function testParseWithCommentsNoOptions()
37+
{
38+
$component = ExpressionArray::parse(
39+
new Parser(),
40+
$this->getTokensList('(expr) -- comment ?')
41+
);
42+
$this->assertCount(1, $component);
43+
$this->assertEquals('(expr)', $component[0]->expr);
44+
}
45+
46+
public function testParseWithCommentsAndOptions()
47+
{
48+
$component = ExpressionArray::parse(
49+
new Parser(),
50+
$this->getTokensList('(expr -- comment ?)'),
51+
array(
52+
'parenthesesDelimited' => true
53+
)
54+
);
55+
$this->assertCount(1, $component);
56+
$this->assertEquals('(expr', $component[0]->expr);
57+
}
3558
}

tests/Parser/SelectStatementTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public function selectProvider()
8686
array('parser/parseSelectIndexHintErr2'),
8787
array('parser/parseSelectIndexHintErr3'),
8888
array('parser/parseSelectIndexHintErr4'),
89-
array('parser/parseSelectWithParenthesis')
89+
array('parser/parseSelectWithParenthesis'),
90+
array('parser/parseSelectOrderByComment')
9091
);
9192
}
9293
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT `one space` -- this is the SELECT
2+
FROM `Une table espace` -- this is the FROM
3+
ORDER BY `one space` ASC -- this is the order by
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a:4:{s:5:"query";s:143:"SELECT `one space` -- this is the SELECT
2+
FROM `Une table espace` -- this is the FROM
3+
ORDER BY `one space` ASC -- this is the order by";s:5:"lexer";O:26:"PhpMyAdmin\SqlParser\Lexer":8:{s:3:"str";s:143:"SELECT `one space` -- this is the SELECT
4+
FROM `Une table espace` -- this is the FROM
5+
ORDER BY `one space` ASC -- this is the order by";s:3:"len";i:143;s:4:"last";i:144;s:4:"list";O:31:"PhpMyAdmin\SqlParser\TokensList":3:{s:6:"tokens";a:20:{i:0;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"SELECT";s:5:"value";s:6:"SELECT";s:7:"keyword";s:6:"SELECT";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:0;}i:1;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:6;}i:2;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:11:"`one space`";s:5:"value";s:9:"one space";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:7;}i:3;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:2:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:18;}i:4;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:21:"-- this is the SELECT";s:5:"value";s:21:"-- this is the SELECT";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:4;s:8:"position";i:20;}i:5;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:5:"
6+
";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:41;}i:6;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:4:"FROM";s:5:"value";s:4:"FROM";s:7:"keyword";s:4:"FROM";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:46;}i:7;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:50;}i:8;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:18:"`Une table espace`";s:5:"value";s:16:"Une table espace";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:51;}i:9;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:2:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:69;}i:10;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:19:"-- this is the FROM";s:5:"value";s:19:"-- this is the FROM";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:4;s:8:"position";i:71;}i:11;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:5:"
7+
";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:90;}i:12;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:8:"ORDER BY";s:5:"value";s:8:"ORDER BY";s:7:"keyword";s:8:"ORDER BY";s:4:"type";i:1;s:5:"flags";i:7;s:8:"position";i:95;}i:13;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:103;}i:14;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:11:"`one space`";s:5:"value";s:9:"one space";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:104;}i:15;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:115;}i:16;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:3:"ASC";s:5:"value";s:3:"ASC";s:7:"keyword";s:3:"ASC";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:116;}i:17;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:119;}i:18;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:23:"-- this is the order by";s:5:"value";s:23:"-- this is the order by";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:4;s:8:"position";i:120;}i:19;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";N;s:5:"value";N;s:7:"keyword";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:20;s:3:"idx";i:20;}s:9:"delimiter";s:1:";";s:12:"delimiterLen";i:1;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"parser";O:27:"PhpMyAdmin\SqlParser\Parser":5:{s:4:"list";r:7;s:10:"statements";a:1:{i:0;O:47:"PhpMyAdmin\SqlParser\Statements\SelectStatement":17:{s:4:"expr";a:1:{i:0;O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";N;s:6:"column";s:9:"one space";s:4:"expr";s:11:"`one space`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}}s:4:"from";a:1:{i:0;O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";s:16:"Une table espace";s:6:"column";N;s:4:"expr";s:18:"`Une table espace`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}}s:11:"index_hints";N;s:9:"partition";N;s:5:"where";N;s:5:"group";N;s:6:"having";N;s:5:"order";a:1:{i:0;O:44:"PhpMyAdmin\SqlParser\Components\OrderKeyword":2:{s:4:"expr";O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";N;s:6:"column";s:9:"one space";s:4:"expr";s:11:"`one space`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}s:4:"type";s:3:"ASC";}}s:5:"limit";N;s:9:"procedure";N;s:4:"into";N;s:4:"join";N;s:5:"union";a:0:{}s:11:"end_options";N;s:7:"options";O:44:"PhpMyAdmin\SqlParser\Components\OptionsArray":1:{s:7:"options";a:0:{}}s:5:"first";i:0;s:4:"last";i:18;}}s:8:"brackets";i:0;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"errors";a:2:{s:5:"lexer";a:0:{}s:6:"parser";a:0:{}}}

0 commit comments

Comments
 (0)