Skip to content

Commit

Permalink
Merge pull request #107 from mvorisek/fix_reserved_words
Browse files Browse the repository at this point in the history
Make sure keywords are single upper words
  • Loading branch information
greg0ire authored May 30, 2024
2 parents f9f2468 + ff667cc commit 4605e91
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
8 changes: 3 additions & 5 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class Tokenizer
'CASE',
'CHANGE',
'CHANGED',
'CHARACTER SET',
'CHARACTER',
'CHARSET',
'CHECK',
'CHECKSUM',
Expand All @@ -68,7 +68,7 @@ final class Tokenizer
'CONVERT',
'CREATE',
'CROSS',
'CURRENT ROW',
'CURRENT',
'CURRENT_TIMESTAMP',
'DATABASE',
'DATABASES',
Expand Down Expand Up @@ -182,13 +182,10 @@ final class Tokenizer
'MYISAM',
'NAMES',
'NATURAL',
'NO OTHERS',
'NOT',
'NULL',
'OFFSET',
'ON',
'ON DELETE',
'ON UPDATE',
'OPEN',
'OPTIMIZE',
'OPTION',
Expand Down Expand Up @@ -242,6 +239,7 @@ final class Tokenizer
'SEPARATOR',
'SERIALIZABLE',
'SESSION',
'SET',
'SHARE',
'SHOW',
'SHUTDOWN',
Expand Down
14 changes: 14 additions & 0 deletions tests/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;

use function array_filter;
use function preg_match;
use function sort;
use function strtoupper;

final class TokenizerTest extends TestCase
{
Expand Down Expand Up @@ -44,6 +47,17 @@ public function testInternalKeywordListsAreSortedForEasierMaintenance(): void
}
}

public function testKeywordsReservedAreSingleUpperWord(): void
{
$tokenizerReserved = $this->getTokenizerList('reserved');

$kwsDiff = array_filter($tokenizerReserved, static function ($v) {
return $v !== strtoupper($v) || preg_match('~^\w+$~', $v) !== 1;
});

self::assertSame([], $kwsDiff);
}

#[DoesNotPerformAssertions]
public function testThereAreNoRegressions(): void
{
Expand Down
14 changes: 7 additions & 7 deletions tests/clihighlight.txt
Original file line number Diff line number Diff line change
Expand Up @@ -915,31 +915,31 @@
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
EXCLUDE NO OTHERS
AND CURRENT ROW
EXCLUDE NO OTHERS
) AS no_others,
GROUP_CONCAT(b, '.') OVER (
ORDER BY
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
EXCLUDE CURRENT ROW
AND CURRENT ROW
EXCLUDE CURRENT ROW
) AS current_row,
GROUP_CONCAT(b, '.') OVER (
ORDER BY
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
AND CURRENT ROW
EXCLUDE GROUP
) AS grp,
GROUP_CONCAT(b, '.') OVER (
ORDER BY
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
AND CURRENT ROW
EXCLUDE TIES
) AS tie,
GROUP_CONCAT(b, '.') FILTER (
Expand Down Expand Up @@ -990,7 +990,7 @@
ORDER BY
RevenueYear
ROWS
BETWEEN CURRENT ROW
BETWEEN CURRENT ROW
AND UNBOUNDED FOLLOWING
) AS MinRevenueBeyond
FROM
Expand Down
14 changes: 7 additions & 7 deletions tests/format-highlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,31 +915,31 @@
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">NO OTHERS</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="color: #333;">NO</span> <span style="color: #333;">OTHERS</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">no_others</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">OVER</span> (
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">current_row</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">OVER</span> (
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">GROUP</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">grp</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">OVER</span> (
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">TIES</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">tie</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">FILTER</span> (
Expand Down Expand Up @@ -990,7 +990,7 @@
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">RevenueYear</span>
<span style="font-weight:bold;">ROWS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">FOLLOWING</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">MinRevenueBeyond</span>
<span style="font-weight:bold;">FROM</span>
Expand Down
Loading

0 comments on commit 4605e91

Please sign in to comment.