Skip to content

Commit dcdde80

Browse files
committed
fix pre-made root suppliers, add tests
1 parent f0c81fe commit dcdde80

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/RootSupplier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class RootSupplier implements Supplier<Root> {
2121
ExternalDeclarationIndex::withOnlyExact);
2222
public static final RootSupplier PREFIX_UNORDERED_ED_EXACT = new RootSupplier(
2323
NodeIndex::withUnordered,
24-
PrefixIdentifierIndex::withOnlyExact,
24+
PrefixIdentifierIndex::withPrefix,
2525
ExternalDeclarationIndex::withOnlyExact);
2626
public static final RootSupplier PREFIX_UNORDERED_ED_PREFIX = new RootSupplier(
2727
NodeIndex::withUnordered,
28-
PrefixIdentifierIndex::withOnlyExact,
29-
PrefixExternalDeclarationIndex::withOnlyExact);
28+
PrefixIdentifierIndex::withPrefix,
29+
PrefixExternalDeclarationIndex::withPrefix);
3030

3131
public static final RootSupplier EMPTY = new RootSupplier(supplier(null), supplier(null));
3232
public static final RootSupplier ONLY_NODE_INDEX = new RootSupplier(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.github.douira.glsl_transformer.ast.query;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class RootSupplierTest {
8+
// test that the pre-made root suppliers do the right things
9+
@Test
10+
public void testRootSuppliers() {
11+
var root1 = RootSupplier.EXACT_UNORDERED.get();
12+
assertNull(root1.externalDeclarationIndex);
13+
assertThrows(IllegalStateException.class, () -> root1.getPrefixIdentifierIndex());
14+
assertNotNull(root1.identifierIndex);
15+
assertNotNull(root1.nodeIndex);
16+
assertThrows(IllegalStateException.class, () -> root1.getPrefixExternalDeclarationIndex());
17+
18+
var root2 = RootSupplier.PREFIX_UNORDERED.get();
19+
assertNull(root2.externalDeclarationIndex);
20+
assertNotNull(root2.getPrefixIdentifierIndex());
21+
assertNotNull(root2.identifierIndex);
22+
assertNotNull(root2.nodeIndex);
23+
assertThrows(IllegalStateException.class, () -> root2.getPrefixExternalDeclarationIndex());
24+
25+
var root3 = RootSupplier.EXACT_UNORDERED_ED_EXACT.get();
26+
assertNotNull(root3.externalDeclarationIndex);
27+
assertThrows(IllegalStateException.class, () -> root3.getPrefixIdentifierIndex());
28+
assertNotNull(root3.identifierIndex);
29+
assertNotNull(root3.nodeIndex);
30+
assertThrows(IllegalStateException.class, () -> root3.getPrefixExternalDeclarationIndex());
31+
32+
var root4 = RootSupplier.PREFIX_UNORDERED_ED_EXACT.get();
33+
assertNotNull(root4.externalDeclarationIndex);
34+
assertNotNull(root4.getPrefixIdentifierIndex());
35+
assertNotNull(root4.identifierIndex);
36+
assertNotNull(root4.nodeIndex);
37+
assertThrows(IllegalStateException.class, () -> root4.getPrefixExternalDeclarationIndex());
38+
39+
var root5 = RootSupplier.PREFIX_UNORDERED_ED_PREFIX.get();
40+
assertNotNull(root5.externalDeclarationIndex);
41+
assertNotNull(root5.getPrefixIdentifierIndex());
42+
assertNotNull(root5.identifierIndex);
43+
assertNotNull(root5.nodeIndex);
44+
assertNotNull(root5.getPrefixExternalDeclarationIndex());
45+
}
46+
}

0 commit comments

Comments
 (0)