Skip to content

Commit d80d7e1

Browse files
committed
ANSI_QUOTES lexer and parser test-suite proposal
1 parent 73f02b3 commit d80d7e1

File tree

7 files changed

+205
-0
lines changed

7 files changed

+205
-0
lines changed

tests/Lexer/LexerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function lexProvider()
6060
{
6161
return [
6262
['lexer/lex'],
63+
['lexer/ansi/lexAnsi'],
6364
['lexer/lexUtf8'],
6465
['lexer/lexBool'],
6566
['lexer/lexComment'],

tests/Parser/ParserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function parseProvider()
2828
['parser/parse'],
2929
['parser/parse2'],
3030
['parser/parseDelimiter'],
31+
['parser/ansi/parseAnsi']
3132
];
3233
}
3334

tests/TestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PhpMyAdmin\SqlParser\Lexer;
1212
use PhpMyAdmin\SqlParser\Parser;
1313
use PhpMyAdmin\SqlParser\TokensList;
14+
use PhpMyAdmin\SqlParser\Context;
1415
use PHPUnit\Framework\TestCase as BaseTestCase;
1516
use function file_get_contents;
1617
use function unserialize;
@@ -99,6 +100,11 @@ public function runParserTest($name)
99100
*/
100101
$data = $this->getData($name);
101102

103+
if (strpos($name,'/ansi/') !== false) {
104+
// set mode if appropriate
105+
Context::setMode('ANSI_QUOTES');
106+
}
107+
102108
// Lexer.
103109
$lexer = new Lexer($data['query']);
104110
$lexerErrors = $this->getErrorsAsArray($lexer);
@@ -119,5 +125,8 @@ public function runParserTest($name)
119125
// Testing errors.
120126
$this->assertEquals($data['errors']['parser'], $parserErrors);
121127
$this->assertEquals($data['errors']['lexer'], $lexerErrors);
128+
129+
// reset mode after test run
130+
Context::setMode();
122131
}
123132
}

tests/data/lexer/ansi/lexAnsi.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE "addresses" (
2+
"id" int(11) NOT NULL AUTO_INCREMENT,
3+
"country_id" int(11) NOT NULL,
4+
"company_id" int(11) DEFAULT NULL,
5+
"censored" int(11) DEFAULT NULL,
6+
"company_name" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
7+
"address_type_id" int(11) DEFAULT NULL,
8+
"street" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
9+
"city" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
10+
"postal_code" varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
11+
"country_region" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
12+
"modified" datetime DEFAULT NULL,
13+
"created" datetime DEFAULT NULL,
14+
PRIMARY KEY ("id"),
15+
UNIQUE KEY "censored" ("censored"),
16+
KEY "country_id" ("country_id"),
17+
KEY "company_id" ("company_id"),
18+
KEY "address_type_id" ("address_type_id"),
19+
KEY "censored" ("censored"),
20+
CONSTRAINT "addresses_ibfk_1" FOREIGN KEY ("address_type_id") REFERENCES "address_types" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
21+
CONSTRAINT "addresses_ibfk_2" FOREIGN KEY ("company_id") REFERENCES "companies" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
22+
CONSTRAINT "addresses_ibfk_3" FOREIGN KEY ("country_id") REFERENCES "countries" ("id"),
23+
CONSTRAINT "addresses_ibfk_4" FOREIGN KEY ("censored") REFERENCES "censored" ("id") ON DELETE CASCADE ON UPDATE CASCADE
24+
)

tests/data/lexer/ansi/lexAnsi.out

Lines changed: 73 additions & 0 deletions
Large diffs are not rendered by default.

tests/data/parser/ansi/parseAnsi.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE "addresses" (
2+
"id" int(11) NOT NULL AUTO_INCREMENT,
3+
"country_id" int(11) NOT NULL,
4+
"company_id" int(11) DEFAULT NULL,
5+
"censored" int(11) DEFAULT NULL,
6+
"company_name" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
7+
"address_type_id" int(11) DEFAULT NULL,
8+
"street" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
9+
"city" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
10+
"postal_code" varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
11+
"country_region" varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
12+
"modified" datetime DEFAULT NULL,
13+
"created" datetime DEFAULT NULL,
14+
PRIMARY KEY ("id"),
15+
UNIQUE KEY "censored" ("censored"),
16+
KEY "country_id" ("country_id"),
17+
KEY "company_id" ("company_id"),
18+
KEY "address_type_id" ("address_type_id"),
19+
KEY "censored" ("censored"),
20+
CONSTRAINT "addresses_ibfk_1" FOREIGN KEY ("address_type_id") REFERENCES "address_types" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
21+
CONSTRAINT "addresses_ibfk_2" FOREIGN KEY ("company_id") REFERENCES "companies" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
22+
CONSTRAINT "addresses_ibfk_3" FOREIGN KEY ("country_id") REFERENCES "countries" ("id"),
23+
CONSTRAINT "addresses_ibfk_4" FOREIGN KEY ("censored") REFERENCES "censored" ("id") ON DELETE CASCADE ON UPDATE CASCADE
24+
)

0 commit comments

Comments
 (0)