summaryrefslogtreecommitdiffstats
path: root/tests/Components/ExpressionTest.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-07-10 01:45:45 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-07-10 03:47:19 +0300
commit527842708bf44fe2bb4d17a97203cec01b860960 (patch)
tree9eb52c23199199b721b5412e1c16d9129d624e52 /tests/Components/ExpressionTest.php
parent7c925b68763e86be121664575632c9261d380821 (diff)
downloadsql-parser-527842708bf44fe2bb4d17a97203cec01b860960.zip
sql-parser-527842708bf44fe2bb4d17a97203cec01b860960.tar.gz
sql-parser-527842708bf44fe2bb4d17a97203cec01b860960.tar.bz2
Mass renaming. Using 'component' instead of 'fragment'.
Diffstat (limited to 'tests/Components/ExpressionTest.php')
-rw-r--r--tests/Components/ExpressionTest.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php
new file mode 100644
index 0000000..ecf5149
--- /dev/null
+++ b/tests/Components/ExpressionTest.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace SqlParser\Tests\Components;
+
+use SqlParser\Parser;
+use SqlParser\Components\Expression;
+
+use SqlParser\Tests\TestCase;
+
+class ExpressionTest extends TestCase
+{
+
+ public function testParse()
+ {
+ $component = Expression::parse(new Parser(), $this->getTokensList('IF(film_id > 0, film_id, film_id)'));
+ $this->assertEquals($component->expr, 'IF(film_id > 0, film_id, film_id)');
+ }
+
+ public function testParseErr1()
+ {
+ $parser = new Parser();
+ Expression::parse($parser, $this->getTokensList('(1))'));
+ $errors = $this->getErrorsAsArray($parser);
+ $this->assertEquals($errors[0][0], 'Unexpected bracket.');
+ }
+
+ public function testParseErr2()
+ {
+ $parser = new Parser();
+ Expression::parse($parser, $this->getTokensList('tbl..col'));
+ $errors = $this->getErrorsAsArray($parser);
+ $this->assertEquals($errors[0][0], 'Unexpected dot.');
+ }
+
+ public function testBuild()
+ {
+ $component = new Expression('1 + 2', 'three');
+ $this->assertEquals(Expression::build($component), '1 + 2 AS `three`');
+ }
+}