-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.html
194 lines (181 loc) · 6.16 KB
/
tests.html
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<html><head><title>MOTION LANGUAGE REGRESSION TESTS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
var testArray = [
{ name: 'NEWMOTE [name] expands to NAME [name] MOTE',
input: 'NewMOTE nm nm',
expected: '\\d+[A-Za-z]+'
},
{ name: 'MOTE as scalar container',
input: 'newmote m setmote m string abcd fetchmote m',
expected: 'abcd'
},
{ name: 'MOTE as a-a container',
input: 'newmote m store m string def string abcd fetch m def',
expected: 'abcd'
},
{ name: 'name creates alias to an already named thing',
input: 'newmote nm name m nm astore m string 5 string abcd afetch m 5',
expected: 'abcd'
},
{ name: 'MOTE yields mote id',
input: 'MOTE',
expected: '\\d+[A-Za-z]+'
},
{ name: 'MOTE as scalar container',
input: 'name m MOTE setmote m string abcd fetchmote m',
expected: 'abcd'
},
{ name: 'MOTE as a-a container',
input: 'name m MOTE store m string def string abcd fetch m def',
expected: 'abcd'
},
{ name: 'MOTE as array container',
input: 'name m MOTE astore m string 5 string abcd afetch m 5',
expected: 'abcd'
},
{ name: 'NOTHING',
input: 'abc nothing def',
expected: 'abc def'
},
{ name: 'placeholder is an error',
input: ' placeholder x',
expected: 'FAIL PLACEHOLDER_INVOKED_OUTSIDE_OF_SEQUENCE_DEFINITION x'
},
{ name: 'GENSYM',
input: ' Gensym',
expected: 'gs\\d+gs\\d+gs\\d+'
},
{ name: '"STRING" escapes reserved word',
input: 'string string',
expected: 'string'
},
{ name: 'unknown keywords pass through unchanged',
input: 'abcd',
expected: 'abcd'
},
{ name: 'heredoc',
input: 'heredoc x abc def x',
expected: 'abc def'
},
{ name: 'only listed symbols are available within safe',
input: 'name a aa name b bb perform safe a begin a b end',
expected: 'aa b'
},
{ name: 'safe syntax',
input: 'name a aa name b bb perform safe a begin a b',
expected: '[\\s\\S]+SYNTAX[\\s\\S]+'
},
{ name: 'safe syntax',
input: 'name a aa name b bb perform safe a b',
expected: '[\\s\\S]+SYNTAX[\\s\\S]+'
},
{ name: 'names are case-insensitive',
input: 'name q heredoc x abc def x Q',
expected: 'abc def'
},
{ name: 'ephemeral mote identifiers include type',
input: 'sequence x abcdef x ',
expected: '\\d+SEQUENCE'
},
{ name: 'name nothing fail',
input: 'a name a',
expected: 'a fail name_missing_thing'
},
{ name: 'name noname fail',
input: 'a name',
expected: 'a fail name_missing_name'
},
{ name: 'perform a named sequence',
input: 'name q sequence x abcdef x perform Q',
expected: 'abcdef'
},
{ name: 'placeholder in a sequence',
input: 'perform sequence x a placeholder a b A e x cd',
expected: 'a b cd e'
},
{ name: 'placeholder layering',
input: 'name s1 sequence x placeholder S perform S test x name inner sequence h placeholder i we got i , i is what we got h perform s1 inner',
expected: 'we got test , test is what we got'
},
];
var Table;
function GenerateHttpRequestObject(){
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
return httpRequest;
}
function RunTest(N, TO){
var row = document.createElement("TR");
var Icol = document.createElement("TD"); // number
var Ncol = document.createElement("TD"); // name
var Ecol = document.createElement("TD"); // expectation
var Mcol = document.createElement("TD"); // message
var Pcol = document.createElement("TD"); // progress
var Scol = document.createElement("TD"); // pass/fail status
Icol.appendChild(document.createTextNode(N));
Ncol.appendChild(document.createTextNode(TO.name));
Mcol.appendChild(document.createTextNode(TO.input));
Ecol.appendChild(document.createTextNode(TO.expected));
Pcol.appendChild(document.createTextNode('launching'));
Scol.appendChild(document.createTextNode('...'));
row.appendChild(Icol);
row.appendChild(Ncol);
row.appendChild(Mcol);
row.appendChild(Ecol);
row.appendChild(Pcol);
row.appendChild(Scol);
var expec = TO.expected;
var e2 = expec.replace(/\s+/g, "\\s+");
// alert("looking for ["+e2+"]");
var re = new RegExp('^\\s*'+e2+'\\s*$',"i");
Table.appendChild(row);
var HR = GenerateHttpRequestObject();
HR.onreadystatechange = function(){
Pcol.innerHTML = HR.readyState + ' ' + HR.status;
if ( HR.readyState === 4 ){
Pcol.innerHTML = HR.responseText;
if (re.test(HR.responseText)){
Scol.innerHTML = '<b>PASS</b>'
}else{
Scol.innerHTML = '<b>FAIL</b>'
}
}
};
HR.open('POST','http://motes.tipjar.com/cgi-bin/motion/plain');
HR.send('MESSAGE='+TO.input);
};
function start(){
Table = document.getElementById('TestTable');
var testNumber = 1;
for (var i in testArray){
RunTest(i, testArray[i])
}
};
</script>
<body onload="start()" >
<p>
Tests of the current version of Motion (http://motes.tipjar.com/cgi-bin/motion)
</p><hr>
<table id="TestTable" border="1">
<tr><th>#</th><th>test name</th>
<th>message</th><th>expectation</th>
<th>progress</th><th>pass/fail</th><tr>
</table>
</body>