aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/arrays.tm52
-rw-r--r--test/bytes.tm2
-rw-r--r--test/corecursive_func.tm14
-rw-r--r--test/defer.tm42
-rw-r--r--test/enums.tm28
-rw-r--r--test/extern.tm2
-rw-r--r--test/for.tm26
-rw-r--r--test/functions.tm6
-rw-r--r--test/import.tm6
-rw-r--r--test/inline_c.tm2
-rw-r--r--test/integers.tm12
-rw-r--r--test/iterators.tm18
-rw-r--r--test/lambdas.tm28
-rw-r--r--test/lang.tm14
-rw-r--r--test/metamethods.tm34
-rw-r--r--test/minmax.tm6
-rw-r--r--test/nums.tm2
-rw-r--r--test/optionals.tm202
-rw-r--r--test/paths.tm10
-rw-r--r--test/reductions.tm2
-rw-r--r--test/serialization.tm32
-rw-r--r--test/sets.tm2
-rw-r--r--test/structs.tm10
-rw-r--r--test/tables.tm14
-rw-r--r--test/text.tm6
-rw-r--r--test/use_import.tm4
-rw-r--r--test/when.tm14
27 files changed, 295 insertions, 295 deletions
diff --git a/test/arrays.tm b/test/arrays.tm
index c60085ca..f2ed2c7a 100644
--- a/test/arrays.tm
+++ b/test/arrays.tm
@@ -1,9 +1,9 @@
-func main():
- do:
+func main()
+ do
>> nums : [Num32] = []
= []
- do:
+ do
>> arr := [10, 20, 30]
= [10, 20, 30]
@@ -16,18 +16,18 @@ func main():
= 3
sum := 0
- for x in arr:
+ for x in arr
sum += x
>> sum
= 60
str := ""
- for i,x in arr:
+ for i,x in arr
str ++= "($i,$x)"
>> str
= "(1,10)(2,20)(3,30)"
- do:
+ do
>> arr := [10, 20] ++ [30, 40]
= [10, 20, 30, 40]
@@ -35,7 +35,7 @@ func main():
>> arr
= [10, 20, 30, 40, 50, 60]
- do:
+ do
>> arr := [10, 20]
>> copy := arr
>> arr ++= [30]
@@ -44,7 +44,7 @@ func main():
>> copy
= [10, 20]
- do:
+ do
>> [10*i for i in 5]
= [10, 20, 30, 40, 50]
@@ -57,7 +57,7 @@ func main():
>> [x for x in y if x > 1 for y in [3, 4, 5] if y < 5]
= [2, 3, 2, 3, 4]
- do:
+ do
>> arr := @[10, 20]
>> copy := arr[]
>> arr.insert(30)
@@ -70,7 +70,7 @@ func main():
>> arr
= @[999, 20, 30]
- do:
+ do
>> arr := &[10, 20, 30]
>> reversed := arr.reversed()
= [30, 20, 10]
@@ -79,7 +79,7 @@ func main():
>> reversed
= [30, 20, 10]
- do:
+ do
>> nums := @[10, -20, 30]
# Sorted function doesn't mutate original:
>> nums.sorted()
@@ -91,34 +91,34 @@ func main():
>> nums
= @[-20, 10, 30]
# Custom sort functions:
- >> nums.sort(func(x,y:&Int): x.abs() <> y.abs())
+ >> nums.sort(func(x,y:&Int) x.abs() <> y.abs())
>> nums
= @[10, -20, 30]
- >> nums.sort(func(x,y:&Int): y[] <> x[])
+ >> nums.sort(func(x,y:&Int) y[] <> x[])
>> nums
= @[30, 10, -20]
>> ["A", "B", "C"].sample(10, [1.0, 0.5, 0.0])
- do:
+ do
>> heap := @[(i * 1337) mod 37 for i in 10]
>> heap.heapify()
>> heap
heap_order : @[Int] = @[]
- repeat:
+ repeat
heap_order.insert(heap.heap_pop() or stop)
>> heap_order[] == heap_order.sorted()
= yes
heap_order[] = []
- for i in 10:
+ for i in 10
heap.heap_push((i*13337) mod 37)
>> heap
- repeat:
+ repeat
heap_order.insert(heap.heap_pop() or stop)
>> heap_order[] == heap_order.sorted()
= yes
- do:
+ do
>> [i*10 for i in 5].from(3)
= [30, 40, 50]
>> [i*10 for i in 5].to(3)
@@ -146,17 +146,17 @@ func main():
# Test iterating over array.from() and array.to()
xs := ["A", "B", "C", "D"]
- for i,x in xs.to(-2):
- for y in xs.from(i+1):
+ for i,x in xs.to(-2)
+ for y in xs.from(i+1)
say("$(x)$(y)")
- do:
+ do
>> nums := @[-7, -4, -1, 2, 5]
>> nums.sort()
>> [nums.binary_search(i) for i in nums[]]
= [1, 2, 3, 4, 5]
- >> nums.sort(func(a,b:&Int): a.abs() <> b.abs())
- >> [nums.binary_search(i, func(a,b:&Int): a.abs() <> b.abs()) for i in nums[]]
+ >> nums.sort(func(a,b:&Int) a.abs() <> b.abs())
+ >> [nums.binary_search(i, func(a,b:&Int) a.abs() <> b.abs()) for i in nums[]]
= [1, 2, 3, 4, 5]
>> ["a", "b", "c"].find("b")
@@ -164,12 +164,12 @@ func main():
>> ["a", "b", "c"].find("XXX")
= none
- >> [10, 20].first(func(i:&Int): i.is_prime())
+ >> [10, 20].first(func(i:&Int) i.is_prime())
= none
- >> [4, 5, 6].first(func(i:&Int): i.is_prime())
+ >> [4, 5, 6].first(func(i:&Int) i.is_prime())
= 2?
- do:
+ do
>> nums := &[10, 20, 30, 40, 50]
>> nums.pop()
= 50?
diff --git a/test/bytes.tm b/test/bytes.tm
index 862d2674..25efbeb8 100644
--- a/test/bytes.tm
+++ b/test/bytes.tm
@@ -1,5 +1,5 @@
-func main():
+func main()
say("Test bytes:")
>> Byte(100)
= Byte(0x64)
diff --git a/test/corecursive_func.tm b/test/corecursive_func.tm
index b5f5f13e..8faf8b0d 100644
--- a/test/corecursive_func.tm
+++ b/test/corecursive_func.tm
@@ -1,15 +1,15 @@
-func ping(x:Int->[Text]):
- if x > 0:
+func ping(x:Int->[Text])
+ if x > 0
return ["ping: $x"] ++ pong(x-1)
- else:
+ else
return ["ping: $x"]
-func pong(x:Int->[Text]):
- if x > 0:
+func pong(x:Int->[Text])
+ if x > 0
return ["pong: $x"] ++ ping(x-1)
- else:
+ else
return ["pong: $x"]
-func main():
+func main()
>> ping(3)
= ["ping: 3", "pong: 2", "ping: 1", "pong: 0"]
diff --git a/test/defer.tm b/test/defer.tm
index 4053f0c1..e5033075 100644
--- a/test/defer.tm
+++ b/test/defer.tm
@@ -1,8 +1,8 @@
-func main():
+func main()
x := 123
nums : @[Int] = @[]
- do:
- defer:
+ do
+ defer
nums.insert(x)
x = 999
@@ -11,28 +11,28 @@ func main():
>> x
= 999
- defer:
+ defer
say("All done!")
- for word in ["first", "second", "third"]:
- defer:
+ for word in ["first", "second", "third"]
+ defer
say("Got $word deferred")
- if word == "second":
+ if word == "second"
say("<skipped>")
skip
- else if word == "third":
+ else if word == "third"
say("<stopped>")
stop
- for i in 3:
- defer:
+ for i in 3
+ defer
say("Inner loop deferred $i")
- if i == 2:
+ if i == 2
say("<skipped inner>")
skip
- else if i == 3:
+ else if i == 3
say("<stopped inner>")
stop
@@ -40,12 +40,12 @@ func main():
say("Made it through the loop")
- >> thunk := func(return_early=no):
+ >> thunk := func(return_early=no)
say("Entering thunk")
- defer:
+ defer
say("Deferred thunk cleanup")
- if return_early:
+ if return_early
say("Returning early...")
return
@@ -65,20 +65,20 @@ func main():
>> counter()
= 3
-func defer_func(return_early=no):
+func defer_func(return_early=no)
say("Entering defer_func")
- defer:
+ defer
say("Deferred defer_func cleanup")
- if return_early:
+ if return_early
say("Returning early...")
return
say("Finished defer_func")
-func make_counter(->func(->Int)):
+func make_counter(->func(->Int))
i := 1
- return func():
- defer: i += 1
+ return func()
+ defer i += 1
return i
diff --git a/test/enums.tm b/test/enums.tm
index a11f95f9..3b3b31ea 100644
--- a/test/enums.tm
+++ b/test/enums.tm
@@ -1,21 +1,21 @@
enum Foo(Zero, One(x:Int), Two(x:Int, y:Int), Three(x:Int, y:Text, z:Bool), Four(x,y,z,w:Int), Last(t:Text))
-func choose_text(f:Foo->Text):
+func choose_text(f:Foo->Text)
>> f
- when f is Zero:
+ when f is Zero
return "Zero"
- is One(one):
+ is One(one)
return "One: $one"
- is Two(x, y):
+ is Two(x, y)
return "Two: x=$x, y=$y"
- is Three(three):
+ is Three(three)
return "Three: $three"
- is Four:
+ is Four
return "Four"
- else:
+ else
return "else: $f"
-func main():
+func main()
>> Foo.Zero
= Foo.Zero
>> Foo.One(123)
@@ -63,24 +63,24 @@ func main():
i := 1
cases := [Foo.One(1), Foo.One(2), Foo.Zero]
- while when cases[i] is One(x):
+ while when cases[i] is One(x)
>> x
i += 1
>> [
(
- when x is One(y), Two(y,_):
+ when x is One(y), Two(y,_)
"Small $y"
- is Zero:
+ is Zero
"Zero"
- else:
+ else
"Other"
) for x in [Foo.Zero, Foo.One(1), Foo.Two(2,2), Foo.Three(3,"",no)]
]
= ["Zero", "Small 1", "Small 2", "Other"]
- >> expr := when cases[1] is One(y):
+ >> expr := when cases[1] is One(y)
y + 1
- else:
+ else
-1
= 2
diff --git a/test/extern.tm b/test/extern.tm
index 17c39948..8e2b6c06 100644
--- a/test/extern.tm
+++ b/test/extern.tm
@@ -1,5 +1,5 @@
extern sqrt : func(n:Num->Num)
-func main():
+func main()
>> sqrt(4)
= 2.
diff --git a/test/for.tm b/test/for.tm
index e4967e86..75ad2fee 100644
--- a/test/for.tm
+++ b/test/for.tm
@@ -1,35 +1,35 @@
-func all_nums(nums:[Int] -> Text):
+func all_nums(nums:[Int] -> Text)
result := ""
- for num in nums:
+ for num in nums
result ++= "$num,"
- else:
+ else
return "EMPTY"
return result
-func labeled_nums(nums:[Int] -> Text):
+func labeled_nums(nums:[Int] -> Text)
result := ""
- for i,num in nums:
+ for i,num in nums
result ++= "$i:$num,"
- else:
+ else
return "EMPTY"
return result
-func table_str(t:{Text=Text} -> Text):
+func table_str(t:{Text=Text} -> Text)
str := ""
- for k,v in t:
+ for k,v in t
str ++= "$k:$v,"
- else: return "EMPTY"
+ else return "EMPTY"
return str
-func table_key_str(t:{Text=Text} -> Text):
+func table_key_str(t:{Text=Text} -> Text)
str := ""
- for k in t:
+ for k in t
str ++= "$k,"
- else: return "EMPTY"
+ else return "EMPTY"
return str
-func main():
+func main()
>> all_nums([10,20,30])
= "10,20,30,"
>> all_nums([])
diff --git a/test/functions.tm b/test/functions.tm
index 22d950d4..17ca1e85 100644
--- a/test/functions.tm
+++ b/test/functions.tm
@@ -1,10 +1,10 @@
-func add(x:Int, y:Int -> Int):
+func add(x:Int, y:Int -> Int)
return x + y
-func cached_heap(x:Int->@Int; cached):
+func cached_heap(x:Int->@Int; cached)
return @x
-func main():
+func main()
>> add(3, 5)
= 8
diff --git a/test/import.tm b/test/import.tm
index 960bfcbb..a6a6fa16 100644
--- a/test/import.tm
+++ b/test/import.tm
@@ -1,13 +1,13 @@
vectors := use ../examples/vectors/vectors.tm
use ./use_import.tm
-func returns_vec(->vectors.Vec2):
+func returns_vec(->vectors.Vec2)
return vectors.Vec2(1, 2)
-func returns_imported_type(->ImportedType):
+func returns_imported_type(->ImportedType)
return get_value() # Imported from ./use_import.tm
-func main():
+func main()
>> empty : [vectors.Vec2] = []
>> returns_vec()
= Vec2(x=1, y=2)
diff --git a/test/inline_c.tm b/test/inline_c.tm
index 3c0949cd..a79359d1 100644
--- a/test/inline_c.tm
+++ b/test/inline_c.tm
@@ -1,5 +1,5 @@
-func main():
+func main()
>> inline C:Int32 { int x = 1 + 2; x }
= Int32(3)
diff --git a/test/integers.tm b/test/integers.tm
index 508a38ae..72a195b4 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -1,4 +1,4 @@
-func main():
+func main()
>> 2 + 3
= 5
@@ -37,7 +37,7 @@ func main():
= 1
nums := ""
- for x in 5:
+ for x in 5
nums ++= "$x,"
>> nums
= "1,2,3,4,5,"
@@ -66,7 +66,7 @@ func main():
>> Int(2.1, truncate=yes)
= 2
- do:
+ do
>> small_int := 1
= 1
>> max_small_int := 536870911
@@ -84,11 +84,11 @@ func main():
>> super_big + 1
= 10000000000000000000000
- do:
+ do
interesting_numerators := [-999999, -100, -23, -1, 0, 1, 23, 100, 999999]
interesting_denominators := [-99, -20, -17, -1, 1, 17, 20, 99]
- for n in interesting_numerators:
- for d in interesting_denominators:
+ for n in interesting_numerators
+ for d in interesting_denominators
>> (n/d)*d + (n mod d) == n
= yes
diff --git a/test/iterators.tm b/test/iterators.tm
index 64d21ea3..1816fd7a 100644
--- a/test/iterators.tm
+++ b/test/iterators.tm
@@ -1,22 +1,22 @@
struct Pair(x:Text, y:Text)
-func pairwise(strs:[Text] -> func(->Pair?)):
+func pairwise(strs:[Text] -> func(->Pair?))
i := 1
- return func():
- if i + 1 > strs.length: return none
+ return func()
+ if i + 1 > strs.length return none
i += 1
return Pair(strs[i-1], strs[i])?
-func range(first:Int, last:Int -> func(->Int?)):
+func range(first:Int, last:Int -> func(->Int?))
i := first
- return func():
- if i > last:
+ return func()
+ if i > last
return none
i += 1
return (i-1)?
-func main():
+func main()
values := ["A", "B", "C", "D"]
>> (++: "($(foo.x)$(foo.y))" for foo in pairwise(values))!
@@ -24,9 +24,9 @@ func main():
>> ["$(foo.x)$(foo.y)" for foo in pairwise(values)]
= ["AB", "BC", "CD"]
- do:
+ do
result : @[Text] = @[]
- for foo in pairwise(values):
+ for foo in pairwise(values)
result.insert("$(foo.x)$(foo.y)")
>> result[]
= ["AB", "BC", "CD"]
diff --git a/test/lambdas.tm b/test/lambdas.tm
index 6e261e0f..d6501cb7 100644
--- a/test/lambdas.tm
+++ b/test/lambdas.tm
@@ -1,18 +1,18 @@
-func make_adder(x:Int -> func(y:Int->Int)):
- return func(y:Int): x + y
+func make_adder(x:Int -> func(y:Int->Int))
+ return func(y:Int) x + y
-func suffix_fn(fn:func(t:Text->Text), suffix:Text -> func(t:Text->Text)):
- return func(t:Text): fn(t)++suffix
+func suffix_fn(fn:func(t:Text->Text), suffix:Text -> func(t:Text->Text))
+ return func(t:Text) fn(t)++suffix
-func mul_func(n:Int, fn:func(x:Int->Int) -> func(x:Int->Int)):
- return func(x:Int): n*fn(x)
+func mul_func(n:Int, fn:func(x:Int->Int) -> func(x:Int->Int))
+ return func(x:Int) n*fn(x)
-func main():
- >> add_one := func(x:Int): x + 1
+func main()
+ >> add_one := func(x:Int) x + 1
>> add_one(10)
= 11
- >> shout := func(msg:Text): say("$(msg.upper())!")
+ >> shout := func(msg:Text) say("$(msg.upper())!")
>> shout("hello")
>> asdf := add_one
@@ -23,7 +23,7 @@ func main():
>> add_100(5)
= 105
- >> shout2 := suffix_fn(func(t:Text): t.upper(), "!")
+ >> shout2 := suffix_fn(func(t:Text) t.upper(), "!")
>> shout2("hello")
= "HELLO!"
@@ -33,10 +33,10 @@ func main():
# Test nested lambdas:
outer := "Hello"
- fn := func():
- return func():
- return func():
- defer: say("$outer")
+ fn := func()
+ return func()
+ return func()
+ defer say("$outer")
return outer
>> fn()()()
= "Hello"
diff --git a/test/lang.tm b/test/lang.tm
index 6d0a94ea..081438ed 100644
--- a/test/lang.tm
+++ b/test/lang.tm
@@ -1,6 +1,6 @@
-lang HTML:
+lang HTML
HEADER := $HTML"<!DOCTYPE HTML>"
- convert(t:Text->HTML):
+ convert(t:Text->HTML)
t = t.translate({
"&"="&amp;",
"<"="&lt;",
@@ -11,17 +11,17 @@ lang HTML:
return HTML.from_text(t)
- convert(i:Int->HTML):
+ convert(i:Int->HTML)
return HTML.from_text("$i")
- func paragraph(content:HTML->HTML):
+ func paragraph(content:HTML->HTML)
return $HTML"<p>$content</p>"
-struct Bold(text:Text):
- convert(b:Bold -> HTML):
+struct Bold(text:Text)
+ convert(b:Bold -> HTML)
return $HTML"<b>$(b.text)</b>"
-func main():
+func main()
>> HTML.HEADER
= $HTML"<!DOCTYPE HTML>"
diff --git a/test/metamethods.tm b/test/metamethods.tm
index aac37c4b..9399bc9a 100644
--- a/test/metamethods.tm
+++ b/test/metamethods.tm
@@ -1,50 +1,50 @@
-struct Vec2(x,y:Int):
- func plus(a,b:Vec2 -> Vec2; inline):
+struct Vec2(x,y:Int)
+ func plus(a,b:Vec2 -> Vec2; inline)
return Vec2(a.x+b.x, a.y+b.y)
- func minus(a,b:Vec2 -> Vec2; inline):
+ func minus(a,b:Vec2 -> Vec2; inline)
return Vec2(a.x-b.x, a.y-b.y)
- func dot(a,b:Vec2 -> Int; inline):
+ func dot(a,b:Vec2 -> Int; inline)
return a.x*b.x + a.y*b.y
- func scaled_by(a:Vec2, k:Int -> Vec2; inline):
+ func scaled_by(a:Vec2, k:Int -> Vec2; inline)
return Vec2(a.x*k, a.y*k)
- func times(a,b:Vec2 -> Vec2; inline):
+ func times(a,b:Vec2 -> Vec2; inline)
return Vec2(a.x*b.x, a.y*b.y)
- func divided_by(a:Vec2, k:Int -> Vec2; inline):
+ func divided_by(a:Vec2, k:Int -> Vec2; inline)
return Vec2(a.x/k, a.y/k)
- func negative(v:Vec2 -> Vec2; inline):
+ func negative(v:Vec2 -> Vec2; inline)
return Vec2(-v.x, -v.y)
- func negated(v:Vec2 -> Vec2; inline):
+ func negated(v:Vec2 -> Vec2; inline)
return Vec2(not v.x, not v.y)
- func bit_and(a,b:Vec2 -> Vec2; inline):
+ func bit_and(a,b:Vec2 -> Vec2; inline)
return Vec2(a.x and b.x, a.y and b.y)
- func bit_or(a,b:Vec2 -> Vec2; inline):
+ func bit_or(a,b:Vec2 -> Vec2; inline)
return Vec2(a.x or b.x, a.y or b.y)
- func bit_xor(a,b:Vec2 -> Vec2; inline):
+ func bit_xor(a,b:Vec2 -> Vec2; inline)
return Vec2(a.x xor b.x, a.y xor b.y)
- func left_shifted(v:Vec2, bits:Int -> Vec2; inline):
+ func left_shifted(v:Vec2, bits:Int -> Vec2; inline)
return Vec2(v.x >> bits, v.y >> bits)
- func right_shifted(v:Vec2, bits:Int -> Vec2; inline):
+ func right_shifted(v:Vec2, bits:Int -> Vec2; inline)
return Vec2(v.x << bits, v.y << bits)
- func modulo(v:Vec2, modulus:Int -> Vec2; inline):
+ func modulo(v:Vec2, modulus:Int -> Vec2; inline)
return Vec2(v.x mod modulus, v.y mod modulus)
- func modulo1(v:Vec2, modulus:Int -> Vec2; inline):
+ func modulo1(v:Vec2, modulus:Int -> Vec2; inline)
return Vec2(v.x mod1 modulus, v.y mod1 modulus)
-func main():
+func main()
>> x := Vec2(10, 20)
>> y := Vec2(100, 200)
>> x + y
diff --git a/test/minmax.tm b/test/minmax.tm
index a0f0640f..8ffb401e 100644
--- a/test/minmax.tm
+++ b/test/minmax.tm
@@ -1,9 +1,9 @@
-struct Foo(x:Int, y:Int):
- func len(f:Foo->Num):
+struct Foo(x:Int, y:Int)
+ func len(f:Foo->Num)
return Num.sqrt(Num(f.x*f.x + f.y*f.y))!
-func main():
+func main()
>> 3 _min_ 5
= 3
>> 5 _min_ 3
diff --git a/test/nums.tm b/test/nums.tm
index e5de1e22..573b50ec 100644
--- a/test/nums.tm
+++ b/test/nums.tm
@@ -1,4 +1,4 @@
-func main():
+func main()
>> n := 1.5
= 1.5
diff --git a/test/optionals.tm b/test/optionals.tm
index bf3e1633..d81d065f 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -1,74 +1,74 @@
-struct Struct(x:Int, y:Text):
- func maybe(should_i:Bool->Struct?):
- if should_i:
+struct Struct(x:Int, y:Text)
+ func maybe(should_i:Bool->Struct?)
+ if should_i
return Struct(123, "hello")
- else:
+ else
return none
-enum Enum(X, Y(y:Int)):
- func maybe(should_i:Bool->Enum?):
- if should_i:
+enum Enum(X, Y(y:Int))
+ func maybe(should_i:Bool->Enum?)
+ if should_i
return Enum.Y(123)
- else:
+ else
return none
-func maybe_int(should_i:Bool->Int?):
- if should_i:
+func maybe_int(should_i:Bool->Int?)
+ if should_i
return 123
- else:
+ else
return none
-func maybe_int64(should_i:Bool->Int64?):
- if should_i:
+func maybe_int64(should_i:Bool->Int64?)
+ if should_i
return Int64(123)
- else:
+ else
return none
-func maybe_array(should_i:Bool->[Int]?):
- if should_i:
+func maybe_array(should_i:Bool->[Int]?)
+ if should_i
return [10, 20, 30]
- else:
+ else
return none
-func maybe_bool(should_i:Bool->Bool?):
- if should_i:
+func maybe_bool(should_i:Bool->Bool?)
+ if should_i
return no
- else:
+ else
return none
-func maybe_text(should_i:Bool->Text?):
- if should_i:
+func maybe_text(should_i:Bool->Text?)
+ if should_i
return "Hello"
- else:
+ else
return none
-func maybe_num(should_i:Bool->Num?):
- if should_i:
+func maybe_num(should_i:Bool->Num?)
+ if should_i
return 12.3
- else:
+ else
return none
-func maybe_lambda(should_i:Bool-> func()?):
- if should_i:
- return func(): say("hi!")
- else:
+func maybe_lambda(should_i:Bool-> func()?)
+ if should_i
+ return func() say("hi!")
+ else
return none
-func maybe_c_string(should_i:Bool->CString?):
- if should_i:
+func maybe_c_string(should_i:Bool->CString?)
+ if should_i
return ("hi".as_c_string())?
- else:
+ else
return none
-func main():
+func main()
>> 5?
= 5?
- >> if no:
+ >> if no
x : Int? = none
x
- else:
+ else
5
= 5?
@@ -85,157 +85,157 @@ func main():
>> none_int or -1
= -1
- do:
+ do
say("Ints:")
>> yep := maybe_int(yes)
= 123?
>> nope := maybe_int(no)
= none
- >> if yep:
+ >> if yep
>> yep
= 123
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("Int64s:")
>> yep := maybe_int64(yes)
= Int64(123)?
>> nope := maybe_int64(no)
= none
- >> if yep:
+ >> if yep
>> yep
= Int64(123)
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("Arrays:")
>> yep := maybe_array(yes)
= [10, 20, 30]?
>> nope := maybe_array(no)
= none
- >> if yep:
+ >> if yep
>> yep
= [10, 20, 30]
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("Bools:")
>> yep := maybe_bool(yes)
= no?
>> nope := maybe_bool(no)
= none
- >> if yep:
+ >> if yep
>> yep
= no
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("Text:")
>> yep := maybe_text(yes)
= "Hello"?
>> nope := maybe_text(no)
= none
- >> if yep:
+ >> if yep
>> yep
= "Hello"
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("Nums:")
>> yep := maybe_num(yes)
= 12.3?
>> nope := maybe_num(no)
= none
- >> if yep:
+ >> if yep
>> yep
= 12.3
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("Lambdas:")
# >> yep := maybe_lambda(yes)
# = func() [optionals.tm:54] : func()?
>> nope := maybe_lambda(no)
= none
- # >> if yep:
+ # >> if yep
# >> yep
# = func() [optionals.tm:54]
- # else: fail("Falsey: $yep")
- >> if nope:
+ # else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("Structs:")
>> yep := Struct.maybe(yes)
= Struct(x=123, y="hello")?
>> nope := Struct.maybe(no)
= none
- >> if yep:
+ >> if yep
>> yep
= Struct(x=123, y="hello")
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("Enums:")
>> yep := Enum.maybe(yes)
= Enum.Y(123)?
>> nope := Enum.maybe(no)
= none
- >> if yep:
+ >> if yep
>> yep
= Enum.Y(123)
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- do:
+ do
say("...")
say("C Strings:")
>> yep := maybe_c_string(yes)
= CString("hi")?
>> nope := maybe_c_string(no)
= none
- >> if yep:
+ >> if yep
>> yep
= CString("hi")
- else: fail("Falsey: $yep")
- >> if nope:
+ else fail("Falsey: $yep")
+ >> if nope
fail("Truthy: $nope")
- else: say("Falsey: $nope")
+ else say("Falsey: $nope")
- if yep := maybe_int(yes):
+ if yep := maybe_int(yes)
>> yep
= 123
- else: fail("Unreachable")
+ else fail("Unreachable")
>> maybe_int(yes)!
= 123
@@ -251,32 +251,32 @@ func main():
>> [5?, none, none, 6?].sorted()
= [none, none, 5, 6]
- do:
- >> value := if var := 5?:
+ do
+ >> value := if var := 5?
var
- else:
+ else
0
= 5
- do:
+ do
>> value := if var : Int? = none:
var
- else:
+ else
0
= 0
- do:
+ do
>> opt := 5?
- >> if opt:
+ >> if opt
>> opt
- else:
+ else
>> opt
- do:
+ do
>> opt : Int? = none
- >> if opt:
+ >> if opt
>> opt
- else:
+ else
>> opt
>> not 5?
@@ -289,7 +289,7 @@ func main():
>> [Struct(5,"A")?, Struct(6,"B"), Struct(7,"C")]
= [Struct(x=5, y="A")?, Struct(x=6, y="B")?, Struct(x=7, y="C")?]
- if 5? or no:
+ if 5? or no
say("Binary op 'or' works with optionals")
- else:
+ else
fail("Failed to do binary op 'or' on optional")
diff --git a/test/paths.tm b/test/paths.tm
index 85f9b191..700a0393 100644
--- a/test/paths.tm
+++ b/test/paths.tm
@@ -1,5 +1,5 @@
# Tests for file paths
-func main():
+func main()
>> (/).exists()
= yes
>> (~/).exists()
@@ -29,19 +29,19 @@ func main():
>> tmpdir.files().has(tmpfile)
= yes
- if tmp_lines := tmpfile.by_line():
+ if tmp_lines := tmpfile.by_line()
>> [line for line in tmp_lines]
= ["Hello world!"]
- else:
+ else
fail("Couldn't read lines in $tmpfile")
>> (./does-not-exist.xxx).read()
= none
>> (./does-not-exist.xxx).read_bytes()
= none
- if lines := (./does-not-exist.xxx).by_line():
+ if lines := (./does-not-exist.xxx).by_line()
fail("I could read lines in a nonexistent file")
- else:
+ else
pass
>> tmpfile.remove()
diff --git a/test/reductions.tm b/test/reductions.tm
index c56c7d09..2666e1a9 100644
--- a/test/reductions.tm
+++ b/test/reductions.tm
@@ -1,6 +1,6 @@
struct Foo(x,y:Int)
-func main():
+func main()
>> (+: [10, 20, 30])
= 60?
diff --git a/test/serialization.tm b/test/serialization.tm
index b3ccc67a..457442e5 100644
--- a/test/serialization.tm
+++ b/test/serialization.tm
@@ -3,45 +3,45 @@ struct Foo(name:Text, next:@Foo?=none)
enum MyEnum(Zero, One(x:Int), Two(x:Num, y:Text))
-func main():
- do:
+func main()
+ do
>> obj := Int64(123)
>> bytes := obj.serialized()
>> deserialize(bytes -> Int64) == obj
= yes
- do:
+ do
>> obj := 5
>> bytes := obj.serialized()
>> deserialize(bytes -> Int) == obj
= yes
- do:
+ do
>> obj := 9999999999999999999999999999999999999999999999999999
>> bytes := obj.serialized()
>> deserialize(bytes -> Int) == obj
= yes
- do:
+ do
>> obj := "Héllo"
>> bytes := obj.serialized()
>> deserialize(bytes -> Text)
>> deserialize(bytes -> Text) == obj
= yes
- do:
+ do
>> obj := [Int64(10), Int64(20), Int64(30)].reversed()
>> bytes := obj.serialized()
>> deserialize(bytes -> [Int64]) == obj
= yes
- do:
+ do
>> obj := yes
>> bytes := obj.serialized()
>> deserialize(bytes -> Bool) == obj
= yes
- do:
+ do
>> obj := @[10, 20]
>> bytes := obj.serialized()
>> roundtrip := deserialize(bytes -> @[Int])
@@ -50,46 +50,46 @@ func main():
>> roundtrip[] == obj[]
= yes
- do:
+ do
>> obj := {"A"=10, "B"=20; fallback={"C"=30}}
>> bytes := obj.serialized()
>> deserialize(bytes -> {Text=Int}) == obj
= yes
- do:
+ do
>> obj := @Foo("root")
>> obj.next = @Foo("abcdef", next=obj)
>> bytes := obj.serialized()
>> deserialize(bytes -> @Foo)
# = @Foo(name="root", next=@Foo(name="abcdef", next=@~1))
- do:
+ do
>> obj := MyEnum.Two(123, "OKAY")
>> bytes := obj.serialized()
>> deserialize(bytes -> MyEnum) == obj
= yes
- do:
+ do
>> obj := "Hello"?
>> bytes := obj.serialized()
>> deserialize(bytes -> Text?) == obj
= yes
- do:
+ do
>> obj := {10, 20, 30}
>> bytes := obj.serialized()
>> deserialize(bytes -> {Int}) == obj
= yes
- do:
+ do
>> obj : Num? = none
>> bytes := obj.serialized()
>> deserialize(bytes -> Num?) == obj
= yes
- do:
+ do
cases := [0, -1, 1, 10, 100000, 999999999999999999999999999]
- for i in cases:
+ for i in cases
>> bytes := i.serialized()
>> deserialize(bytes -> Int) == i
= yes
diff --git a/test/sets.tm b/test/sets.tm
index 5179947e..1c395fba 100644
--- a/test/sets.tm
+++ b/test/sets.tm
@@ -1,5 +1,5 @@
-func main():
+func main()
>> t1 := @{10, 20, 30, 10}
= @{10, 20, 30}
>> t1.has(10)
diff --git a/test/structs.tm b/test/structs.tm
index cf7b6a1c..f1ae49d0 100644
--- a/test/structs.tm
+++ b/test/structs.tm
@@ -8,7 +8,7 @@ struct Password(text:Text; secret)
struct CorecursiveA(other:@CorecursiveB?)
struct CorecursiveB(other:@CorecursiveA?=none)
-func test_literals():
+func test_literals()
>> Single(123)
= Single(123)
>> x := Pair(10, 20)
@@ -20,7 +20,7 @@ func test_literals():
>> x == Pair(-1, -2)
= no
-func test_metamethods():
+func test_metamethods()
>> x := Pair(10, 20)
>> y := Pair(100, 200)
>> x == y
@@ -38,7 +38,7 @@ func test_metamethods():
>> set.has(y)
= no
-func test_mixed():
+func test_mixed()
>> x := Mixed(10, "Hello")
>> y := Mixed(99, "Hello")
>> x == y
@@ -55,14 +55,14 @@ func test_mixed():
>> set.has(y)
= no
-func test_text():
+func test_text()
>> b := @CorecursiveB()
>> a := @CorecursiveA(b)
>> b.other = a
>> a
# = @CorecursiveA(@CorecursiveB(@~1))
-func main():
+func main()
test_literals()
test_metamethods()
test_mixed()
diff --git a/test/tables.tm b/test/tables.tm
index a5f51520..67299142 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -1,4 +1,4 @@
-func main():
+func main()
>> t := {"one"=1, "two"=2}
= {"one"=1, "two"=2}
@@ -14,7 +14,7 @@ func main():
= -1
t_str := ""
- for k,v in t:
+ for k,v in t
t_str ++= "($k=$v)"
>> t_str
= "(one=1)(two=2)"
@@ -45,7 +45,7 @@ func main():
= {"one"=1, "two"=2}?
t2_str := ""
- for k,v in t2:
+ for k,v in t2
t2_str ++= "($k=$v)"
>> t2_str
= "(three=3)"
@@ -62,7 +62,7 @@ func main():
>> t3
= @{1=10, 2=20}
- do:
+ do
>> plain := {1=10, 2=20, 3=30}
>> plain[2]!
= 20
@@ -81,14 +81,14 @@ func main():
>> fallback[1] or -999
= 10
- do:
+ do
>> t4 := &{"one"= 1}
>> t4["one"] = 999
>> t4["two"] = 222
>> t4
= &{"one"=999, "two"=222}
- do:
+ do
>> {1=1, 2=2} == {2=2, 1=1}
= yes
>> {1=1, 2=2} == {1=1, 2=999}
@@ -102,7 +102,7 @@ func main():
>> other_ints : [{Int}] = [{/}, {1}, {2}, {99}, {0, 3}, {1, 2}, {99}].sorted()
= [{/}, {0, 3}, {1}, {1, 2}, {2}, {99}, {99}]
- do:
+ do
# Default values:
counter := &{"x"=10; default=0}
>> counter["x"]
diff --git a/test/text.tm b/test/text.tm
index b353aa26..1cabbdea 100644
--- a/test/text.tm
+++ b/test/text.tm
@@ -1,4 +1,4 @@
-func main():
+func main()
str := "Hello Amélie!"
say("Testing strings like $str")
@@ -236,7 +236,7 @@ func main():
>> ("hello" ++ " " ++ "Amélie").reversed()
= "eilémA olleh"
- do:
+ do
say("Testing concatenation-stability:")
ab := Text.from_codepoint_names(["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"])!
>> ab.codepoint_names()
@@ -254,7 +254,7 @@ func main():
= 1
- do:
+ do
concat := "e" ++ Text.from_codepoints([Int32(0x300)])
>> concat.length
= 1
diff --git a/test/use_import.tm b/test/use_import.tm
index 714c26b0..a56d9cbb 100644
--- a/test/use_import.tm
+++ b/test/use_import.tm
@@ -2,8 +2,8 @@ struct ImportedType(name:Text)
needs_initializing := 999999999999999999
-func get_value(->ImportedType):
+func get_value(->ImportedType)
return ImportedType("Hello")
-func main():
+func main()
pass
diff --git a/test/when.tm b/test/when.tm
index d93745dd..28573d88 100644
--- a/test/when.tm
+++ b/test/when.tm
@@ -1,13 +1,13 @@
# Tests for the 'when' block
-func main():
+func main()
answers := [
(
- when x is "A","B":
+ when x is "A","B"
"A or B"
- is "C":
+ is "C"
"C"
- else:
+ else
"Other"
) for x in ["A", "B", "C", "D"]
]
@@ -15,7 +15,7 @@ func main():
= ["A or B", "A or B", "C", "Other"]
n := 23
- >> when n is 1: Int64(1)
- is 2: Int64(2)
- is 21 + 2: Int64(23)
+ >> when n is 1 Int64(1)
+ is 2 Int64(2)
+ is 21 + 2 Int64(23)
= Int64(23)?