-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathArray2dTest.php
95 lines (84 loc) · 2.81 KB
/
Array2dTest.php
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
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Parsers\Array2d;
use PhpMyAdmin\SqlParser\Parsers\ArrayObjs;
use PhpMyAdmin\SqlParser\Tests\TestCase;
class Array2dTest extends TestCase
{
public function testParse(): void
{
$parser = new Parser();
$arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +'));
$this->assertEquals(
[
1,
2,
],
$arrays[0]->values,
);
}
public function testBuildAll(): void
{
$arrays = Array2d::parse(new Parser(), $this->getTokensList('(1, 2), (3, 4), (5, 6)'));
$this->assertEquals(
'(1, 2), (3, 4), (5, 6)',
ArrayObjs::buildAll($arrays),
);
}
public function testParseErr1(): void
{
$parser = new Parser();
Array2d::parse($parser, $this->getTokensList('(1, 2 +'));
$this->assertCount(1, $parser->errors);
$this->assertEquals('A closing bracket was expected.', $parser->errors[0]->getMessage());
}
public function testParseErr2(): void
{
$parser = new Parser();
Array2d::parse($parser, $this->getTokensList('(1, 2 TABLE'));
$this->assertCount(1, $parser->errors);
$this->assertEquals('A closing bracket was expected.', $parser->errors[0]->getMessage());
}
public function testParseErr3(): void
{
$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(): void
{
$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(): void
{
$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(): void
{
$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(),
);
}
}