-
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.
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
VV_LOCAL_SYMBOL _result_string main__empty(string s) { | ||
_result_string _t2; /* if prepend */ | ||
if ((s).len != 0) { | ||
_result_ok(&(string[]) { s }, (_result*)(&_t2), sizeof(string)); | ||
} else { | ||
return (_result_string){ .is_error=true, .err=_v_error(_SLIT("empty")), .data={EMPTY_STRUCT_INITIALIZATION} }; | ||
} | ||
_result_string _t1 = _t2; | ||
return _t1; | ||
} |
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,21 @@ | ||
fn empty(s string) !string { | ||
return if s != '' { | ||
s | ||
} else { | ||
return error('empty') | ||
} | ||
} | ||
|
||
fn main() { | ||
str_1 := empty('something') or { | ||
assert false, 'something is not empty!' | ||
return | ||
} | ||
assert str_1 == 'something' | ||
|
||
str_2 := empty('') or { | ||
println('expected error ${err}') | ||
return | ||
} | ||
assert false, 'invalid accepted ${str_2}' | ||
} |