feat: FontSuggest – ähnliche Schriftnamen für unbekannte Schriften (W5)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
8740e9b8dc
commit
05ff2d90f3
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Design\FontSuggest;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FontSuggestTest extends TestCase
|
||||
{
|
||||
private const NAMES = [
|
||||
'Roboto', 'Roboto Condensed', 'Roboto Slab', 'Open Sans', 'Open Sans Condensed', 'Lato', 'Lora', 'Arial',
|
||||
'Source Sans 3', 'Playfair Display', 'Helvetica', 'Georgia',
|
||||
];
|
||||
|
||||
public function testTheSameNameInAnotherCaseComesFirst(): void
|
||||
{
|
||||
self::assertSame(
|
||||
['Open Sans', 'Open Sans Condensed'],
|
||||
FontSuggest::similar('open sans', self::NAMES, 2)
|
||||
);
|
||||
self::assertSame('Lato', FontSuggest::similar('LATO', self::NAMES)[0]);
|
||||
}
|
||||
|
||||
public function testRanksPrefixBeforeSubstringBeforeASmallDistance(): void
|
||||
{
|
||||
$names = ['Big Roboto', 'Rubik', 'Roboto Slab', 'Roboot', 'Robot'];
|
||||
|
||||
self::assertSame(
|
||||
['Roboto Slab', 'Big Roboto', 'Robot', 'Roboot'],
|
||||
FontSuggest::similar('roboto', $names)
|
||||
);
|
||||
}
|
||||
|
||||
public function testATypoIsFoundByDistanceButUnrelatedNamesAreNot(): void
|
||||
{
|
||||
self::assertSame(['Open Sans'], FontSuggest::similar('Opne Sans', self::NAMES));
|
||||
self::assertSame(['Playfair Display'], FontSuggest::similar('Playfair Displey', self::NAMES));
|
||||
self::assertSame([], FontSuggest::similar('Comic Sans', ['Arial', 'Georgia', 'Helvetica']));
|
||||
}
|
||||
|
||||
public function testTheLimitCutsTheListAndTheOrderIsStable(): void
|
||||
{
|
||||
$first = FontSuggest::similar('Roboto', self::NAMES, 2);
|
||||
|
||||
self::assertSame(['Roboto', 'Roboto Slab'], $first);
|
||||
self::assertSame($first, FontSuggest::similar('Roboto', array_reverse(self::NAMES), 2));
|
||||
self::assertSame(['Roboto', 'Roboto Slab', 'Roboto Condensed'], FontSuggest::similar('Roboto', self::NAMES, 5));
|
||||
self::assertCount(5, FontSuggest::similar('o', self::NAMES));
|
||||
}
|
||||
|
||||
public function testTiesAreBrokenByLengthThenAlphabet(): void
|
||||
{
|
||||
self::assertSame(['Aab', 'Aac', 'Aaaa'], FontSuggest::similar('aa', ['Aaaa', 'Aac', 'Aab']));
|
||||
}
|
||||
|
||||
public function testEdgeCases(): void
|
||||
{
|
||||
self::assertSame([], FontSuggest::similar('', self::NAMES));
|
||||
self::assertSame([], FontSuggest::similar(' ', self::NAMES));
|
||||
self::assertSame([], FontSuggest::similar('Lato', self::NAMES, 0));
|
||||
self::assertSame([], FontSuggest::similar('Lato', []));
|
||||
self::assertSame(['Lato'], FontSuggest::similar(' lato ', ['Lato', 'Lato']), 'trimmed, duplicates once');
|
||||
self::assertSame(['Fjalla Önö'], FontSuggest::similar('FJALLA ÖNÖ', ['Fjalla Önö']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user