summaryrefslogtreecommitdiffstats
path: root/tests/Components
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-07-19 14:36:53 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-07-19 14:36:53 +0300
commit5e554b3534c44f122906fea36ef7698a5769316b (patch)
tree4cd766c505b0f93498eccc6d75f9446b21f6a5a4 /tests/Components
parentb894375c04eb138f4c541623e644be8364ff11de (diff)
downloadsql-parser-5e554b3534c44f122906fea36ef7698a5769316b.zip
sql-parser-5e554b3534c44f122906fea36ef7698a5769316b.tar.gz
sql-parser-5e554b3534c44f122906fea36ef7698a5769316b.tar.bz2
Avoid processing the alias twice and generate an error.
Errors are triggered when an unexpected token is found between clauses. Refactoring.
Diffstat (limited to 'tests/Components')
-rw-r--r--tests/Components/ExpressionArrayTest.php13
-rw-r--r--tests/Components/ExpressionTest.php37
2 files changed, 42 insertions, 8 deletions
diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php
index ea772e3..0fad913 100644
--- a/tests/Components/ExpressionArrayTest.php
+++ b/tests/Components/ExpressionArrayTest.php
@@ -21,4 +21,17 @@ class ExpressionArrayTest extends TestCase
);
$this->assertEquals(array(), $component);
}
+
+ public function testParse2()
+ {
+ $component = ExpressionArray::parse(
+ new Parser(),
+ $this->getTokensList('(expr) +'),
+ array(
+ 'bracketsDelimited' => true,
+ )
+ );
+ $this->assertEquals(1, count($component));
+ $this->assertEquals('(expr)', $component[0]->expr);
+ }
}
diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php
index f1c491c..01492fd 100644
--- a/tests/Components/ExpressionTest.php
+++ b/tests/Components/ExpressionTest.php
@@ -21,20 +21,41 @@ class ExpressionTest extends TestCase
$component = Expression::parse(new Parser(), $this->getTokensList('col`test`'));
}
- public function testParseErr1()
+ /**
+ * @dataProvider testParseErrProvider
+ */
+ public function testParseErr($expr, $error)
{
$parser = new Parser();
- Expression::parse($parser, $this->getTokensList('(1))'));
+ Expression::parse($parser, $this->getTokensList($expr));
$errors = $this->getErrorsAsArray($parser);
- $this->assertEquals($errors[0][0], 'Unexpected closing bracket.');
+ $this->assertEquals($errors[0][0], $error);
}
- public function testParseErr2()
+ public function testParseErrProvider()
{
- $parser = new Parser();
- Expression::parse($parser, $this->getTokensList('tbl..col'));
- $errors = $this->getErrorsAsArray($parser);
- $this->assertEquals($errors[0][0], 'Unexpected dot.');
+ return array(
+ array(
+ '(1))',
+ 'Unexpected closing bracket.',
+ ),
+ array(
+ 'tbl..col',
+ 'Unexpected dot.',
+ ),
+ array(
+ 'id AS id2 AS id3',
+ 'An alias was previously found.',
+ ),
+ array(
+ 'id`id2`\'id3\'',
+ 'An alias was previously found.',
+ ),
+ array(
+ '(id) id2 id3',
+ 'An alias was previously found.',
+ ),
+ );
}
public function testBuild()