forked from hflicka/arden2bytecode
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMlmFormatTest.java
More file actions
117 lines (97 loc) · 3.58 KB
/
MlmFormatTest.java
File metadata and controls
117 lines (97 loc) · 3.58 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package arden.tests.specification;
import org.junit.Test;
import arden.tests.specification.testcompiler.ArdenVersion;
import arden.tests.specification.testcompiler.CompatibilityRule.Compatibility;
import arden.tests.specification.testcompiler.SpecificationTest;
public class MlmFormatTest extends SpecificationTest {
// TODO test character set (ASCII/UNICODE, linebreak)?
@Test
public void testFileFormat() throws Exception {
String otherMlm = createCodeBuilder()
.setName("other_mlm")
.toString();
String multipleMlms = createCodeBuilder()
.addMlm(otherMlm)
.toString();
assertValid(multipleMlms);
String missingEnd = createCodeBuilder()
.toString()
.replace("end:", "");
assertInvalid(missingEnd);
}
@Test
public void testCategories() throws Exception {
String spaceBeforeColon = createCodeBuilder().renameSlot("maintenance:", "maintenance :").toString();
assertInvalid(spaceBeforeColon);
// error on wrong category order
String wrongOrder = createCodeBuilder().toString();
int maintenanceIndex = wrongOrder.indexOf("maintenance:");
int libraryIndex = wrongOrder.indexOf("library:");
int knowledgeIndex = wrongOrder.indexOf("knowledge:");
String maintenanceCode = wrongOrder.substring(maintenanceIndex, libraryIndex);
String libraryCode = wrongOrder.substring(libraryIndex, knowledgeIndex);
wrongOrder = wrongOrder
.replace(maintenanceCode, "$TEMP")
.replace(libraryCode, maintenanceCode)
.replace("$TEMP", libraryCode);
assertInvalid(wrongOrder);
}
@Test
public void testSlots() throws Exception {
String spaceBeforeColon = createCodeBuilder().renameSlot("version:", "version :").toString();
assertInvalid(spaceBeforeColon);
String duplicateSlot = createCodeBuilder().renameSlot("citations:", "links:").toString();
assertInvalid(duplicateSlot);
String wrongOrder = createCodeBuilder()
.renameSlot("specialist:", "temp:")
.renameSlot("author:", "specialist:")
.renameSlot("temp:", "author:")
.toString();
assertInvalid(wrongOrder);
// double semicolon not allowed in slot
assertInvalidSlot("institution:", "abc;;xyz");
}
@Test
@Compatibility(min = ArdenVersion.V2)
public void testDoubleSemicolon() throws Exception {
// double semicolon in string constants
assertValidStatement("x := \";;\";");
// double semicolon in mapping
assertValidSlot("data:", "x := EVENT {;;};");
// double semicolon in comment
assertValidSlot("data:", "//;;" + System.lineSeparator());
}
@Test
@Compatibility(max = ArdenVersion.V1, pedantic = true)
public void testDoubleSemicolonInvalid() throws Exception {
// double semicolon are not allowed in string constants in version 1
assertInvalidStatement("x := \";;\";");
}
@Test
public void testSlotBodyTypes() throws Exception {
// arbitrary text in textual slots
assertValidSlot("title:", "the mlm at time of now & = + - * ; abs if else >= mlmname mlmname:");
String emptyTextualSlots = createCodeBuilder()
.clearSlotContent("title:")
.clearSlotContent("version:")
.clearSlotContent("institution:")
.clearSlotContent("author:")
.clearSlotContent("specialist:")
.clearSlotContent("purpose:")
.clearSlotContent("explanation:")
.clearSlotContent("keywords:")
.clearSlotContent("citations:")
.clearSlotContent("links:")
.toString();
assertValid(emptyTextualSlots);
}
@Test
public void testCaseInsensitivity() throws Exception {
String mixedCases = createCodeBuilder()
.renameSlot("end:", "eNd:")
.renameSlot("library:", "LIBraRy:")
.renameSlot("author:", "aUTHOr:")
.toString();
assertValid(mixedCases);
}
}