packages/sql-faker/tests/Unit/Generation/Value/WordDomainTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\Generation\Value;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use SqlFaker\Generation\Value\WordDomain;
10
11#[CoversClass(WordDomain::class)]
12final class WordDomainTest extends TestCase
13{
14 public function testChooseSelectsLiteralWordsIncludingEmptyComponents(): void
15 {
16 $domain = new WordDomain(['', 'A.B', 'C~D'], true);
17 self::assertSame('', $domain->choose(static fn (int $count): int => 0));
18 self::assertSame('C~D', $domain->choose(static fn (int $count): int => $count - 1));
19 }
20
21 public function testMatchTreatsMetacharactersLiterallyAndPreservesOffsets(): void
22 {
23 self::assertSame([2, 5], (new WordDomain(['', 'A.B', 'A.B'], true))->match('xxa.b!', 2));
24 self::assertSame([], (new WordDomain(['A.B']))->match('a.b'));
25 self::assertSame([], (new WordDomain(['A.B'], true))->match('AxB'));
26 }
27}
28