-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbreakelse.nt
45 lines (39 loc) · 1.06 KB
/
breakelse.nt
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
module breakelse;
macro import std.macro.assert;
void basetest() {
void check((bool | :test) value, bool ifTaken) {
if (bool b = value.case(:test: breakelse)) {
assert(ifTaken);
} else {
assert(!ifTaken);
}
if (bool b = value.case(:test: breakelse)) {
assert(ifTaken);
return;
}
assert(!ifTaken);
}
check(value=false, ifTaken=false);
check(value=true, ifTaken=true);
check(value=:test, ifTaken=false);
}
void findtest() {
(size_t | :else) find(string text, string marker) {
for (mut size_t i = 0; i <= text.length - marker.length; i++) {
if (text[i .. i + marker.length] == marker)
return i;
}
return :else;
}
if (size_t pos = "Helloworld".find("owo")?) {
assert(pos == 4);
} else {
assert(false);
}
assert("Helloworld".find("owo").(that? else return) == 4);
assert("Helloworld".find("uwu").(that? else return) == 4);
}
void main() {
basetest;
findtest;
}