forked from runtimeverification/k
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParserTest.java
More file actions
38 lines (31 loc) · 1.29 KB
/
ParserTest.java
File metadata and controls
38 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2015-2016 K Team. All Rights Reserved.
package org.kframework;
import static org.junit.Assert.*;
import org.junit.Test;
import org.kframework.definition.*;
import org.kframework.kore.K;
import org.kframework.kore.Sort;
import scala.Option;
import scala.Tuple2;
import java.util.Set;
import static org.kframework.kore.KORE.*;
import static org.kframework.Collections.*;
public class ParserTest {
private static final Sort xSort = Sort("X");
Module m = Module.apply("TEST", Set(
Production.apply(xSort, Seq(Terminal.apply("x")), Att().add("klabel", "x"))
));
@Test
public void simpleNoWarning() {
Tuple2<Option<K>, Set<Warning>> actual = Parser.from(m).apply(xSort, "x");
assertTrue("The parse should succeed, but was " + actual, actual._1().isDefined());
assertTrue("There should be no warnings, but were: " + actual._2(), actual._2().isEmpty());
assertEquals(KApply(KLabel("x")), actual._1().get());
}
@Test
public void simpleFailedParse() {
Tuple2<Option<K>, Set<Warning>> actual = Parser.from(m).apply(xSort, "y");
assertTrue("The parse should fail, but was " + actual, actual._1().isEmpty());
assertTrue("There should be one error, but were: " + actual._2(), actual._2().size() == 1);
}
}