<?php

use App\Support\EmailAddress;
use CodeIgniter\Test\CIUnitTestCase;

/**
 * @internal
 */
final class EmailAddressTest extends CIUnitTestCase
{
    public function testNormalizeTrimsAndLowercases(): void
    {
        $this->assertSame('user@example.com', EmailAddress::normalize('  User@Example.COM  '));
    }

    public function testInvalidEmailRejected(): void
    {
        $this->assertFalse(EmailAddress::isValid(''));
        $this->assertFalse(EmailAddress::isValid('not-an-email'));
        $this->assertFalse(EmailAddress::isValid('user@'));
        $this->assertTrue(EmailAddress::isValid('user@example.com'));
    }

    public function testMaskKeepsTwoLocalCharacters(): void
    {
        $this->assertSame('vi***@example.com', EmailAddress::mask('victor@example.com'));
        $this->assertSame('ab***@example.com', EmailAddress::mask('AB@Example.com'));
    }
}
