packages/sql-faker/tests/Unit/Generation/Value/RepeatDomainTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\Generation\Value;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use SqlFaker\Generation\Value\RepeatDomain;
11use SqlFaker\Generation\Value\WordDomain;
12
13#[CoversClass(RepeatDomain::class)]
14#[UsesClass(WordDomain::class)]
15final class RepeatDomainTest extends TestCase
16{
17    public function testChooseRepeatsCompleteComponents(): void
18    {
19        $domain = new RepeatDomain(new WordDomain(['_0']), 1, 3);
20        self::assertSame('_0', $domain->choose(static fn (int $count): int => 0));
21        self::assertSame('_0_0_0', $domain->choose(static fn (int $count): int => $count - 1));
22    }
23
24    public function testMatchRequiresProgressAndAllowsLongExplicitRuns(): void
25    {
26        $domain = new RepeatDomain(new WordDomain(['a', 'aa']), 1, 1);
27        self::assertEqualsCanonicalizing([1, 2, 3], $domain->match('aaa'));
28        self::assertSame([], $domain->match(''));
29        self::assertSame([0], (new RepeatDomain(new WordDomain(['']), 0, 1))->match('abc'));
30        self::assertSame([0], (new RepeatDomain(new WordDomain(['']), 2, 2))->match('abc'));
31    }
32
33}
34