-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add breakelse, :else propagation and .else().
- Loading branch information
1 parent
16dd6a8
commit fe3a998
Showing
6 changed files
with
140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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").else(return) == 4); | ||
} | ||
|
||
void main() { | ||
basetest; | ||
findtest; | ||
} |