summaryrefslogtreecommitdiffstats
path: root/tests/Components/Array2dTest.php
blob: 1c57a4320d6753524369ecdf2fc56d95b6459d0b (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);

namespace PhpMyAdmin\SqlParser\Tests\Components;

use PhpMyAdmin\SqlParser\Components\Array2d;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;

class Array2dTest extends TestCase
{
    public function testParse()
    {
        $parser = new Parser();
        $arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +'));
        $this->assertEquals(
            [
                1,
                2,
            ],
            $arrays[0]->values
        );
    }

    public function testBuild()
    {
        $arrays = Array2d::parse(new Parser(), $this->getTokensList('(1, 2), (3, 4), (5, 6)'));
        $this->assertEquals(
            '(1, 2), (3, 4), (5, 6)',
            Array2d::build($arrays)
        );
    }

    public function testParseErr1()
    {
        $parser = new Parser();
        Array2d::parse($parser, $this->getTokensList('(1, 2 +'));

        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    public function testParseErr2()
    {
        $parser = new Parser();
        Array2d::parse($parser, $this->getTokensList('(1, 2 TABLE'));

        $this->markTestIncomplete(
            'This test has not been implemented yet.'
        );
    }

    public function testParseErr3()
    {
        $parser = new Parser();
        Array2d::parse($parser, $this->getTokensList(')'));
        $this->assertCount(
            1,
            $parser->errors
        );
        $this->assertEquals(
            'An opening bracket followed by a set of values was expected.',
            $parser->errors[0]->getMessage()
        );
    }

    public function testParseErr4()
    {
        $parser = new Parser();
        Array2d::parse($parser, $this->getTokensList('TABLE'));
        $this->assertCount(
            1,
            $parser->errors
        );
        $this->assertEquals(
            'An opening bracket followed by a set of values was expected.',
            $parser->errors[0]->getMessage()
        );
    }

    public function testParseErr5()
    {
        $parser = new Parser();
        Array2d::parse($parser, $this->getTokensList('(1, 2),'));
        $this->assertCount(
            1,
            $parser->errors
        );
        $this->assertEquals(
            'An opening bracket followed by a set of values was expected.',
            $parser->errors[0]->getMessage()
        );
    }

    public function testParseErr6()
    {
        $parser = new Parser();
        Array2d::parse($parser, $this->getTokensList('(1, 2),(3)'));
        $this->assertCount(
            1,
            $parser->errors
        );
        $this->assertEquals(
            '2 values were expected, but found 1.',
            $parser->errors[0]->getMessage()
        );
    }
}