packages/sql-parser/tests/Unit/Lexer/AsciiTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lexer;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\Attributes\TestWith;
10use PHPUnit\Framework\TestCase;
11use SqlParser\Lexer\Ascii;
12
13#[CoversClass(Ascii::class)]
14#[Small]
15final class AsciiTest extends TestCase
16{
17 #[TestWith(['IDENTIFIER_012', 'identifier_012'])]
18 #[TestWith(['IİıiÄä', 'iİıiÄä'])]
19 #[TestWith(["\xDDI\0A\xFF", "\xDDi\0a\xFF"])]
20 public function testLowerLeavesNonAsciiBytesUntouched(string $input, string $expected): void
21 {
22 self::assertSame($expected, Ascii::lower($input));
23 }
24
25 #[TestWith(['is distinct from', 'IS DISTINCT FROM'])]
26 #[TestWith(['IİıiÄä', 'IİıIÄä'])]
27 #[TestWith(["\xFDi\0z\xFF", "\xFDI\0Z\xFF"])]
28 public function testUpperRecognizesAsciiKeywordsWithoutLocaleFolding(string $input, string $expected): void
29 {
30 self::assertSame($expected, Ascii::upper($input));
31 }
32
33 #[TestWith(['', false])]
34 #[TestWith(['A', true])]
35 #[TestWith(['z', true])]
36 #[TestWith(['0', false])]
37 #[TestWith(['[', false])]
38 #[TestWith(['é', false])]
39 #[TestWith(["\xDD", false])]
40 #[TestWith(['ab', false])]
41 public function testLetterRecognizesOnlyOneAsciiAlphabeticByte(string $byte, bool $expected): void
42 {
43 self::assertSame($expected, Ascii::letter($byte));
44 }
45
46 #[TestWith(['', false])]
47 #[TestWith(['0', true])]
48 #[TestWith(['9', true])]
49 #[TestWith(['/', false])]
50 #[TestWith([':', false])]
51 #[TestWith(['٠', false])]
52 #[TestWith(['00', false])]
53 public function testDigitDistinguishesDecimalLookaheadFromOtherBytes(string $byte, bool $expected): void
54 {
55 self::assertSame($expected, Ascii::digit($byte));
56 }
57
58 #[TestWith(['', false])]
59 #[TestWith([' ', true])]
60 #[TestWith(["\t", true])]
61 #[TestWith(["\n", true])]
62 #[TestWith(["\v", true])]
63 #[TestWith(["\xA0", false])]
64 #[TestWith(["\0", false])]
65 public function testSpaceKeepsSqlWhitespaceIndependentOfHostLocale(string $byte, bool $expected): void
66 {
67 self::assertSame($expected, Ascii::space($byte));
68 }
69
70 #[TestWith(['', false])]
71 #[TestWith(["\0", true])]
72 #[TestWith(["\x1F", true])]
73 #[TestWith(["\x7F", true])]
74 #[TestWith([' ', false])]
75 #[TestWith(["\x80", false])]
76 public function testControlRecognizesAsciiControlBytesAndDel(string $byte, bool $expected): void
77 {
78 self::assertSame($expected, Ascii::control($byte));
79 }
80}
81