47 lines
1.8 KiB
PHP
47 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Infra\Adapters\Parsers;
|
||
|
|
|
||
|
|
use Infra\Adapters\Parsers\IncoStringParser;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
covers(IncoStringParser::class);
|
||
|
|
|
||
|
|
uses(TestCase::class);
|
||
|
|
|
||
|
|
describe('IncoStringParser', function (): void {
|
||
|
|
describe('toPhrase', function (): void {
|
||
|
|
it('formats string as phrase with capitalized first letter and no trailing period', function (): void {
|
||
|
|
expect(IncoStringParser::toPhrase('VOLAILLE DE QUALITE.'))->toBe('Volaille de qualite')
|
||
|
|
->and(IncoStringParser::toPhrase(' viande de porc '))->toBe('Viande de porc')
|
||
|
|
->and(IncoStringParser::toPhrase(''))->toBe('');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('beautifyName', function (): void {
|
||
|
|
it('converts text to title case and trims punctuation', function (): void {
|
||
|
|
expect(IncoStringParser::beautifyName('poulet rôti fermier.'))->toBe('Poulet Rôti Fermier')
|
||
|
|
->and(IncoStringParser::beautifyName(':NUGGETS DE POULET'))->toBe('Nuggets De Poulet')
|
||
|
|
->and(IncoStringParser::beautifyName(''))->toBe('');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('beautifyText', function (): void {
|
||
|
|
it('returns null when input is null', function (): void {
|
||
|
|
expect(IncoStringParser::beautifyText(null))->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('properly formats sentences and preserves decimal floating point numbers', function (): void {
|
||
|
|
$input = 'viande de poulet 51,5% et eau 20.5%. cuisson au four.';
|
||
|
|
$result = IncoStringParser::beautifyText($input);
|
||
|
|
|
||
|
|
expect($result)->toContain('51.5%')
|
||
|
|
->and($result)->toContain('20.5%')
|
||
|
|
->and($result)->toContain('Viande de poulet')
|
||
|
|
->and($result)->toContain('Cuisson au four.');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|