aboutsummaryrefslogtreecommitdiff
path: root/test/for.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-07 12:07:14 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-03-07 12:07:14 -0500
commitcd1785b5cb4e432dc0f1bb4148517fd0f8d8de84 (patch)
tree03f6a28f736d58eec471273122fb09454f33e52b /test/for.tm
parent4e6001fa553a6478f9917d2b9b277127e460a581 (diff)
Added test
Diffstat (limited to 'test/for.tm')
-rw-r--r--test/for.tm49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/for.tm b/test/for.tm
new file mode 100644
index 00000000..05990d37
--- /dev/null
+++ b/test/for.tm
@@ -0,0 +1,49 @@
+
+func all_nums(nums:[Int])->Text
+ result := ""
+ for num in nums
+ result ++= "{num},"
+ else
+ return "EMPTY"
+ return result
+
+>> all_nums([10,20,30])
+= "10,20,30,"
+>> all_nums([:Int])
+= "EMPTY"
+
+func labeled_nums(nums:[Int])->Text
+ result := ""
+ for i,num in nums
+ result ++= "{i}:{num},"
+ else
+ return "EMPTY"
+ return result
+
+>> labeled_nums([10,20,30])
+= "1:10,2:20,3:30,"
+>> labeled_nums([:Int])
+= "EMPTY"
+
+func table_str(t:{Text=>Text})->Text
+ str := ""
+ for k,v in t
+ str ++= "{k}=>{v},"
+ else return "EMPTY"
+ return str
+
+>> t := {"key1"=>"value1", "key2"=>"value2"}
+>> table_str(t)
+= "key1=>value1,key2=>value2,"
+>> table_str({:Text=>Text})
+= "EMPTY"
+
+func table_key_str(t:{Text=>Text})->Text
+ str := ""
+ for k in t
+ str ++= "{k},"
+ else return "EMPTY"
+ return str
+
+>> table_key_str(t)
+= "key1,key2,"