packages/sql-semantics-postgres/tests/Unit/Statement/Literal/IntegerConstantTest.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\IntegerConstant;
15
16#[CoversClass(IntegerConstant::class)]
17#[Small]
18final class IntegerConstantTest extends TestCase
19{
20    public function testRenderWritesTheDigits(): void
21    {
22        $out = new Output(new Codec(GrammarRelease::PostgreSql172));
23        (new IntegerConstant('2147483647'))->render($out);
24        self::assertSame('2147483647', (new Lexical())->join($out->pieces()));
25    }
26
27    public function testRejectsAnIntegerBeyond32Bits(): void
28    {
29        $this->expectExceptionMessage('An integer constant fits 32 bits; a larger integer is a numeric constant.');
30        new IntegerConstant('2147483648');
31    }
32
33    public function testRejectsASign(): void
34    {
35        $this->expectExceptionMessage('An integer constant is canonical decimal digits.');
36        new IntegerConstant('-1');
37    }
38}
39