implements PR002
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.NameId;
|
||||
|
||||
public class NameTable extends InternTable<NameId, String> implements NameTableReader {
|
||||
public NameTable() {
|
||||
super(NameId::new);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.NameId;
|
||||
|
||||
public interface NameTableReader extends InternTableReader<NameId, String> {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
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.assertTrue;
|
||||
|
||||
class NameTableTest {
|
||||
|
||||
@Test
|
||||
void shouldInternEqualNamesToSameIdentifier() {
|
||||
final var table = new NameTable();
|
||||
|
||||
final var first = table.register("sum");
|
||||
final var second = table.register("sum");
|
||||
final var third = table.register("tick");
|
||||
|
||||
assertEquals(first, second);
|
||||
assertEquals(2, table.size());
|
||||
assertTrue(table.containsKey("sum"));
|
||||
assertEquals("tick", table.get(third));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user