value)->toBe('abc123'); }); it('rejects non-alphanumeric strings', function () { AlphanumericString::fromString('abc-123'); })->throws(InvalidArgumentException::class, 'alphanumeric'); it('rejects empty strings', function () { AlphanumericString::fromString(''); })->throws(InvalidArgumentException::class); it('converts to TypedString', function () { $str = AlphanumericString::fromString('test123'); $typed = $str->toTypedString(); expect($typed->value)->toBe('test123'); expect($typed->isAlphanumeric())->toBeTrue(); }); it('checks equality', function () { $str1 = AlphanumericString::fromString('abc123'); $str2 = AlphanumericString::fromString('abc123'); $str3 = AlphanumericString::fromString('xyz789'); expect($str1->equals($str2))->toBeTrue(); expect($str1->equals($str3))->toBeFalse(); }); it('converts to string', function () { $str = AlphanumericString::fromString('test123'); expect((string) $str)->toBe('test123'); }); }); describe('NumericString', function () { it('creates from valid numeric string', function () { $str = NumericString::fromString('12345'); expect($str->value)->toBe('12345'); }); it('rejects non-numeric strings', function () { NumericString::fromString('12.34'); })->throws(InvalidArgumentException::class, 'digits'); it('rejects alphanumeric strings', function () { NumericString::fromString('123abc'); })->throws(InvalidArgumentException::class); it('rejects empty strings', function () { NumericString::fromString(''); })->throws(InvalidArgumentException::class); it('converts to integer', function () { $str = NumericString::fromString('12345'); expect($str->toInt())->toBe(12345); }); it('converts to float', function () { $str = NumericString::fromString('12345'); expect($str->toFloat())->toBe(12345.0); }); it('handles large numbers', function () { $str = NumericString::fromString('999999999'); expect($str->toInt())->toBe(999999999); }); }); describe('HexadecimalString', function () { it('creates from valid hexadecimal string', function () { $str = HexadecimalString::fromString('deadbeef'); expect($str->value)->toBe('deadbeef'); }); it('accepts uppercase hexadecimal', function () { $str = HexadecimalString::fromString('DEADBEEF'); expect($str->value)->toBe('DEADBEEF'); }); it('accepts mixed case hexadecimal', function () { $str = HexadecimalString::fromString('DeAdBeEf'); expect($str->value)->toBe('DeAdBeEf'); }); it('rejects non-hexadecimal strings', function () { HexadecimalString::fromString('ghijk'); })->throws(InvalidArgumentException::class, 'hexadecimal'); it('rejects empty strings', function () { HexadecimalString::fromString(''); })->throws(InvalidArgumentException::class); it('converts to binary', function () { $str = HexadecimalString::fromString('48656c6c6f'); // "Hello" $binary = $str->toBinary(); expect($binary)->toBe('Hello'); }); it('converts to integer', function () { $str = HexadecimalString::fromString('ff'); expect($str->toInt())->toBe(255); }); it('handles long hexadecimal strings', function () { $str = HexadecimalString::fromString('0123456789abcdef'); expect($str->toInt())->toBe(81985529216486895); }); }); describe('PrintableString', function () { it('creates from valid printable string', function () { $str = PrintableString::fromString('Hello World!'); expect($str->value)->toBe('Hello World!'); }); it('accepts strings with whitespace', function () { $str = PrintableString::fromString("Hello\nWorld\tTest"); expect($str->value)->toContain('Hello'); }); it('rejects strings with control characters', function () { PrintableString::fromString("Hello\x00World"); })->throws(InvalidArgumentException::class, 'printable'); it('rejects empty strings', function () { PrintableString::fromString(''); })->throws(InvalidArgumentException::class); it('accepts special characters', function () { $str = PrintableString::fromString('!@#$%^&*()_+-=[]{}|;:,.<>?'); expect($str->value)->toContain('!@#$'); }); it('converts to TypedString', function () { $str = PrintableString::fromString('Test String'); $typed = $str->toTypedString(); expect($typed->value)->toBe('Test String'); expect($typed->isPrintable())->toBeTrue(); }); });