implements PR-05.0.2
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record ModuleReference(
|
||||
String project,
|
||||
ReadOnlyList<String> pathSegments) {
|
||||
public ModuleReference {
|
||||
project = Objects.requireNonNull(project, "project");
|
||||
if (project.isBlank()) {
|
||||
throw new IllegalArgumentException("project must not be blank");
|
||||
}
|
||||
pathSegments = pathSegments == null ? ReadOnlyList.empty() : pathSegments;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
|
||||
public class ModuleTable extends InternTable<ModuleId, ModuleReference> {
|
||||
|
||||
public ModuleTable() {
|
||||
super(ModuleId::new);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user