-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ada754c
commit af27d65
Showing
5 changed files
with
75 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# test for the walrus operator | ||
var a = 1 | ||
assert((a := a + 1) == 2) | ||
assert((a := a + 1) == 3) | ||
|
||
def f() | ||
var defer = 10 | ||
var ret = [] | ||
for i:0..100 | ||
if (defer := defer - 1) == 0 | ||
ret.push(i) | ||
defer = 10 | ||
end | ||
end | ||
return ret | ||
end | ||
assert(f() == [9, 19, 29, 39, 49, 59, 69, 79, 89, 99]) | ||
|
||
# test for expressions with no side effects | ||
def assert_attribute_error(c) | ||
try | ||
compile(c)() | ||
assert(false, 'unexpected execution flow') | ||
except 'syntax_error' as e, m | ||
end | ||
end | ||
|
||
# below the expressions `a` or `a b` have no side effect and do not generate any code, this is an error when in strict mode | ||
import strict | ||
var a, b | ||
assert_attribute_error("var a,b def f() a b end") | ||
assert_attribute_error("var a,b def f() a end") | ||
|
||
# while the following does have side effect | ||
def f() a := b end |