aboutsummaryrefslogtreecommitdiff
path: root/test/optionals.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-11 12:39:56 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-11 12:39:56 -0400
commit30d39378c721aa6506c5aa038f6da9bf98cb1527 (patch)
tree5051263c667915bfd9178bbfdf691afb54088e3f /test/optionals.tm
parent210179ee672a0c3799328a54e886f574b3823e3d (diff)
Optional C Strings
Diffstat (limited to 'test/optionals.tm')
-rw-r--r--test/optionals.tm19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/optionals.tm b/test/optionals.tm
index a721deaa..521bba51 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -49,6 +49,12 @@ func maybe_lambda(should_i:Bool)-> func()?:
else:
return !func()
+func maybe_c_string(should_i:Bool)->CString?:
+ if should_i:
+ return ("hi":as_c_string())?
+ else:
+ return !CString
+
func main():
>> 5?
= 5? : Int?
@@ -162,6 +168,19 @@ func main():
fail("Truthy: $nope")
else: !! Falsey: $nope
+ do:
+ !! ...
+ !! C Strings:
+ >> yep := maybe_c_string(yes)
+ = CString("hi")?
+ >> nope := maybe_c_string(no)
+ = !CString
+ >> if yep: >> yep
+ else: fail("Falsey: $yep")
+ >> if nope:
+ fail("Truthy: $nope")
+ else: !! Falsey: $nope
+
if yep := maybe_int(yes):
>> yep
= 123 : Int