-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathbool.be
More file actions
54 lines (47 loc) · 1.31 KB
/
bool.be
File metadata and controls
54 lines (47 loc) · 1.31 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
# Test boolean expressions and conversions
# Test boolean comparisons
assert(1 != false && 1 != true)
assert(0 != false && 0 != true)
assert(!!1 == true)
assert(!!0 == false)
a = true
b = false
assert(!!list == true)
assert(a && b == false)
assert(!(a && b))
def test(a, b)
while !(a && b)
assert(false)
end
end
test(true, true)
# Test unary operator bug fix
def f(i)
var j = !i # Bug if i is erroneously modified
return i
end
assert(f(1) == 1)
# Test bool() function
assert(bool() == false)
assert(bool(0) == false)
assert(bool(0.0) == false)
assert(bool(false) == false)
assert(bool(nil) == false)
assert(bool(-1) == true)
assert(bool(3.5) == true)
assert(bool('') == false) # Changed behavior
assert(bool('a') == true)
assert(bool(list) == true)
assert(bool(list()) == false) # Changed behavior
assert(bool([]) == false) # Changed behavior
assert(bool([0]) == true)
assert(bool(map()) == false) # Changed behavior
assert(bool({}) == false) # Changed behavior
assert(bool({false:false}) == true)
assert(bool({nil:nil}) == false)# Changed behavior - nil key ignored
import introspect
assert(bool(introspect.toptr(0x1000)) == true)
assert(bool(introspect.toptr(0)) == false)
# Test bug fix for issue #372
def f() var a = false var b = true || a return a end
assert(f() == false)