packages/sql-semantics-postgres/tests/Unit/Statement/Literal/BitStringConstantTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Literal;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
11use SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical;
12use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
13use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
14use SqlSemantics\Platform\PostgreSql\Statement\Literal\BitStringConstant;
15use SqlSemantics\Platform\PostgreSql\Statement\Literal\BitStringRadix;
16
17#[CoversClass(BitStringConstant::class)]
18#[Small]
19final class BitStringConstantTest extends TestCase
20{
21 public function testRenderWritesThePrefixAndTheDigits(): void
22 {
23 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
24 (new BitStringConstant(BitStringRadix::Hexadecimal, '1F'))->render($out);
25 self::assertSame("x'1F'", (new Lexical())->join($out->pieces()));
26 }
27
28 public function testRejectsAQuoteAmongTheDigits(): void
29 {
30 $this->expectExceptionMessage('A bit-string constant holds no quote and no zero byte.');
31 new BitStringConstant(BitStringRadix::Binary, "1'0");
32 }
33}
34