package p.studio.compiler.source.tables;

import org.junit.jupiter.api.Test;

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

class HostBindingTableTest {

    @Test
    void shouldInternEqualHostBindingsToSameIdentifier() {
        final var table = new HostBindingTable();

        final var first = table.register("gfx", "draw_pixel", 1);
        final var second = table.register("gfx", "draw_pixel", 1);
        final var third = table.register("gfx", "draw_pixel", 2);

        assertEquals(first, second);
        assertNotEquals(first, third);
        assertEquals(2, table.size());
    }

    @Test
    void shouldRejectInvalidHostBindingContract() {
        assertThrows(IllegalArgumentException.class, () -> new HostBindingRef("", "draw_pixel", 1));
        assertThrows(IllegalArgumentException.class, () -> new HostBindingRef("gfx", "", 1));
        assertThrows(IllegalArgumentException.class, () -> new HostBindingRef("gfx", "draw_pixel", -1));
    }
}
