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;

class CallableShapeTableTest {

    @Test
    void shouldInternEqualShapesToSameIdentifier() {
        final var surfaces = new TypeSurfaceTable();
        final var shapes = new CallableShapeTable();

        final var intType = surfaces.register("simple:int");
        final var unitType = surfaces.register("unit");
        final var first = shapes.register(ReadOnlyList.from(intType, intType), unitType);
        final var second = shapes.register(ReadOnlyList.from(intType, intType), unitType);
        final var third = shapes.register(ReadOnlyList.from(intType), unitType);

        assertEquals(first, second);
        assertEquals(2, shapes.size());
        assertEquals(1, shapes.get(third).parameterTypeSurfaces().size());
    }
}
