package p.studio.compiler.source.tables;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class IntrinsicTableTest {

    @Test
    void shouldInternEqualIntrinsicReferencesToSameIdentifier() {
        final var table = new IntrinsicTable();

        final var first = table.register("core.color.pack", 1);
        final var second = table.register("core.color.pack", 1);
        final var third = table.register("core.input.poll", 1);

        assertEquals(first, second);
        assertEquals(2, table.size());
        assertTrue(table.containsKey(new IntrinsicReference("core.color.pack", 1)));
        assertEquals("core.input.poll", table.get(third).canonicalName());
    }

    @Test
    void shouldRejectInvalidIntrinsicReferenceContract() {
        assertThrows(IllegalArgumentException.class, () -> new IntrinsicReference("", 1));
        assertThrows(IllegalArgumentException.class, () -> new IntrinsicReference("core.color.pack", -1));
    }
}
