1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?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 testParse2()
{
$component = Expression::parse(new Parser(), $this->getTokensList('col`test`'));
}
/**
* @dataProvider testParseErrProvider
*/
public function testParseErr($expr, $error)
{
$parser = new Parser();
Expression::parse($parser, $this->getTokensList($expr));
$errors = $this->getErrorsAsArray($parser);
$this->assertEquals($errors[0][0], $error);
}
public function testParseErrProvider()
{
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()
{
$component = new Expression('1 + 2', 'three');
$this->assertEquals(Expression::build($component), '1 + 2 AS `three`');
}
}
|