-
Notifications
You must be signed in to change notification settings - Fork 1
/
interpoltest.html
83 lines (82 loc) · 3.32 KB
/
interpoltest.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
<!DOCTYPE html>
<html>
<head>
<title>Interpolator test</title>
<style>
body { font-family: monospace; }
table, th, td { border: 1px solid black; border-collapse: collapse; padding: 10px; white-space: pre; }
</style>
</head>
<body>
<h1>Interpolator Test</h1>
<p><input id="input"></input> <button id="run">Test it</button></p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Output</th>
</tr>
</thead>
<tbody id="out"></tbody>
</table>
<script src="js/interpol.js"></script>
<script>
const box = document.getElementById('input');
const btn = document.getElementById('run');
const out = document.getElementById('out');
function appendResult(input, output, isError) {
var row = document.createElement('tr');
var inD = document.createElement('td');
var ouD = document.createElement('td');
inD.textContent = input;
if (isError) {
ouD.textContent = 'Error: ' + output;
ouD.setAttribute('style', 'color:red');
} else {
ouD.textContent = output;
}
row.appendChild(inD);
row.appendChild(ouD);
out.appendChild(row);
}
function runTest(x) {
var input, output;
if (x) {
input = x;
}
else {
input = box.value;
box.value = '';
}
if (!input) return;
try {
appendResult(input, processExpressions(input), false);
} catch(e) {
appendResult(input, e.toString(), true);
}
}
btn.addEventListener('click', () => runTest());
[
'nothing here',
'#should #not #change',
'expect an error #foobar;',
'no #123; change outside of expression',
'multiple #123; interspersed #456; interpolations',
'#`-`:+:+:+:+::++;',
'top item is 789: #123\'456\'789;',
'result string is foobar: #`foobar`;',
'top string is barbaz: #`foobar``barbaz`;',
'noooooop test: #123\'\'\'\'\'\'\'\';',
'random: #123?;',
'ternary true test: #`❌``✅`1@;',
'ternary false test: #`✅``❌`0@;',
'swap: #123\'456\\ 123=`❌`\\`✅`\\@;',
'modulo: #123\'2% 1=`❌`\\`✅`\\@;',
'add: #123\'2+ 125=`❌`\\`✅`\\@;',
'add strings: #`foo``bar`+ `foobar`=`❌`\\`✅`\\@;',
'subtract: #123\'2- 121=`❌`\\`✅`\\@;',
'drop: #123\'123\'2$+ 246=`❌`\\`✅`\\@;',
].forEach(runTest);
</script>
</body>
</html>