-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path054_truthy.xml
More file actions
161 lines (129 loc) · 3.3 KB
/
054_truthy.xml
File metadata and controls
161 lines (129 loc) · 3.3 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
<?xml version="1.0" encoding="utf-8" ?>
<!--
/*****************************************************************************
*
* ReoScript - .NET Script Language Engine
*
* https://github.com/unvell/ReoScript
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
* PURPOSE.
*
* This software released under MIT license.
* Copyright (c) 2012-2019 Jingwood, unvell.com, all rights reserved.
*
****************************************************************************/
-->
<test-suite id="054" name="truthy">
<test-case id="001" name="if truthy values">
<script>
var t = debug.assert;
var result = false;
if (1) result = true;
t(result == true);
result = false;
if ("hello") result = true;
t(result == true);
result = false;
var obj = {};
if (obj) result = true;
t(result == true);
result = false;
if (-1) result = true;
t(result == true);
result = false;
if (0.5) result = true;
t(result == true);
</script>
</test-case>
<test-case id="002" name="if falsy values">
<script>
var t = debug.assert;
var result = true;
if (0) result = false;
t(result == true);
result = true;
if (null) result = false;
t(result == true);
result = true;
if ("") result = false;
t(result == true);
</script>
</test-case>
<test-case id="003" name="not operator truthy">
<script>
var t = debug.assert;
t(!null == true);
t(!0 == true);
t(!"" == true);
t(!1 == false);
t(!"hello" == false);
t(!{} == false);
</script>
</test-case>
<test-case id="004" name="logical or default value">
<script>
var t = debug.assert;
var a = null;
var b = a || "default";
t(b, "default");
var c = "value";
var d = c || "default";
t(d, "value");
var e = 0;
var f = e || 42;
t(f, 42);
</script>
</test-case>
<test-case id="005" name="logical and short-circuit">
<script>
var t = debug.assert;
var a = null;
var b = a && "hello";
t(b == null);
var c = "value";
var d = c && "hello";
t(d, "hello");
var e = 1;
var f = e && 42;
t(f, 42);
</script>
</test-case>
<test-case id="006" name="ternary with truthy">
<script>
var t = debug.assert;
var a = 1 ? "yes" : "no";
t(a, "yes");
var b = 0 ? "yes" : "no";
t(b, "no");
var c = "str" ? "yes" : "no";
t(c, "yes");
var d = null ? "yes" : "no";
t(d, "no");
</script>
</test-case>
<test-case id="007" name="while with truthy condition">
<script>
var t = debug.assert;
var count = 5;
var sum = 0;
while (count) {
sum += count;
count--;
}
t(sum, 15);
</script>
</test-case>
<test-case id="008" name="for with truthy condition">
<script>
var t = debug.assert;
var sum = 0;
for (var arr = [1,2,3], i = arr.length; i; i--) {
sum += arr[i - 1];
}
t(sum, 6);
</script>
</test-case>
</test-suite>