package p.studio.compiler.source.tables;

import org.junit.jupiter.api.Test;

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

class CallableTableTest {

    @Test
    void shouldInternEqualCallableSignaturesToSameIdentifier() {
        final var table = new CallableTable();

        final var first = table.register("draw", 2, "(simple:int,simple:int)->unit");
        final var second = table.register("draw", 2, "(simple:int,simple:int)->unit");
        final var third = table.register("draw", 1, "(simple:int)->unit");

        assertEquals(first, second);
        assertEquals(2, table.size());
        assertEquals(1, table.get(third).arity());
    }

    @Test
    void shouldRejectInvalidCallableSignatureReferenceContract() {
        assertThrows(IllegalArgumentException.class, () -> new CallableSignatureRef("", 1, "(unit)->unit"));
        assertThrows(IllegalArgumentException.class, () -> new CallableSignatureRef("draw", -1, "(unit)->unit"));
    }
}
