mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
More type parser tests
This commit is contained in:
parent
c6eb794049
commit
7aacca6941
@ -56,9 +56,8 @@ public class TypeAssumptionParser { // TODO: document type syntax? or refer to o
|
||||
return type2;
|
||||
}
|
||||
type = type2.unwrap().getLeft();
|
||||
parenCount -= type2.unwrap().getRight() - 1;
|
||||
removedParens += type2.unwrap().getRight() - 1;
|
||||
if (parenCount < 0) {
|
||||
if (parenCount - removedParens < 0) {
|
||||
return new Result<>(new ImmutablePair<>(type, removedParens));
|
||||
}
|
||||
break;
|
||||
@ -81,9 +80,8 @@ public class TypeAssumptionParser { // TODO: document type syntax? or refer to o
|
||||
}
|
||||
t = token.unwrap();
|
||||
if (t.getType() == TokenType.RIGHT_PARENTHESIS) {
|
||||
parenCount -= 1;
|
||||
removedParens += 1;
|
||||
if (parenCount <= 0) {
|
||||
if (parenCount - removedParens <= 0) {
|
||||
return new Result<>(new ImmutablePair<>(type, removedParens));
|
||||
}
|
||||
continue;
|
||||
@ -100,8 +98,7 @@ public class TypeAssumptionParser { // TODO: document type syntax? or refer to o
|
||||
}
|
||||
type = new FunctionType(type, nextType.unwrap().getLeft());
|
||||
removedParens += nextType.unwrap().getRight();
|
||||
parenCount -= nextType.unwrap().getRight();
|
||||
if (parenCount <= 0) {
|
||||
if (parenCount - removedParens <= 0) {
|
||||
return new Result<>(new ImmutablePair<>(type, removedParens));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import edu.kit.typicalc.model.type.*;
|
||||
import edu.kit.typicalc.util.Result;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -192,4 +193,33 @@ class TypeAssumptionParserTest {
|
||||
new NamedType("d")
|
||||
)), assumption.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void variousTypes() {
|
||||
Type x = new NamedType("x");
|
||||
Type xx = new FunctionType(x, x);
|
||||
Type xxx = new FunctionType(x, xx);
|
||||
Type xxxx = new FunctionType(x, xxx);
|
||||
Type xxxxx = new FunctionType(xx, xxx);
|
||||
Type xxxxxx = new FunctionType(xxx, xxx);
|
||||
Map<String, TypeAbstraction> tests = new HashMap<>();
|
||||
tests.put("x", new TypeAbstraction(x));
|
||||
tests.put("x -> x", new TypeAbstraction(xx));
|
||||
tests.put("x -> (x)", new TypeAbstraction(xx));
|
||||
tests.put("x -> ((x))", new TypeAbstraction(xx));
|
||||
tests.put("x -> x -> x", new TypeAbstraction(xxx));
|
||||
tests.put("x -> (x -> x)", new TypeAbstraction(xxx));
|
||||
tests.put("x -> x -> x -> x", new TypeAbstraction(xxxx));
|
||||
tests.put("x -> (x -> x -> x)", new TypeAbstraction(xxxx));
|
||||
tests.put("x -> (x -> (x -> x))", new TypeAbstraction(xxxx));
|
||||
tests.put("x -> (x -> (x -> (x)))", new TypeAbstraction(xxxx));
|
||||
tests.put("(x -> x) -> (x -> (x -> (x)))", new TypeAbstraction(xxxxx));
|
||||
tests.put("((x) -> ((x)) -> (x)) -> (x -> (x -> (x)))", new TypeAbstraction(xxxxxx));
|
||||
for (Map.Entry<String, TypeAbstraction> entry : tests.entrySet()) {
|
||||
TypeAssumptionParser parser = new TypeAssumptionParser();
|
||||
Result<Map<VarTerm, TypeAbstraction>, ParseError> type = parser.parse(Map.of("type1", entry.getKey()));
|
||||
assertTrue(type.isOk());
|
||||
assertEquals(entry.getValue(), type.unwrap().get(new VarTerm("type1")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user