package p.studio.compiler.source.tables;

import org.junit.jupiter.api.Test;
import p.studio.utilities.structures.ReadOnlyList;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

class ModuleTableTest {

    @Test
    void shouldInternSameReferenceWithStableId() {
        final var table = new ModuleTable();
        final var reference = new ModuleReference("core", ReadOnlyList.wrap(java.util.List.of("math", "vec")));

        final var first = table.register(reference);
        final var second = table.register(reference);

        assertEquals(first, second);
    }

    @Test
    void shouldAllocateDifferentIdForDifferentReference() {
        final var table = new ModuleTable();

        final var first = table.register(new ModuleReference("core", ReadOnlyList.wrap(java.util.List.of("math"))));
        final var second = table.register(new ModuleReference("core", ReadOnlyList.wrap(java.util.List.of("gfx"))));

        assertNotEquals(first, second);
    }
}
