-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstdlib-tests.lithia
149 lines (125 loc) · 3.85 KB
/
stdlib-tests.lithia
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
module example
import tests {
test
}
import tests.tests_t
import os
import lists
import strings
test "any in enums matches all types", { fail =>
enum AnyEnum {
Int
Any
}
let isCorrect = with "should be any", type AnyEnum {
Int: { _ => False },
Any: { _ => True }
}
unless isCorrect, fail "should not be the case"
}
test "any allows to use fewer enum cases in type expression", { fail =>
enum AnyEnum {
Int
String
Any
}
let isCorrect = with "should be any", type AnyEnum {
Int: { _ => False },
Any: { _ => True }
}
unless isCorrect, fail "should not be the case"
}
test "int comparisions", { fail =>
unless 1 == 1, fail "1 == 1"
unless 0 == 0, fail "0 == 0"
unless 0 != 42, fail "0 != 42"
unless 13 != 42, fail "13 != 42"
when 1 == 2, fail "!(1 == 2)"
unless 1 + 1 == 2, fail "1 + 1 == 2"
unless 3 * 2 + 1 == 7, fail "3 * 2 + 1 == 7"
unless 42 - 1 < 42, fail "42 - 1 < 42"
when 42 < 42, fail "42 < 42"
unless 1 * 1 == 1, fail "1 * 1 == 1"
func incr { i => i + 1 }
unless (incr 1) == 2, fail "(incr 1) == 2"
}
test "float comparisions", { fail =>
unless 1.0 == 1.0, fail "1.0 == 1.0"
unless 4.2 == 4.20, fail "4.2 == 4.20"
unless 0.0 == 0.0, fail "0.0 == 0.0"
unless 0.37 != 0.42, fail "0.37 != 0.42"
unless 1.3 != 4.2, fail "1.3 != 4.2"
when 1.2 == 2.3, fail "!(1.2 == 2.3)"
unless 1.1 + 1.2 == 2.3, fail "1.1 + 1.2 == 2.3"
unless 3.01 * 2 + 1 == 7.02, fail "3.01 * 2 + 1 == 7.02"
unless 4.2 - 0.1 < 4.2, fail "4.2 - 0.1 < 4.2"
when 4.2 < 4.2, fail "4.2 < 4.2"
unless 1.1 * 1 == 1.1, fail "1.1 * 1 == 1.1"
func incr { i => i + 1 }
unless (incr 1.3) == 2.3, fail "(incr 1.3) == 2.3"
}
test "lists.replicate", { fail =>
when (lists.replicate 0, 42) != [], fail "zero elements"
when (lists.replicate 1, 42) != [42], fail "one element"
when (lists.replicate 2, 42) != [42, 42], fail "two elements"
}
test "dict length", { fail =>
unless [:].length == 0, fail "[:] length 0"
unless ["a": "b"].length == 1, fail "[a: b] length 1"
unless ["a": "b", "c": "d"].length == 2, fail "[a: b, c: d] length 2"
}
test "dict get", { fail =>
let user = [
"username": "vknabel",
]
unless (user.get "username") == (Some "vknabel"), fail "found returns Some value"
unless (user.get "notfound") == None, fail "not found returns None"
}
test "dict set", { fail =>
let user = [
"username": "vknabel",
]
let changed = user.set "username", "@vknabel"
unless (user.get "username") == (Some "vknabel"), fail "does not change original"
unless (changed.get "username") == (Some "@vknabel"), fail "updates copy"
unless changed != user, fail "both dicts are not equal"
}
test "dict delete", { fail =>
let user = [
"username": "vknabel",
"id": 123
]
let changed = user.delete "id"
unless (user.get "id") == (Some 123), fail "does not change original"
unless (changed.get "id") == None, fail "updates copy"
unless changed != user, fail "both dicts are not equal"
}
test "dict keys", { fail =>
let user = [
"username": "vknabel",
"id": 123
]
unless user.keys == ["username", "id"] ||
user.keys == ["id", "username"], fail (strings.join " ", [
"must list all keys, got",
user.keys
])
}
test "dict values", { fail =>
let user = [
"username": "vknabel",
"id": 123
]
unless user.values == ["vknabel", 123] ||
user.values == [123, "vknabel"], fail (strings.join " ", [
"must list all values, got",
user.values
])
}
func main { =>
print "main not implemented."
print "to run tests, set LITHIA_TESTS=1"
os.exit 1
}
when tests.enabled, tests.runTests
unless tests.enabled, main