-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v: unwrap an option value automatically, inside
if o != none {
(vla…
- Loading branch information
Showing
3 changed files
with
90 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
struct Test { | ||
a int | ||
} | ||
|
||
type MySum = f64 | int | ||
|
||
type MyAlias = Test | ||
|
||
fn test_int() { | ||
a := ?int(1) | ||
if a != none { | ||
assert dump(a) == 1 | ||
assert true | ||
} else { | ||
assert false | ||
} | ||
} | ||
|
||
fn test_struct() { | ||
b := ?Test{ | ||
a: 1 | ||
} | ||
if b != none { | ||
assert dump(b) == Test{ | ||
a: 1 | ||
} | ||
assert true | ||
} else { | ||
assert false | ||
} | ||
} | ||
|
||
fn test_string() { | ||
c := ?string('foo') | ||
if c != none { | ||
assert dump(c) == 'foo' | ||
assert true | ||
} else { | ||
assert false | ||
} | ||
} | ||
|
||
fn test_sum_type() { | ||
d := ?MySum(1.2) | ||
assert d != none | ||
|
||
if d != none { | ||
assert dump(d) == MySum(1.2) | ||
assert true | ||
} else { | ||
assert false | ||
} | ||
} | ||
|
||
fn test_alias() { | ||
d := ?MyAlias(Test{ | ||
a: 1 | ||
}) | ||
assert d != none | ||
|
||
if d != none { | ||
assert dump(d) == Test{ | ||
a: 1 | ||
} | ||
assert true | ||
} else { | ||
assert false | ||
} | ||
} |