implements PR-05.0.6
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class HostBindingId extends SourceIdentifier {
|
||||
public HostBindingId(final int id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record HostBindingRef(
|
||||
String module,
|
||||
String name,
|
||||
long version) {
|
||||
public HostBindingRef {
|
||||
module = Objects.requireNonNull(module, "module");
|
||||
name = Objects.requireNonNull(name, "name");
|
||||
if (module.isBlank() || name.isBlank()) {
|
||||
throw new IllegalArgumentException("module and name must not be blank");
|
||||
}
|
||||
if (version < 0) {
|
||||
throw new IllegalArgumentException("version must be non-negative");
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.HostBindingId;
|
||||
|
||||
public class HostBindingTable extends InternTable<HostBindingId, HostBindingRef> {
|
||||
|
||||
public HostBindingTable() {
|
||||
super(HostBindingId::new);
|
||||
}
|
||||
|
||||
public HostBindingId register(
|
||||
final String module,
|
||||
final String name,
|
||||
final long version) {
|
||||
return register(new HostBindingRef(module, name, version));
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
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.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user