packages/sql-semantics/tests/Unit/Statement/AssertionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\Attributes\TestWith;
10use PHPUnit\Framework\TestCase;
11use SqlSemantics\Statement\Assertion;
12use SqlSemantics\Statement\Model\Sqlite\Value\ExprWithExprPlusMinusExpr_82e360dc as Addition;
13use SqlSemantics\Statement\Model\Sqlite\Value\ExprWithExprStarSlashRemExpr_6ca99fe8 as Multiplication;
14use SqlSemantics\Statement\Model\Sqlite\Value\ExprWithLpExprRp_ad646753 as Parentheses;
15use SqlSemantics\Statement\Model\Sqlite\Value\NmWithIdj_a2015ecf as Name;
16use SqlSemantics\Statement\Model\Sqlite\Value\TermWithInteger_298801b2 as IntegerValue;
17
18#[CoversClass(Assertion::class)]
19#[Medium]
20final class AssertionTest extends TestCase
21{
22 #[TestWith(['0'])]
23 #[TestWith(['12345678901234567890'])]
24 #[TestWith(['0xFF'])]
25 public function testAssertMatchesPatternPreservesIntegerSpelling(string $spelling): void
26 {
27 $value = new IntegerValue('1');
28 $updated = $value->withValue($spelling);
29 self::assertSame('1', $value->value);
30 self::assertSame($spelling, $updated->value);
31 }
32
33 public function testAssertMatchesPatternPreservesQuotedIdentifierSpelling(): void
34 {
35 $name = new Name('foo');
36 $updated = $name->withName('"foo.bar"');
37 self::assertSame('foo', $name->name);
38 self::assertSame('"foo.bar"', $updated->name);
39 }
40
41 public function testAssertOperandBindingStrengthAcceptsExplicitGrouping(): void
42 {
43 $sum = new Addition(new IntegerValue('1'), '+', new IntegerValue('2'));
44 $grouped = new Parentheses($sum);
45 $value = new Multiplication(new IntegerValue('1'), '*', new IntegerValue('3'));
46 $updated = $value->withExpr($grouped);
47 self::assertSame($grouped, $updated->expr);
48 self::assertSame($value->expr2, $updated->expr2);
49 self::assertNotSame($value, $updated);
50 }
51}
52