Skip to content
Snippets Groups Projects
Commit 832f0d64 authored by Nathan PERIER's avatar Nathan PERIER
Browse files

Added tests for recursive types

parent c50fea75
No related branches found
No related tags found
No related merge requests found
......@@ -147,4 +147,28 @@ public class TypedefParserTest {
Assertions.assertThrows(ParsingException.class, () -> TypedefParser.parse(it, ctx));
}
@Test
public void recursiveSumTypeTest() {
TokenPeekIterator it = new Lexer("type 'a sum = Empty | Cons of 'a * 'a sum;;").wrap();
SumType exp = new SumType("sum", List.of(new GenericType("a")));
exp.addConstructor("Empty");
exp.addConstructor("Cons", new NupleType(new Type[] {
new GenericType("a"),
exp
}));
Assertions.assertTrue(it.junkIf(TokenType.TYPEDEF));
TypeDef td = TypedefParser.parse(it, ctx);
Type t = td.getType();
Assertions.assertEquals(exp, t);
Assertions.assertTrue(it.junkIf(TokenType.TERMINATION));
Assertions.assertFalse(it.hasNext());
}
@Test
public void noRecursiveAliasTypeTest() {
TokenPeekIterator it = new Lexer("type alias = alias list;;").wrap();
Assertions.assertTrue(it.junkIf(TokenType.TYPEDEF));
Assertions.assertThrows(ParsingException.class, () -> TypedefParser.parse(it, ctx));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment