package dev.dinauer.maven.maven.core.model;

import dev.dinauer.maven.maven.shared.Extensions;
import dev.dinauer.maven.maven.shared.ParserResult;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ExtensionParserTest
{
    @Test
    void test_01()
    {
        String filename = "jackson-core-2.21.0-20250419.123456-1.jar.md5";

        ParserResult<Extensions> extensionResult = new ExtensionParser().parse(filename);

        Assertions.assertEquals("jackson-core-2.21.0-20250419.123456-1", extensionResult.remainder());
        Assertions.assertEquals(FileExt.JAR, extensionResult.result().ext());
        Assertions.assertEquals(FileHash.MD5, extensionResult.result().hashExt().orElseThrow());
    }

    @Test
    void test_02()
    {
        String filename = "test.pom.sha1";

        ParserResult<Extensions> extensionResult = new ExtensionParser().parse(filename);

        Assertions.assertEquals("test", extensionResult.remainder());
        Assertions.assertEquals(FileExt.POM, extensionResult.result().ext());
        Assertions.assertEquals(FileHash.SHA1, extensionResult.result().hashExt().orElseThrow());
    }

    @Test
    void test_03()
    {
        String filename = "test.jar";

        ParserResult<Extensions> extensionResult = new ExtensionParser().parse(filename);

        Assertions.assertEquals("test", extensionResult.remainder());
        Assertions.assertEquals(FileExt.JAR, extensionResult.result().ext());
        Assertions.assertTrue(extensionResult.result().hashExt().isEmpty());
    }
}
