summaryrefslogtreecommitdiffstats
path: root/tests/Lexer/LexerTest.php
blob: f29e23388aaa0b300fcd780cc45f9db9dcef282f (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

namespace PhpMyAdmin\SqlParser\Tests\Lexer;

use PhpMyAdmin\SqlParser\Exceptions\LexerException;
use PhpMyAdmin\SqlParser\Lexer;
use PhpMyAdmin\SqlParser\Tests\TestCase;

class LexerTest extends TestCase
{
    /**
     * @runInSeparateProcess
     * @preserveGlobalState disabled
     */
    public function testError()
    {
        $lexer = new Lexer('');

        $lexer->error('error #1', 'foo', 1, 2);
        $lexer->error(
            sprintf('%2$s #%1$d', 2, 'error'),
            'bar',
            3,
            4
        );

        $this->assertEquals(
            $lexer->errors,
            array(
                new LexerException('error #1', 'foo', 1, 2),
                new LexerException('error #2', 'bar', 3, 4),
            )
        );
    }

    /**
     * @expectedException \PhpMyAdmin\SqlParser\Exceptions\LexerException
     * @expectedExceptionMessage strict error
     * @expectedExceptionCode 4
     */
    public function testErrorStrict()
    {
        $lexer = new Lexer('');
        $lexer->strict = true;

        $lexer->error('strict error', 'foo', 1, 4);
    }

    /**
     * @dataProvider testLexProvider
     *
     * @param mixed $test
     */
    public function testLex($test)
    {
        $this->runParserTest($test);
    }

    public function testLexProvider()
    {
        return array(
            array('lexer/lex'),
            array('lexer/lexUtf8'),
            array('lexer/lexBool'),
            array('lexer/lexComment'),
            array('lexer/lexDelimiter'),
            array('lexer/lexDelimiter2'),
            array('lexer/lexDelimiterErr1'),
            array('lexer/lexDelimiterErr2'),
            array('lexer/lexDelimiterErr3'),
            array('lexer/lexKeyword'),
            array('lexer/lexKeyword2'),
            array('lexer/lexNumber'),
            array('lexer/lexOperator'),
            array('lexer/lexString'),
            array('lexer/lexStringErr1'),
            array('lexer/lexSymbol'),
            array('lexer/lexSymbolErr1'),
            array('lexer/lexSymbolErr2'),
            array('lexer/lexSymbolErr3'),
            array('lexer/lexSymbolUser'),
            array('lexer/lexWhitespace'),
            array('lexer/lexLabel1'),
            array('lexer/lexLabel2'),
        );
    }
}