-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.xml
123 lines (117 loc) · 2.8 KB
/
test.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="justice.xsl" type="text/xsl"?>
<campaign xmlns="http://justice.hoverview.org/ns">
<import src="loop.js"/>
<test>
<synopsis>Check loaded</synopsis>
<action>
return !!loop;
</action>
<facit>true</facit>
</test>
<test>
<synopsis>Copy array</synopsis>
<action>
<![CDATA[
var input = ['gibbon', 'bonobo', 'lemur'];
var actual = loop(input, [], function(lo){
lo.result.push(lo.item);
});
return actual;
]]>
</action>
<facit><![CDATA[gibbon,bonobo,lemur]]></facit>
</test>
<test>
<synopsis>Find element and stop searching</synopsis>
<action>
<![CDATA[
var input = [{name:'gibbon', verdict:'gibbon'},
{name:'bonobo', verdict:'bonobo1'},
{name:'bonobo', verdict:'bonobo2'}];
var actual = loop(input, 'default', function(lo){
console.log(lo.item);
if(lo.item.name == 'bonobo'){
lo.result = lo.item.verdict;
lo.stop();
}
});
return actual;
]]>
</action>
<facit><![CDATA[bonobo1]]></facit>
</test>
<test>
<synopsis>Fold a sum</synopsis>
<action>
<![CDATA[
var input = [{name:'bonobo', nr:12},
{name:'bonobo', nr:23},
{name:'lemur', nr:19}];
var actual = loop(input, 0, function(lo){
if(lo.item.name == 'bonobo'){
lo.result += lo.item.nr;
}
});
return actual;
]]>
</action>
<facit><![CDATA[35]]></facit>
</test>
<test>
<synopsis>Cannot loop a number</synopsis>
<action>
<![CDATA[
var input = 23;
try {
return loop(23, "Wrong", function(lo){});
} catch (e) {
return e;
}
]]>
</action>
<facit><![CDATA[Cannot loop over 23]]></facit>
</test>
<test>
<synopsis>Missing first param is this</synopsis>
<action>
<![CDATA[
var input = [9, 5];
input.loop = loop;
return input.loop(12, function(lo){
lo.result += lo.item;
});
]]>
</action>
<facit><![CDATA[26]]></facit>
</test>
<test>
<synopsis>Missing second param is null</synopsis>
<action>
<![CDATA[
var input = [9];
input.loop = loop;
return input.loop(function(lo){
if(lo.result == null){
lo.result = true;
}
});
]]>
</action>
<facit><![CDATA[true]]></facit>
</test>
<test>
<synopsis>Only last loop returns true for isLast</synopsis>
<action>
<![CDATA[
var input = [5,4,3];
return loop(input, 0, function(lo){
if(lo.isLast()){
lo.result += lo.item;
}
});
]]>
</action>
<facit><![CDATA[3]]></facit>
</test>
</campaign>