-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSC.php
More file actions
182 lines (174 loc) · 3.91 KB
/
TestSC.php
File metadata and controls
182 lines (174 loc) · 3.91 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" src="SugarCubes.js">
</script>
<style>
#program_source {
float:left;
width: 45vw;
overflow:auto;
margin:0;
border: 1px solid black;
padding:0;
unicode-bidi: embed;
font-family: monospace;
white-space: pre;
}
#expected_result {
width: 45vw;
overflow:auto;
margin:0;
border: 1px solid black;
padding:0;
unicode-bidi: embed;
font-family: monospace;
white-space: pre;
}
#testPanel {
float:right;
width: 45vw;
height:100vh;
margin:0;
border:0;
padding:0;
unicode-bidi: embed;
font-family: monospace;
white-space: pre;
}
</style>
</head>
<body>
<div>
<script type="text/javascript">
<?php
$test_files = glob("sc_test/test*.js");
if($test_files){
echo "var max_test_file_num = ".count($test_files).";\n";
}
else{
echo "var max_test_file_num = 1;\n";
}
?>
</script>
<button onclick="window.location.search='?n='+(Math.max(1, testNum-2))"><</button>
<input type="checkbox" id="check_cont" <?php
if(isset($_GET['continue'])
&& ("true" == $_GET['continue'])){
echo "checked";
}
?> onclick="autoContinueSetting()">Auto continue</input>
<button onclick="window.location.search='?n='+(Math.min(max_test_file_num, testNum))">></button>
</div>
<div id="program_source">
</div>
<textarea id="testPanel">
</textarea>
<div id="expected_result">
</div>
<script type="text/javascript">
var check_cont=document.getElementById("check_cont");
function autoContinueSetting(evt){
if(testNum<max_test_file_num && check_cont.checked){
window.location.search="?n="+testNum+"&continue=true";
}
}
var source=document.getElementById("program_source");
var testPanel=document.getElementById("testPanel");
var testNum=0;
try{
testNum=parseInt((/\?n=([^&#]*)/.exec(location.search))[1]);
if(isNaN(testNum)||!(/^[1-9][0-9]*$/.test(""+testNum))){
window.location.search='?n=1';
}
}
catch(e){
window.location.search='?n=1';
}
function writeInConsole(msg){
testPanel.value+=msg;
}
SC.log=function(){ return SC.nothing() };
SC.dump=function(msg){
return SC.action(
function(m){
testPanel.value+=m.msg;
}
);
}
var m=SC.clock({
dumpTraceFun: function(msgs){
for(var i in msgs){
testPanel.value+=msgs[i];
}
}
});
m.enablePrompt(true);
m.setStdOut(writeInConsole);
var e=SC.evt("e");
var f=SC.evt("f");
var g=SC.evt("g");
var e1=SC.evt("e1");
var e2=SC.evt("e2");
var e3=SC.evt("e3");
var e4=SC.evt("e4");
var sens1=SC.sampled("sens1");
var called1=function(v){};
var fun1=function(v){ return called1(v); };
var sens2=SC.sampled("sens2");
var called2=function(v){};
var fun2=function(v){ return called2(v); };
<?php
echo "testBehavior =";
if(isset($_GET['n'])
&& ctype_digit($_GET['n'])){
$test_nb = $_GET['n'];
if($test_nb > 0){
require_once("sc_test/test".$test_nb.".js");
}
else{
echo "{prg:\"SC.nothing()\"}";
}
}
else{
echo "{prg:\"SC.nothing()\"}";
}
?>
if("function"==typeof(testBehavior.init)){
testBehavior.init();
}
var maxInstants=(undefined==testBehavior.maxI)?10:testBehavior.maxI;
var test_prg=testBehavior.prg;
if("string"==typeof(test_prg)){
test_prg=eval(test_prg);
}
source.innerHTML=testBehavior.prg;
if(testBehavior.persist){
m.addProgram(SC.pause(maxInstants));
}
m.addProgram(test_prg);
if("function"==typeof(testBehavior.async)){
testBehavior.async=testBehavior.async.bind(testBehavior);
}
const power= SC.processor({ n: maxInstants, async: testBehavior.async });
m.bindTo(power);
power.run();
if(testPanel.value==testBehavior.expected){
testNum++;
if(testNum<=max_test_file_num){
if(check_cont.checked){
window.location.search="?n="+testNum+"&continue=true";
}
}
else{
alert("Ok");
}
}
else{
document.getElementById("expected_result").innerHTML=""+testBehavior.expected;
testPanel.style.background="red";
}
</script>
</body>
</html>