aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compile/assertions.c7
-rw-r--r--src/compile/comparisons.c5
-rw-r--r--src/environment.c4
-rw-r--r--src/parse/statements.c2
-rw-r--r--src/typecheck.c2
-rw-r--r--test/bytes.tm27
-rw-r--r--test/corecursive_func.tm3
-rw-r--r--test/defer.tm15
-rw-r--r--test/enums.tm68
-rw-r--r--test/for.tm21
-rw-r--r--test/functions.tm3
-rw-r--r--test/import.tm9
-rw-r--r--test/inline_c.tm3
-rw-r--r--test/integers.tm150
-rw-r--r--test/iterators.tm16
-rw-r--r--test/lambdas.tm18
-rw-r--r--test/lang.tm31
-rw-r--r--test/lists.tm157
-rw-r--r--test/metamethods.tm45
-rw-r--r--test/minmax.tm22
-rw-r--r--test/nums.tm53
-rw-r--r--test/optionals.tm171
-rw-r--r--test/paths.tm127
-rw-r--r--test/reductions.tm54
-rw-r--r--test/serialization.tm3
-rw-r--r--test/structs.tm40
-rw-r--r--test/tables.tm126
-rw-r--r--test/text.tm383
-rw-r--r--test/when.tm12
29 files changed, 569 insertions, 1008 deletions
diff --git a/src/compile/assertions.c b/src/compile/assertions.c
index 3ea6bf1e..5746b21e 100644
--- a/src/compile/assertions.c
+++ b/src/compile/assertions.c
@@ -4,7 +4,6 @@
#include "../config.h"
#include "../environment.h"
#include "../stdlib/datatypes.h"
-#include "../stdlib/print.h"
#include "../stdlib/text.h"
#include "../stdlib/util.h"
#include "../typecheck.h"
@@ -17,7 +16,7 @@ Text_t compile_assertion(env_t *env, ast_t *ast) {
const char *failure = NULL;
switch (expr->tag) {
case And: {
- DeclareMatch(and_, ast, And);
+ DeclareMatch(and_, expr, And);
return Texts(compile_statement(env, WrapAST(ast, Assert, .expr = and_->lhs, .message = message)),
compile_statement(env, WrapAST(ast, Assert, .expr = and_->rhs, .message = message)));
}
@@ -32,13 +31,13 @@ Text_t compile_assertion(env_t *env, ast_t *ast) {
assert_comparison: {
binary_operands_t cmp = BINARY_OPERANDS(expr);
type_t *lhs_t = get_type(env, cmp.lhs);
- type_t *rhs_t = get_type(env, cmp.rhs);
+ type_t *rhs_t = get_type(with_enum_scope(env, lhs_t), cmp.rhs);
type_t *operand_t;
if (cmp.lhs->tag == Int && is_numeric_type(rhs_t)) {
operand_t = rhs_t;
} else if (cmp.rhs->tag == Int && is_numeric_type(lhs_t)) {
operand_t = lhs_t;
- } else if (can_compile_to_type(env, cmp.rhs, lhs_t)) {
+ } else if (can_compile_to_type(with_enum_scope(env, lhs_t), cmp.rhs, lhs_t)) {
operand_t = lhs_t;
} else if (can_compile_to_type(env, cmp.lhs, rhs_t)) {
operand_t = rhs_t;
diff --git a/src/compile/comparisons.c b/src/compile/comparisons.c
index 0f9a7ddd..ffa04b9d 100644
--- a/src/compile/comparisons.c
+++ b/src/compile/comparisons.c
@@ -20,20 +20,19 @@ static CONSTFUNC const char *comparison_operator(ast_e tag) {
}
Text_t compile_comparison(env_t *env, ast_t *ast) {
-
switch (ast->tag) {
case Equals:
case NotEquals: {
binary_operands_t binop = BINARY_OPERANDS(ast);
type_t *lhs_t = get_type(env, binop.lhs);
- type_t *rhs_t = get_type(env, binop.rhs);
+ type_t *rhs_t = get_type(with_enum_scope(env, lhs_t), binop.rhs);
type_t *operand_t;
if (binop.lhs->tag == Int && is_numeric_type(rhs_t)) {
operand_t = rhs_t;
} else if (binop.rhs->tag == Int && is_numeric_type(lhs_t)) {
operand_t = lhs_t;
- } else if (can_compile_to_type(env, binop.rhs, lhs_t)) {
+ } else if (can_compile_to_type(with_enum_scope(env, lhs_t), binop.rhs, lhs_t)) {
operand_t = lhs_t;
} else if (can_compile_to_type(env, binop.lhs, rhs_t)) {
operand_t = rhs_t;
diff --git a/src/environment.c b/src/environment.c
index 603a04d9..ccbe4a8f 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -573,10 +573,10 @@ env_t *fresh_scope(env_t *env) {
}
env_t *with_enum_scope(env_t *env, type_t *t) {
- while (t->tag == OptionalType)
+ while (t && t->tag == OptionalType)
t = Match(t, OptionalType)->type;
- if (t->tag != EnumType) return env;
+ if (t == NULL || t->tag != EnumType) return env;
env = fresh_scope(env);
env_t *ns_env = Match(t, EnumType)->env;
for (tag_t *tag = Match(t, EnumType)->tags; tag; tag = tag->next) {
diff --git a/src/parse/statements.c b/src/parse/statements.c
index c767ae0b..24917a76 100644
--- a/src/parse/statements.c
+++ b/src/parse/statements.c
@@ -111,7 +111,7 @@ ast_t *parse_debug_log(parse_ctx_t *ctx, const char *pos) {
spaces(&pos);
}
REVERSE_LIST(values);
- whitespace(ctx, &pos);
+ // whitespace(ctx, &pos);
return NewAST(ctx->file, start, pos, DebugLog, .values = values);
}
diff --git a/src/typecheck.c b/src/typecheck.c
index 308ed259..57a1b994 100644
--- a/src/typecheck.c
+++ b/src/typecheck.c
@@ -354,7 +354,7 @@ void bind_statement(env_t *env, ast_t *statement) {
switch (statement->tag) {
case DebugLog: {
for (ast_list_t *value = Match(statement, DebugLog)->values; value; value = value->next)
- prebind_statement(env, value->ast);
+ bind_statement(env, value->ast);
break;
}
case Assert: {
diff --git a/test/bytes.tm b/test/bytes.tm
index a207c633..b137aeb6 100644
--- a/test/bytes.tm
+++ b/test/bytes.tm
@@ -1,25 +1,16 @@
func main()
say("Test bytes:")
- >> Byte(100)
- = Byte(0x64)
+ assert Byte(100) == Byte(0x64)
- >> Byte(0xFF)
- = Byte(0xFF)
+ assert Byte(0xFF) == Byte(0xFF)
>> b := Byte(0x0F)
- >> b.hex()
- = "0F"
- >> b.hex(prefix=yes)
- = "0x0F"
- >> b.hex(uppercase=no)
- = "0f"
+ assert b.hex() == "0F"
+ assert b.hex(prefix=yes) == "0x0F"
+ assert b.hex(uppercase=no) == "0f"
- >> Byte(0x06).get_bit(1)
- = no
- >> Byte(0x06).get_bit(2)
- = yes
- >> Byte(0x06).get_bit(3)
- = yes
- >> Byte(0x06).get_bit(4)
- = no
+ assert Byte(0x06).get_bit(1) == no
+ assert Byte(0x06).get_bit(2) == yes
+ assert Byte(0x06).get_bit(3) == yes
+ assert Byte(0x06).get_bit(4) == no
diff --git a/test/corecursive_func.tm b/test/corecursive_func.tm
index 8faf8b0d..261b6319 100644
--- a/test/corecursive_func.tm
+++ b/test/corecursive_func.tm
@@ -11,5 +11,4 @@ func pong(x:Int->[Text])
return ["pong: $x"]
func main()
- >> ping(3)
- = ["ping: 3", "pong: 2", "ping: 1", "pong: 0"]
+ assert ping(3) == ["ping: 3", "pong: 2", "ping: 1", "pong: 0"]
diff --git a/test/defer.tm b/test/defer.tm
index 8cab3122..8f0cb3be 100644
--- a/test/defer.tm
+++ b/test/defer.tm
@@ -6,10 +6,8 @@ func main()
nums.insert(x)
x = 999
- >> nums[]
- = [123]
- >> x
- = 999
+ assert nums[] == [123]
+ assert x == 999
defer
say("All done!")
@@ -58,12 +56,9 @@ func main()
>> defer_func(no)
>> counter := make_counter()
- >> counter()
- = 1
- >> counter()
- = 2
- >> counter()
- = 3
+ assert counter() == 1
+ assert counter() == 2
+ assert counter() == 3
func defer_func(return_early=no)
say("Entering defer_func")
diff --git a/test/enums.tm b/test/enums.tm
index 0cef37cf..f12b3d79 100644
--- a/test/enums.tm
+++ b/test/enums.tm
@@ -29,48 +29,33 @@ func enum_return_function(i:Int -> enum(Zero, One, Many))
struct EnumFields(x:enum(A, B, C))
func main()
- >> Foo.Zero
- = Foo.Zero
- >> Foo.One(123)
- = Foo.One(123)
- >> Foo.Two(123, 456)
- = Foo.Two(x=123, y=456)
+ assert Foo.Zero == Foo.Zero
+ assert Foo.One(123) == Foo.One(123)
+ assert Foo.Two(123, 456) == Foo.Two(x=123, y=456)
>> one := Foo.One(123)
- >> one.One
- = yes
- >> one.Two
- = no
+ assert one.One == yes
+ assert one.Two == no
assert Foo.One(10) == Foo.One(10)
- >> Foo.One(10) == Foo.Zero
- = no
+ assert Foo.One(10) == Foo.Zero == no
- >> Foo.One(10) == Foo.One(-1)
- = no
+ assert Foo.One(10) == Foo.One(-1) == no
assert Foo.One(10) < Foo.Two(1, 2)
>> x := Foo.One(123)
>> t := {x=yes}
- >> t.has(x)
- = yes
- >> t.has(Foo.Zero)
- = no
-
- >> choose_text(Foo.Zero)
- = "Zero"
- >> choose_text(Foo.One(123))
- = "One: 123"
- >> choose_text(Foo.Two(123, 456))
- = "Two: x=123, y=456"
- >> choose_text(Foo.Three(123, "hi", yes))
- = 'Three: Three(x=123, y="hi", z=yes)'
- >> choose_text(Foo.Four(1,2,3,4))
- = "Four"
- >> choose_text(Foo.Last("XX"))
- = 'else: Last("XX")'
+ assert t.has(x) == yes
+ assert t.has(Foo.Zero) == no
+
+ assert choose_text(Foo.Zero) == "Zero"
+ assert choose_text(Foo.One(123)) == "One: 123"
+ assert choose_text(Foo.Two(123, 456)) == "Two: x=123, y=456"
+ assert choose_text(Foo.Three(123, "hi", yes)) == 'Three: Three(x=123, y="hi", z=yes)'
+ assert choose_text(Foo.Four(1,2,3,4)) == "Four"
+ assert choose_text(Foo.Last("XX")) == 'else: Last("XX")'
i := 1
cases := [Foo.One(1), Foo.One(2), Foo.Zero]
@@ -79,7 +64,7 @@ func main()
i += 1
else stop
- >> [
+ assert [
(
when x is One(y), Two(y,_)
"Small $y"
@@ -88,14 +73,13 @@ func main()
else
"Other"
) for x in [Foo.Zero, Foo.One(1), Foo.Two(2,2), Foo.Three(3,"",no)]
- ]
- = ["Zero", "Small 1", "Small 2", "Other"]
+ ] == ["Zero", "Small 1", "Small 2", "Other"]
- >> expr := when cases[1]! is One(y)
+ expr := when cases[1]! is One(y)
y + 1
else
-1
- = 2
+ assert expr == 2
>> enum_arg_function(Zero)
>> enum_arg_function(Two(2,3))
@@ -109,13 +93,9 @@ func main()
is Two
say("two")
- >> enum_return_function(0)
- = Zero
- >> enum_return_function(1)
- = One
- >> enum_return_function(2)
- = Many
+ assert enum_return_function(0) == Zero
+ assert enum_return_function(1) == One
+ assert enum_return_function(2) == Many
- >> EnumFields(A)
- = EnumFields(x=A)
+ assert EnumFields(A) == EnumFields(x=A)
diff --git a/test/for.tm b/test/for.tm
index 75ad2fee..3598df85 100644
--- a/test/for.tm
+++ b/test/for.tm
@@ -30,21 +30,14 @@ func table_key_str(t:{Text=Text} -> Text)
return str
func main()
- >> all_nums([10,20,30])
- = "10,20,30,"
- >> all_nums([])
- = "EMPTY"
+ assert all_nums([10,20,30]) == "10,20,30,"
+ assert all_nums([]) == "EMPTY"
- >> labeled_nums([10,20,30])
- = "1:10,2:20,3:30,"
- >> labeled_nums([])
- = "EMPTY"
+ assert labeled_nums([10,20,30]) == "1:10,2:20,3:30,"
+ assert labeled_nums([]) == "EMPTY"
>> t := {"key1"="value1", "key2"="value2"}
- >> table_str(t)
- = "key1:value1,key2:value2,"
- >> table_str({})
- = "EMPTY"
+ assert table_str(t) == "key1:value1,key2:value2,"
+ assert table_str({}) == "EMPTY"
- >> table_key_str(t)
- = "key1,key2,"
+ assert table_key_str(t) == "key1,key2,"
diff --git a/test/functions.tm b/test/functions.tm
index 7ceca977..e2e35bf8 100644
--- a/test/functions.tm
+++ b/test/functions.tm
@@ -5,8 +5,7 @@ func cached_heap(x:Int->@Int; cached)
return @x
func main()
- >> add(3, 5)
- = 8
+ assert add(3, 5) == 8
assert cached_heap(1) == cached_heap(1)
assert cached_heap(1) != cached_heap(2)
diff --git a/test/import.tm b/test/import.tm
index edae08f6..cb642ac6 100644
--- a/test/import.tm
+++ b/test/import.tm
@@ -9,12 +9,9 @@ func returns_imported_type(->ImportedType)
func main()
>> empty : [vectors.Vec2]
- >> returns_vec()
- = Vec2(x=1, y=2)
+ assert returns_vec() == Vec2(x=1, y=2)
>> imported : [ImportedType]
- >> returns_imported_type()
- = ImportedType("Hello")
+ assert returns_imported_type() == ImportedType("Hello")
- >> needs_initializing # imported from ./use_import.tm
- = 999999999999999999
+ assert needs_initializing == 999999999999999999
diff --git a/test/inline_c.tm b/test/inline_c.tm
index a9a7d6fc..79e8a97d 100644
--- a/test/inline_c.tm
+++ b/test/inline_c.tm
@@ -1,7 +1,6 @@
func main()
- >> C_code:Int32`int x = 1 + 2; x`
- = Int32(3)
+ assert C_code:Int32`int x = 1 + 2; x` == Int32(3)
>> C_code `
say(Text("Inline C code works!"), true);
diff --git a/test/integers.tm b/test/integers.tm
index ee560952..d6e68066 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -7,11 +7,9 @@ func main()
assert 2 * 3 + 4 == 10
- >> Int8(1) + Int16(2)
- = Int16(3)
+ assert Int8(1) + Int16(2) == Int16(3)
- >> 1 << 10
- = 1024
+ assert 1 << 10 == 1024
# say("Signed and unsigned bit shifting:")
# >> Int64(-2) << 1
@@ -23,62 +21,46 @@ func main()
# >> Int64(-2) >>> 1
# = Int64(9223372036854775807)
- >> 3 and 2
- = 2
+ assert (3 and 2) == 2
- >> 3 or 4
- = 7
+ assert (3 or 4) == 7
- >> 3 xor 2
- = 1
+ assert (3 xor 2) == 1
nums := ""
for x in 5
nums ++= "$x,"
- >> nums
- = "1,2,3,4,5,"
+ assert nums == "1,2,3,4,5,"
>> x := Int64(123)
- >> x.hex()
- = "0x7B"
- >> x.hex(digits=4)
- = "0x007B"
- >> x.octal()
- = "0o173"
+ assert x.hex() == "0x7B"
+ assert x.hex(digits=4) == "0x007B"
+ assert x.octal() == "0o173"
- >> Int64.min
- = Int64(-9223372036854775808)
- >> Int64.max
- = Int64(9223372036854775807)
+ assert Int64.min == Int64(-9223372036854775808)
+ assert Int64.max == Int64(9223372036854775807)
- >> Int32(123).hex()
- = "0x7B"
- >> Int16(123).hex()
- = "0x7B"
- >> Int8(123).hex()
- = "0x7B"
+ assert Int32(123).hex() == "0x7B"
+ assert Int16(123).hex() == "0x7B"
+ assert Int8(123).hex() == "0x7B"
- >> Int(2.1, truncate=yes)
- = 2
+ assert Int(2.1, truncate=yes) == 2
do
- >> small_int := 1
- = 1
- >> max_small_int := 536870911
- = 536870911
- >> max_i64 := 536870912
- = 536870912
- >> super_big := 9999999999999999999999
- = 9999999999999999999999
- >> max_small_int + 1
- = 536870912
-
- >> max_small_int + max_small_int
- = 1073741822
-
- >> super_big + 1
- = 10000000000000000000000
+ small_int := 1
+ assert small_int == 1
+ max_small_int := 536870911
+ assert max_small_int == 536870911
+ max_i64 := 536870912
+ assert max_i64 == 536870912
+ super_big := 9999999999999999999999
+ assert super_big == 9999999999999999999999
+ assert max_small_int + 1 == 536870912
+
+ assert max_small_int + max_small_int == 1073741822
+
+ assert super_big + 1 == 10000000000000000000000
do
interesting_numerators := [-999999, -100, -23, -1, 0, 1, 23, 100, 999999]
@@ -87,10 +69,8 @@ func main()
for d in interesting_denominators
assert (n/d)*d + (n mod d) == n
- >> (0).next_prime()
- = 2
- >> (7).next_prime()
- = 11
+ assert (0).next_prime() == 2
+ assert (7).next_prime() == 11
#>> (11).prev_prime()
#= 7
assert (and: p.is_prime() for p in [
@@ -107,51 +87,33 @@ func main()
771958616175795150904761471637,
])!
- >> (or: p.is_prime() for p in [
+ assert (or: p.is_prime() for p in [
-1, 0, 1, 4, 6,
137372146048179869781170214707*2,
811418847921670560768224995279*3,
292590241572454328697048860273*754893741683930091960170890717,
- ])!
- = no
-
- >> Int(yes)
- = 1
- >> Int(no)
- = 0
-
- >> Int64(yes)
- = Int64(1)
- >> Int64(no)
- = Int64(0)
-
- >> (4).choose(2)
- = 6
-
- >> (4).factorial()
- = 24
-
- >> (3).is_between(1, 5)
- = yes
- >> (3).is_between(1, 3)
- = yes
- >> (3).is_between(100, 200)
- = no
-
- >> (6).get_bit(1)
- = no
- >> (6).get_bit(2)
- = yes
- >> (6).get_bit(3)
- = yes
- >> (6).get_bit(4)
- = no
-
- >> Int64(6).get_bit(1)
- = no
- >> Int64(6).get_bit(2)
- = yes
- >> Int64(6).get_bit(3)
- = yes
- >> Int64(6).get_bit(4)
- = no
+ ])! == no
+
+ assert Int(yes) == 1
+ assert Int(no) == 0
+
+ assert Int64(yes) == Int64(1)
+ assert Int64(no) == Int64(0)
+
+ assert (4).choose(2) == 6
+
+ assert (4).factorial() == 24
+
+ assert (3).is_between(1, 5) == yes
+ assert (3).is_between(1, 3) == yes
+ assert (3).is_between(100, 200) == no
+
+ assert (6).get_bit(1) == no
+ assert (6).get_bit(2) == yes
+ assert (6).get_bit(3) == yes
+ assert (6).get_bit(4) == no
+
+ assert Int64(6).get_bit(1) == no
+ assert Int64(6).get_bit(2) == yes
+ assert Int64(6).get_bit(3) == yes
+ assert Int64(6).get_bit(4) == no
diff --git a/test/iterators.tm b/test/iterators.tm
index ed08f73d..7b4fe1f6 100644
--- a/test/iterators.tm
+++ b/test/iterators.tm
@@ -18,20 +18,16 @@ func range(first:Int, last:Int -> func(->Int?))
func main()
values := ["A", "B", "C", "D"]
- >> (++: "($(foo.x)$(foo.y))" for foo in pairwise(values))!
- = "(AB)(BC)(CD)"
- >> ["$(foo.x)$(foo.y)" for foo in pairwise(values)]
- = ["AB", "BC", "CD"]
+ assert (++: "($(foo.x)$(foo.y))" for foo in pairwise(values))! == "(AB)(BC)(CD)"
+ assert ["$(foo.x)$(foo.y)" for foo in pairwise(values)] == ["AB", "BC", "CD"]
do
result : @[Text]
for foo in pairwise(values)
result.insert("$(foo.x)$(foo.y)")
- >> result[]
- = ["AB", "BC", "CD"]
+ assert result[] == ["AB", "BC", "CD"]
- >> [i for i in range(5, 10)]
- = [5, 6, 7, 8, 9, 10]
+ assert [i for i in range(5, 10)] == [5, 6, 7, 8, 9, 10]
+
+ assert (+: range(5, 10))! == 45
- >> (+: range(5, 10))!
- = 45
diff --git a/test/lambdas.tm b/test/lambdas.tm
index d6501cb7..1d1b2775 100644
--- a/test/lambdas.tm
+++ b/test/lambdas.tm
@@ -9,27 +9,22 @@ func mul_func(n:Int, fn:func(x:Int->Int) -> func(x:Int->Int))
func main()
>> add_one := func(x:Int) x + 1
- >> add_one(10)
- = 11
+ assert add_one(10) == 11
>> shout := func(msg:Text) say("$(msg.upper())!")
>> shout("hello")
>> asdf := add_one
- >> asdf(99)
- = 100
+ assert asdf(99) == 100
>> add_100 := make_adder(100)
- >> add_100(5)
- = 105
+ assert add_100(5) == 105
>> shout2 := suffix_fn(func(t:Text) t.upper(), "!")
- >> shout2("hello")
- = "HELLO!"
+ assert shout2("hello") == "HELLO!"
>> abs100 := mul_func(100, Int.abs)
- >> abs100(-5)
- = 500
+ assert abs100(-5) == 500
# Test nested lambdas:
outer := "Hello"
@@ -38,5 +33,4 @@ func main()
return func()
defer say("$outer")
return outer
- >> fn()()()
- = "Hello"
+ assert fn()()() == "Hello"
diff --git a/test/lang.tm b/test/lang.tm
index 21b70f96..9db69dbe 100644
--- a/test/lang.tm
+++ b/test/lang.tm
@@ -22,34 +22,25 @@ struct Bold(text:Text)
return $HTML"<b>$(b.text)</b>"
func main()
- >> HTML.HEADER
- = $HTML"<!DOCTYPE HTML>"
+ assert HTML.HEADER == $HTML"<!DOCTYPE HTML>"
- >> HTML.HEADER[1]
- = $HTML"<"
+ assert HTML.HEADER[1] == $HTML"<"
- >> HTML.HEADER.text
- = "<!DOCTYPE HTML>"
+ assert HTML.HEADER.text == "<!DOCTYPE HTML>"
>> user := "I <3 hax"
- >> html := $HTML"Hello $user!"
- = $HTML"Hello I &lt;3 hax!"
- >> html ++ $HTML"<br>"
- = $HTML"Hello I &lt;3 hax!<br>"
+ html := $HTML"Hello $user!"
+ assert html == $HTML"Hello I &lt;3 hax!"
+ assert html ++ $HTML"<br>" == $HTML"Hello I &lt;3 hax!<br>"
- >> $HTML"$(1 + 2)"
- = $HTML"3"
+ assert $HTML"$(1 + 2)" == $HTML"3"
- >> $HTML"$(Int8(3))"
- = $HTML"3"
+ assert $HTML"$(Int8(3))" == $HTML"3"
- >> html.paragraph()
- = $HTML"<p>Hello I &lt;3 hax!</p>"
+ assert html.paragraph() == $HTML"<p>Hello I &lt;3 hax!</p>"
- >> Text(html)
- = '\$HTML"Hello I &lt;3 hax!"'
+ assert Text(html) == '\$HTML"Hello I &lt;3 hax!"'
>> b := Bold("Some <text> with junk")
- >> $HTML"Your text: $b"
- = $HTML"Your text: <b>Some &lt;text&gt; with junk</b>"
+ assert $HTML"Your text: $b" == $HTML"Your text: <b>Some &lt;text&gt; with junk</b>"
diff --git a/test/lists.tm b/test/lists.tm
index 2342c570..176c3d6d 100644
--- a/test/lists.tm
+++ b/test/lists.tm
@@ -1,106 +1,85 @@
func main()
do
- >> nums : [Num32] = []
- = []
+ nums : [Num32] = []
+ assert nums == []
do
- >> nums : [Num32]
- = []
+ nums : [Num32]
+ assert nums == []
do
- >> list := [10, 20, 30]
- = [10, 20, 30]
+ list := [10, 20, 30]
+ assert list == [10, 20, 30]
- >> list[1]
- = 10
- >> list[-1]
- = 30
+ assert list[1] == 10
+ assert list[-1] == 30
- >> list.length
- = 3
+ assert list.length == 3
sum := 0
for x in list
sum += x
- >> sum
- = 60
+ assert sum == 60
str := ""
for i,x in list
str ++= "($i,$x)"
- >> str
- = "(1,10)(2,20)(3,30)"
+ assert str == "(1,10)(2,20)(3,30)"
do
- >> list := [10, 20] ++ [30, 40]
- = [10, 20, 30, 40]
+ list := [10, 20] ++ [30, 40]
+ assert list == [10, 20, 30, 40]
>> list ++= [50, 60]
- >> list
- = [10, 20, 30, 40, 50, 60]
+ assert list == [10, 20, 30, 40, 50, 60]
do
>> list := [10, 20]
>> copy := list
>> list ++= [30]
- >> list
- = [10, 20, 30]
- >> copy
- = [10, 20]
+ assert list == [10, 20, 30]
+ assert copy == [10, 20]
do
- >> [10*i for i in 5]
- = [10, 20, 30, 40, 50]
+ assert [10*i for i in 5] == [10, 20, 30, 40, 50]
- >> [i*10 for i in 5]
- = [10, 20, 30, 40, 50]
+ assert [i*10 for i in 5] == [10, 20, 30, 40, 50]
- >> [i*10 for i in 5 if i mod 2 != 0]
- = [10, 30, 50]
+ assert [i*10 for i in 5 if i mod 2 != 0] == [10, 30, 50]
- >> [x for x in y if x > 1 for y in [3, 4, 5] if y < 5]
- = [2, 3, 2, 3, 4]
+ assert [x for x in y if x > 1 for y in [3, 4, 5] if y < 5] == [2, 3, 2, 3, 4]
do
>> list := @[10, 20]
>> copy := list[]
>> list.insert(30)
- >> list[]
- = [10, 20, 30]
- >> copy
- = [10, 20]
+ assert list[] == [10, 20, 30]
+ assert copy == [10, 20]
>> list[1] = 999
- >> list[]
- = [999, 20, 30]
+ assert list[] == [999, 20, 30]
do
>> list := &[10, 20, 30]
- >> reversed := list.reversed()
- = [30, 20, 10]
+ reversed := list.reversed()
+ assert reversed == [30, 20, 10]
# Ensure the copy-on-write behavior triggers:
>> list[1] = 999
- >> reversed
- = [30, 20, 10]
+ assert reversed == [30, 20, 10]
do
>> nums := @[10, -20, 30]
# Sorted function doesn't mutate original:
- >> nums.sorted()
- = [-20, 10, 30]
- >> nums[]
- = [10, -20, 30]
+ assert nums.sorted() == [-20, 10, 30]
+ assert nums[] == [10, -20, 30]
# Sort function does mutate in place:
>> nums.sort()
- >> nums[]
- = [-20, 10, 30]
+ assert nums[] == [-20, 10, 30]
# Custom sort functions:
>> nums.sort(func(x,y:&Int) x.abs() <> y.abs())
- >> nums[]
- = [10, -20, 30]
+ assert nums[] == [10, -20, 30]
>> nums.sort(func(x,y:&Int) y[] <> x[])
- >> nums[]
- = [30, 10, -20]
+ assert nums[] == [30, 10, -20]
>> ["A", "B", "C"].sample(10, [1.0, 0.5, 0.0])
@@ -121,30 +100,20 @@ func main()
assert heap_order[] == heap_order.sorted()
do
- >> [i*10 for i in 5].from(3)
- = [30, 40, 50]
- >> [i*10 for i in 5].to(3)
- = [10, 20, 30]
- >> [i*10 for i in 5].to(-2)
- = [10, 20, 30, 40]
- >> [i*10 for i in 5].from(-2)
- = [40, 50]
-
- >> [i*10 for i in 5].by(2)
- = [10, 30, 50]
- >> [i*10 for i in 5].by(-1)
- = [50, 40, 30, 20, 10]
-
- >> [10, 20, 30, 40].by(2)
- = [10, 30]
- >> [10, 20, 30, 40].by(-2)
- = [40, 20]
-
- >> [i*10 for i in 10].by(2).by(2)
- = [10, 50, 90]
-
- >> [i*10 for i in 10].by(2).by(-1)
- = [90, 70, 50, 30, 10]
+ assert [i*10 for i in 5].from(3) == [30, 40, 50]
+ assert [i*10 for i in 5].to(3) == [10, 20, 30]
+ assert [i*10 for i in 5].to(-2) == [10, 20, 30, 40]
+ assert [i*10 for i in 5].from(-2) == [40, 50]
+
+ assert [i*10 for i in 5].by(2) == [10, 30, 50]
+ assert [i*10 for i in 5].by(-1) == [50, 40, 30, 20, 10]
+
+ assert [10, 20, 30, 40].by(2) == [10, 30]
+ assert [10, 20, 30, 40].by(-2) == [40, 20]
+
+ assert [i*10 for i in 10].by(2).by(2) == [10, 50, 90]
+
+ assert [i*10 for i in 10].by(2).by(-1) == [90, 70, 50, 30, 10]
# Test iterating over list.from() and list.to()
xs := ["A", "B", "C", "D"]
@@ -155,36 +124,24 @@ func main()
do
>> nums := @[-7, -4, -1, 2, 5]
>> nums.sort()
- >> [nums.binary_search(i) for i in nums[]]
- = [1, 2, 3, 4, 5]
+ assert [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[]]
- = [1, 2, 3, 4, 5]
+ assert [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")
- = 2
- >> ["a", "b", "c"].find("XXX")
- = none
+ assert ["a", "b", "c"].find("b") == 2
+ assert ["a", "b", "c"].find("XXX") == none
- >> [10, 20].where(func(i:&Int) i.is_prime())
- = none
- >> [4, 5, 6].where(func(i:&Int) i.is_prime())
- = 2
+ assert [10, 20].where(func(i:&Int) i.is_prime()) == none
+ assert [4, 5, 6].where(func(i:&Int) i.is_prime()) == 2
do
>> nums := &[10, 20, 30, 40, 50]
- >> nums.pop()
- = 50
- >> nums[]
- = [10, 20, 30, 40]
- >> nums.pop(2)
- = 20
- >> nums[]
- = [10, 30, 40]
+ assert nums.pop() == 50
+ assert nums[] == [10, 20, 30, 40]
+ assert nums.pop(2) == 20
+ assert nums[] == [10, 30, 40]
>> nums.clear()
- >> nums[]
- = []
- >> nums.pop()
- = none
+ assert nums[] == []
+ assert nums.pop() == none
assert [1,2,1,2,3].unique() == [1,2,3]
diff --git a/test/metamethods.tm b/test/metamethods.tm
index 9399bc9a..91f79f91 100644
--- a/test/metamethods.tm
+++ b/test/metamethods.tm
@@ -47,44 +47,31 @@ struct Vec2(x,y:Int)
func main()
>> x := Vec2(10, 20)
>> y := Vec2(100, 200)
- >> x + y
- = Vec2(x=110, y=220)
- >> x - y
- = Vec2(x=-90, y=-180)
- >> x * y
- = Vec2(x=1000, y=4000)
- >> x.dot(y)
- = 5000
- >> x * -1
- = Vec2(x=-10, y=-20)
- >> -10 * x
- = Vec2(x=-100, y=-200)
+ assert x + y == Vec2(x=110, y=220)
+ assert x - y == Vec2(x=-90, y=-180)
+ assert x * y == Vec2(x=1000, y=4000)
+ assert x.dot(y) == 5000
+ assert x * -1 == Vec2(x=-10, y=-20)
+ assert -10 * x == Vec2(x=-100, y=-200)
>> x = Vec2(1, 2)
>> x += Vec2(10, 20)
- = Vec2(x=11, y=22)
+ assert x == Vec2(x=11, y=22)
>> x *= Vec2(10, -1)
- = Vec2(x=110, y=-22)
+ assert x == Vec2(x=110, y=-22)
>> x *= -1
- = Vec2(x=-110, y=22)
+ assert x == Vec2(x=-110, y=22)
>> x = Vec2(1, 2)
- >> -x
- = Vec2(x=-1, y=-2)
+ assert -x == Vec2(x=-1, y=-2)
x = Vec2(1, 2)
y = Vec2(4, 3)
- >> x and y
- = Vec2(x=0, y=2)
- >> x or y
- = Vec2(x=5, y=3)
- >> x xor y
- = Vec2(x=5, y=1)
- >> x / 2
- = Vec2(x=0, y=1)
- >> x mod 3
- = Vec2(x=1, y=2)
- >> x mod1 3
- = Vec2(x=1, y=2)
+ assert (x and y) == Vec2(x=0, y=2)
+ assert (x or y) == Vec2(x=5, y=3)
+ assert (x xor y) == Vec2(x=5, y=1)
+ assert x / 2 == Vec2(x=0, y=1)
+ assert x mod 3 == Vec2(x=1, y=2)
+ assert x mod1 3 == Vec2(x=1, y=2)
diff --git a/test/minmax.tm b/test/minmax.tm
index 8ffb401e..038f03e4 100644
--- a/test/minmax.tm
+++ b/test/minmax.tm
@@ -4,24 +4,16 @@ struct Foo(x:Int, y:Int)
return Num.sqrt(Num(f.x*f.x + f.y*f.y))!
func main()
- >> 3 _min_ 5
- = 3
- >> 5 _min_ 3
- = 3
+ assert (3 _min_ 5) == 3
+ assert (5 _min_ 3) == 3
- >> Foo(5, 1) _min_ Foo(5, 999)
- = Foo(x=5, y=1)
+ assert (Foo(5, 1) _min_ Foo(5, 999)) == Foo(x=5, y=1)
- >> Foo(5, 999) _min_.x Foo(5, 1)
- = Foo(x=5, y=999)
+ assert (Foo(5, 999) _min_.x Foo(5, 1)) == Foo(x=5, y=999)
- >> Foo(999, 1) _min_.y Foo(1, 10)
- = Foo(x=999, y=1)
-
- >> Foo(-999, -999) _max_.len() Foo(10, 10)
- = Foo(x=-999, y=-999)
+ assert (Foo(999, 1) _min_.y Foo(1, 10)) == Foo(x=999, y=1)
+ assert (Foo(-999, -999) _max_.len() Foo(10, 10)) == Foo(x=-999, y=-999)
>> foos := [Foo(5, 1), Foo(5, 99), Foo(-999, -999)]
- >> (_max_: foos)!
- = Foo(x=5, y=99)
+ assert (_max_: foos)! == Foo(x=5, y=99)
diff --git a/test/nums.tm b/test/nums.tm
index 1ca09d7b..ef139d0d 100644
--- a/test/nums.tm
+++ b/test/nums.tm
@@ -1,40 +1,32 @@
func main()
- >> n := 1.5
- = 1.5
+ n := 1.5
+ assert n == 1.5
- >> n + n
- = 3.
+ assert n + n == 3.
- >> n * 2
- = 3.
+ assert n * 2 == 3.
- >> n - n
- = 0.
+ assert n - n == 0.
- >> Num.PI
- = 3.141592653589793
+ assert Num.PI == 3.141592653589793
- >> Num.PI.with_precision(0.01)
- = 3.14
+ assert Num.PI.with_precision(0.01) == 3.14
- >> Num.INF
- = Num.INF
+ assert Num.INF == Num.INF
assert Num.INF.isinf()
- >> none_num : Num? = none
- = none
+ none_num : Num? = none
+ assert none_num == none
assert none_num == none_num
assert (none_num < none_num) == no
assert (none_num > none_num) == no
assert (none_num != none_num) == no
- >> none_num <> none_num
- = Int32(0)
+ assert (none_num <> none_num) == Int32(0)
assert (none_num == 0.0) == no
assert none_num < 0.0
assert (none_num > 0.0) == no
assert none_num != 0.0
- >> none_num <> 0.0
- = Int32(-1)
+ assert (none_num <> 0.0) == Int32(-1)
# >> nan + 1
# = none
@@ -47,21 +39,14 @@ func main()
assert Num.PI.cos()!.near(-1)
assert Num.PI.sin()!.near(0)
- >> Num.INF.near(-Num.INF)
- = no
+ assert Num.INF.near(-Num.INF) == no
- >> Num32.sqrt(16)
- = Num32(4)
- >> Num32.sqrt(-1)
- = none
+ assert Num32.sqrt(16) == Num32(4)
+ assert Num32.sqrt(-1) == none
- >> (0.25).mix(10, 20)
- = 12.5
- >> (2.0).mix(10, 20)
- = 30.
+ assert (0.25).mix(10, 20) == 12.5
+ assert (2.0).mix(10, 20) == 30.
- >> Num(5)
- = 5.
+ assert Num(5) == 5.
- >> (0.5).percent()
- = "50%"
+ assert (0.5).percent() == "50%"
diff --git a/test/optionals.tm b/test/optionals.tm
index dcec904d..4528ee6c 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -62,38 +62,34 @@ func maybe_c_string(should_i:Bool->CString?)
return none
func main()
- >> optional : Int? = 5
- = 5
+ optional : Int? = 5
+ assert optional == 5
- >> if no
- x : Int? = none
- x
- else
- 5
- = 5
+ assert (
+ if no
+ x : Int? = none
+ x
+ else
+ 5
+ ) == 5
- >> optional or -1
- = 5
+ assert (optional or -1) == 5
- >> optional or fail("Non-none is falsey")
- = 5
+ assert (optional or fail("Non-none is falsey")) == 5
- >> optional or exit("Non-none is falsey")
- = 5
+ assert (optional or exit("Non-none is falsey")) == 5
>> none_int : Int? = none
- >> none_int or -1
- = -1
+ assert none_int or -1 == -1
do
say("Ints:")
- >> yep := maybe_int(yes)
- = 123
- >> nope := maybe_int(no)
- = none
+ yep := maybe_int(yes)
+ assert yep == 123
+ nope := maybe_int(no)
+ assert nope == none
>> if yep
- >> yep
- = 123
+ assert yep == 123
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -101,13 +97,12 @@ func main()
do
say("Int64s:")
- >> yep := maybe_int64(yes)
- = Int64(123)
- >> nope := maybe_int64(no)
- = none
+ yep := maybe_int64(yes)
+ assert yep == Int64(123)
+ nope := maybe_int64(no)
+ assert nope == none
>> if yep
- >> yep
- = Int64(123)
+ assert yep == Int64(123)
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -115,13 +110,12 @@ func main()
do
say("Lists:")
- >> yep := maybe_list(yes)
- = [10, 20, 30]
- >> nope := maybe_list(no)
- = none
+ yep := maybe_list(yes)
+ assert yep == [10, 20, 30]
+ nope := maybe_list(no)
+ assert nope == none
>> if yep
- >> yep
- = [10, 20, 30]
+ assert yep == [10, 20, 30]
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -130,13 +124,12 @@ func main()
do
say("...")
say("Bools:")
- >> yep := maybe_bool(yes)
- = no
- >> nope := maybe_bool(no)
- = none
+ yep := maybe_bool(yes)
+ assert yep == no
+ nope := maybe_bool(no)
+ assert nope == none
>> if yep
- >> yep
- = no
+ assert yep == no
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -145,13 +138,12 @@ func main()
do
say("...")
say("Text:")
- >> yep := maybe_text(yes)
- = "Hello"
- >> nope := maybe_text(no)
- = none
+ yep := maybe_text(yes)
+ assert yep == "Hello"
+ nope := maybe_text(no)
+ assert nope == none
>> if yep
- >> yep
- = "Hello"
+ assert yep == "Hello"
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -160,13 +152,12 @@ func main()
do
say("...")
say("Nums:")
- >> yep := maybe_num(yes)
- = 12.3
- >> nope := maybe_num(no)
- = none
+ yep := maybe_num(yes)
+ assert yep == 12.3
+ nope := maybe_num(no)
+ assert nope == none
>> if yep
- >> yep
- = 12.3
+ assert yep == 12.3
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -175,14 +166,8 @@ func main()
do
say("...")
say("Lambdas:")
- # >> yep := maybe_lambda(yes)
- # = func() [optionals.tm:54] : func()?
- >> nope := maybe_lambda(no)
- = none
- # >> if yep
- # >> yep
- # = func() [optionals.tm:54]
- # else fail("Falsey: $yep")
+ nope := maybe_lambda(no)
+ assert nope == none
>> if nope
fail("Truthy: $nope")
else say("Falsey: $nope")
@@ -190,13 +175,12 @@ func main()
do
say("...")
say("Structs:")
- >> yep := Struct.maybe(yes)
- = Struct(x=123, y="hello")
- >> nope := Struct.maybe(no)
- = none
+ yep := Struct.maybe(yes)
+ assert yep == Struct(x=123, y="hello")
+ nope := Struct.maybe(no)
+ assert nope == none
>> if yep
- >> yep
- = Struct(x=123, y="hello")
+ assert yep == Struct(x=123, y="hello")
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -205,13 +189,12 @@ func main()
do
say("...")
say("Enums:")
- >> yep := Enum.maybe(yes)
- = Enum.Y(123)
- >> nope := Enum.maybe(no)
- = none
+ yep := Enum.maybe(yes)
+ assert yep == Enum.Y(123)
+ nope := Enum.maybe(no)
+ assert nope == none
>> if yep
- >> yep
- = Enum.Y(123)
+ assert yep == Enum.Y(123)
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
@@ -220,48 +203,35 @@ func main()
do
say("...")
say("C Strings:")
- >> yep := maybe_c_string(yes)
- = CString("hi")
- >> nope := maybe_c_string(no)
- = none
+ yep := maybe_c_string(yes)
+ assert yep == CString("hi")
+ nope := maybe_c_string(no)
+ assert nope == none
>> if yep
- >> yep
- = CString("hi")
+ assert yep == CString("hi")
else fail("Falsey: $yep")
>> if nope
fail("Truthy: $nope")
else say("Falsey: $nope")
if yep := maybe_int(yes)
- >> yep
- = 123
+ assert yep == 123
else fail("Unreachable")
- >> maybe_int(yes)!
- = 123
+ assert maybe_int(yes)! == 123
# Test comparisons, hashing, equality:
assert none != optional
assert optional == 5
>> nones : {Int?=Bool} = {none=yes, none=yes}
- >> nones.keys
- = [none]
- >> [5, none, none, 6].sorted()
- = [none, none, 5, 6]
+ assert nones.keys == [none]
+ assert [5, none, none, 6].sorted() == [none, none, 5, 6]
do
- >> value := if var := optional
- var
- else
- 0
- = 5
+ assert (if var := optional then var else 0) == 5
do
- >> value := if var : Int? = none then
- var
- else
- 0
- = 0
+ assert (if var : Int? = none then var else 0) == 0
do
>> opt : Int? = 5
@@ -277,15 +247,12 @@ func main()
else
>> opt
- >> not optional
- = no
+ assert not optional == no
>> nah : Int? = none
- >> not nah
- = yes
+ assert not nah == yes
- >> [none, Struct(5,"A"), Struct(6,"B"), Struct(7,"C")]
- = [none, Struct(x=5, y="A"), Struct(x=6, y="B"), Struct(x=7, y="C")]
+ assert [none, Struct(5,"A"), Struct(6,"B"), Struct(7,"C")] == [none, Struct(x=5, y="A"), Struct(x=6, y="B"), Struct(x=7, y="C")]
if optional or no
say("Binary op 'or' works with optionals")
diff --git a/test/paths.tm b/test/paths.tm
index 22f79c7b..e72cddec 100644
--- a/test/paths.tm
+++ b/test/paths.tm
@@ -3,15 +3,12 @@ func main()
assert (/).exists()
assert (~/).exists()
- >> (~/Downloads/file(1).txt)
- = (~/Downloads/file(1).txt)
+ assert (~/Downloads/file(1).txt) == (~/Downloads/file(1).txt)
- >> (/half\)paren)
- = (/half\)paren)
+ assert (/half\)paren) == (/half\)paren)
>> filename := "example.txt"
- >> (~).child(filename)
- = (~/example.txt)
+ assert (~).child(filename) == (~/example.txt)
>> tmpdir := (/tmp/tomo-test-path-XXXXXX).unique_directory()
assert (/tmp).subdirectories().has(tmpdir)
@@ -19,22 +16,17 @@ func main()
>> tmpfile := (tmpdir++(./one.txt))
>> tmpfile.write("Hello world")
>> tmpfile.append("!")
- >> tmpfile.read()
- = "Hello world!"
- >> tmpfile.read_bytes()!
- = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21]
+ assert tmpfile.read() == "Hello world!"
+ assert tmpfile.read_bytes()! == [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21]
assert tmpdir.files().has(tmpfile)
if tmp_lines := tmpfile.by_line() then
- >> [line for line in tmp_lines]
- = ["Hello world!"]
+ assert [line for line in tmp_lines] == ["Hello world!"]
else
fail("Couldn't read lines in $tmpfile")
- >> (./does-not-exist.xxx).read()
- = none
- >> (./does-not-exist.xxx).read_bytes()
- = none
+ assert (./does-not-exist.xxx).read() == none
+ assert (./does-not-exist.xxx).read_bytes() == none
if lines := (./does-not-exist.xxx).by_line() then
fail("I could read lines in a nonexistent file")
else
@@ -42,101 +34,68 @@ func main()
>> tmpfile.remove()
- >> tmpdir.files().has(tmpfile)
- = no
+ assert tmpdir.files().has(tmpfile) == no
>> tmpdir.remove()
>> p := (/foo/baz.x/qux.tar.gz)
- >> p.base_name()
- = "qux.tar.gz"
- >> p.parent()
- = (/foo/baz.x)
- >> p.extension()
- = "tar.gz"
- >> p.extension(full=no)
- = "gz"
- >> p.has_extension("gz")
- = yes
- >> p.has_extension(".gz")
- = yes
- >> p.has_extension("tar.gz")
- = yes
- >> p.has_extension("txt")
- = no
- >> p.has_extension("")
- = no
- >> (./foo).has_extension("")
- = yes
- >> (..).has_extension("")
- = yes
- >> (~/.foo).has_extension("foo")
- = no
- >> (~/.foo).extension()
- = ""
- >> (~/foo).extension()
- = ""
-
- >> (~/.foo.baz.qux).extension()
- = "baz.qux"
-
- >> (/).parent()
- = (/)
- >> (~/x/.).parent()
- = (~)
- >> (~/x).parent()
- = (~)
- >> (.).parent()
- = (..)
- >> (..).parent()
- = (../..)
- >> (../foo).parent()
- = (..)
+ assert p.base_name() == "qux.tar.gz"
+ assert p.parent() == (/foo/baz.x)
+ assert p.extension() == "tar.gz"
+ assert p.extension(full=no) == "gz"
+ assert p.has_extension("gz") == yes
+ assert p.has_extension(".gz") == yes
+ assert p.has_extension("tar.gz") == yes
+ assert p.has_extension("txt") == no
+ assert p.has_extension("") == no
+ assert (./foo).has_extension("") == yes
+ assert (..).has_extension("") == yes
+ assert (~/.foo).has_extension("foo") == no
+ assert (~/.foo).extension() == ""
+ assert (~/foo).extension() == ""
+
+ assert (~/.foo.baz.qux).extension() == "baz.qux"
+
+ assert (/).parent() == (/)
+ assert (~/x/.).parent() == (~)
+ assert (~/x).parent() == (~)
+ assert (.).parent() == (..)
+ assert (..).parent() == (../..)
+ assert (../foo).parent() == (..)
# Concatenation tests:
say("Basic relative path concatenation:")
- >> (/foo) ++ (./baz)
- = (/foo/baz)
+ assert (/foo) ++ (./baz) == (/foo/baz)
say("Concatenation with a current directory (`.`):")
- >> (/foo/bar) ++ (./.)
- = (/foo/bar)
+ assert (/foo/bar) ++ (./.) == (/foo/bar)
say("Trailing slash in the first path:")
- >> (/foo/) ++ (./baz)
- = (/foo/baz)
+ assert (/foo/) ++ (./baz) == (/foo/baz)
say("Trailing slash in the second path:")
- >> (/foo/bar) ++ (./baz/)
- = (/foo/bar/baz)
+ assert (/foo/bar) ++ (./baz/) == (/foo/bar/baz)
say("Removing redundant current directory (`.`):")
- >> (/foo/bar) ++ (./baz/./qux)
- = (/foo/bar/baz/qux)
+ assert (/foo/bar) ++ (./baz/./qux) == (/foo/bar/baz/qux)
say("Removing redundant parent directory (`..`):")
- >> (/foo/bar) ++ (./baz/qux/../quux)
- = (/foo/bar/baz/quux)
+ assert (/foo/bar) ++ (./baz/qux/../quux) == (/foo/bar/baz/quux)
say("Collapsing `..` to navigate up:")
- >> (/foo/bar/baz) ++ (../qux)
- = (/foo/bar/qux)
+ assert (/foo/bar/baz) ++ (../qux) == (/foo/bar/qux)
say("Current directory and parent directory mixed:")
- >> (/foo/bar) ++ (././../baz)
- = (/foo/baz)
+ assert (/foo/bar) ++ (././../baz) == (/foo/baz)
say("Path begins with a `.`:")
- >> (/foo) ++ (./baz/../qux)
- = (/foo/qux)
+ assert (/foo) ++ (./baz/../qux) == (/foo/qux)
say("Multiple slashes:")
- >> (/foo) ++ (./baz//qux)
- = (/foo/baz/qux)
+ assert (/foo) ++ (./baz//qux) == (/foo/baz/qux)
say("Complex path with multiple `.` and `..`:")
- >> (/foo/bar/baz) ++ (./.././qux/./../quux)
- = (/foo/bar/quux)
+ assert (/foo/bar/baz) ++ (./.././qux/./../quux) == (/foo/bar/quux)
say("Globbing:")
>> (./*.tm).glob()
diff --git a/test/reductions.tm b/test/reductions.tm
index 15c3d454..0d6ac463 100644
--- a/test/reductions.tm
+++ b/test/reductions.tm
@@ -1,54 +1,36 @@
struct Foo(x,y:Int)
func main()
- >> (+: [10, 20, 30])
- = 60
+ assert (+: [10, 20, 30]) == 60
>> empty_ints : [Int]
- >> (+: empty_ints)
- = none
+ assert (+: empty_ints) == none
- >> (+: [10, 20, 30]) or 0
- = 60
+ assert (+: [10, 20, 30]) or 0 == 60
- >> (+: empty_ints) or 0
- = 0
+ assert (+: empty_ints) or 0 == 0
- >> (_max_: [3, 5, 2, 1, 4])
- = 5
+ assert (_max_: [3, 5, 2, 1, 4]) == 5
- >> (_max_.abs(): [1, -10, 5])
- = -10
+ assert (_max_.abs(): [1, -10, 5]) == -10
- >> (_max_: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])!
- = Foo(x=1, y=0)
- >> (_max_.y: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])!
- = Foo(x=0, y=10)
- >> (_max_.y.abs(): [Foo(0, 0), Foo(1, 0), Foo(0, 10), Foo(0, -999)])!
- = Foo(x=0, y=-999)
+ assert (_max_: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])! == Foo(x=1, y=0)
+ assert (_max_.y: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])! == Foo(x=0, y=10)
+ assert (_max_.y.abs(): [Foo(0, 0), Foo(1, 0), Foo(0, 10), Foo(0, -999)])! == Foo(x=0, y=-999)
say("(or) and (and) have early out behavior:")
- >> (or: i == 3 for i in 9999999999999999999999999999)!
- = yes
+ assert (or: i == 3 for i in 9999999999999999999999999999)! == yes
- >> (and: i < 10 for i in 9999999999999999999999999999)!
- = no
+ assert (and: i < 10 for i in 9999999999999999999999999999)! == no
- >> (<=: [1, 2, 2, 3, 4])!
- = yes
+ assert (<=: [1, 2, 2, 3, 4])! == yes
- >> (<=: empty_ints)
- = none
+ assert (<=: empty_ints) == none
- >> (<=: [5, 4, 3, 2, 1])!
- = no
+ assert (<=: [5, 4, 3, 2, 1])! == no
- >> (==: ["x", "y", "z"])
- = no
- >> (==.length: ["x", "y", "z"])
- = yes
- >> (+.length: ["x", "xy", "xyz"])
- = 6
+ assert (==: ["x", "y", "z"]) == no
+ assert (==.length: ["x", "y", "z"]) == yes
+ assert (+.length: ["x", "xy", "xyz"]) == 6
- >> (+.abs(): [1, 2, -3])
- = 6
+ assert (+.abs(): [1, 2, -3]) == 6
diff --git a/test/serialization.tm b/test/serialization.tm
index 0e5be1ae..5653d1f9 100644
--- a/test/serialization.tm
+++ b/test/serialization.tm
@@ -38,8 +38,7 @@ func main()
>> obj := @[10, 20]
>> bytes := obj.serialized()
>> roundtrip := deserialize(bytes -> @[Int])
- >> roundtrip == obj
- = no
+ assert roundtrip != obj
assert roundtrip[] == obj[]
do
diff --git a/test/structs.tm b/test/structs.tm
index 2440911b..fdf92d18 100644
--- a/test/structs.tm
+++ b/test/structs.tm
@@ -9,43 +9,36 @@ struct CorecursiveA(other:@CorecursiveB?)
struct CorecursiveB(other:@CorecursiveA?=none)
func test_literals()
- >> Single(123)
- = Single(123)
- >> x := Pair(10, 20)
- = Pair(x=10, y=20)
- >> y := Pair(y=20, 10)
- = Pair(x=10, y=20)
+ assert Single(123) == Single(123)
+ x := Pair(10, 20)
+ assert x == Pair(x=10, y=20)
+ y := Pair(y=20, 10)
+ assert y == Pair(x=10, y=20)
assert x == y
assert x != Pair(-1, -2)
func test_metamethods()
>> x := Pair(10, 20)
>> y := Pair(100, 200)
- >> x == y
- = no
+ assert x == y == no
assert x == Pair(10, 20)
assert x != Pair(10, 30)
assert x < Pair(11, 20)
>> set := {x=yes}
- >> set.has(x)
- = yes
- >> set.has(y)
- = no
+ assert set.has(x) == yes
+ assert set.has(y) == no
func test_mixed()
>> x := Mixed(10, "Hello")
>> y := Mixed(99, "Hello")
- >> x == y
- = no
+ assert x == y == no
assert x == Mixed(10, "Hello")
assert x != Mixed(10, "Bye")
assert x < Mixed(11, "Hello")
>> set := {x=yes}
- >> set.has(x)
- = yes
- >> set.has(y)
- = no
+ assert set.has(x) == yes
+ assert set.has(y) == no
func test_text()
>> b := @CorecursiveB()
@@ -63,14 +56,11 @@ func main()
>> @LinkedList(10, @LinkedList(20))
>> my_pass := Password("Swordfish")
- = Password("Swordfish")
- >> "$my_pass"
- = "Password(...)"
+ assert my_pass == Password("Swordfish")
+ assert "$my_pass" == "Password(...)"
>> users_by_password := {my_pass="User1", Password("xxx")="User2"}
- >> "$users_by_password"
- = '{Password(...)="User1", Password(...)="User2"}'
- >> users_by_password[my_pass]!
- = "User1"
+ assert "$users_by_password" == '{Password(...)="User1", Password(...)="User2"}'
+ assert users_by_password[my_pass]! == "User1"
>> CorecursiveA(@CorecursiveB())
diff --git a/test/tables.tm b/test/tables.tm
index 66318f11..e13576a0 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -1,115 +1,79 @@
func main()
- >> t := {"one"=1, "two"=2}
- = {"one"=1, "two"=2}
-
- >> t["one"]
- = 1
- >> t["two"]
- = 2
- >> t["???"]
- = none
- >> t["one"]!
- = 1
- >> t["???"] or -1
- = -1
+ t := {"one"=1, "two"=2}
+ assert t == {"one"=1, "two"=2}
+
+ assert t["one"] == 1
+ assert t["two"] == 2
+ assert t["???"] == none
+ assert t["one"]! == 1
+ assert t["???"] or -1 == -1
t_str := ""
for k,v in t
t_str ++= "($k=$v)"
- >> t_str
- = "(one=1)(two=2)"
-
- >> t.length
- = 2
- >> t.fallback
- = none
-
- >> t.keys
- = ["one", "two"]
- >> t.values
- = [1, 2]
-
- >> t2 := {"three"=3; fallback=t}
- = {"three"=3; fallback={"one"=1, "two"=2}}
-
- >> t2["one"]
- = 1
- >> t2["three"]
- = 3
- >> t2["???"]
- = none
-
- >> t2.length
- = 1
- >> t2.fallback
- = {"one"=1, "two"=2}
+ assert t_str == "(one=1)(two=2)"
+
+ assert t.length == 2
+ assert t.fallback == none
+
+ assert t.keys == ["one", "two"]
+ assert t.values == [1, 2]
+
+ t2 := {"three"=3; fallback=t}
+ assert t2 == {"three"=3; fallback={"one"=1, "two"=2}}
+
+ assert t2["one"] == 1
+ assert t2["three"] == 3
+ assert t2["???"] == none
+
+ assert t2.length == 1
+ assert t2.fallback == {"one"=1, "two"=2}
t2_str := ""
for k,v in t2
t2_str ++= "($k=$v)"
- >> t2_str
- = "(three=3)"
+ assert t2_str == "(three=3)"
- >> {i=10*i for i in 5}
- = {1=10, 2=20, 3=30, 4=40, 5=50}
- >> {i=10*i for i in 5 if i mod 2 != 0}
- = {1=10, 3=30, 5=50}
- >> {x=10*x for x in y if x > 1 for y in [3, 4, 5] if y < 5}
- = {2=20, 3=30, 4=40}
+ assert {i=10*i for i in 5} == {1=10, 2=20, 3=30, 4=40, 5=50}
+ assert {i=10*i for i in 5 if i mod 2 != 0} == {1=10, 3=30, 5=50}
+ assert {x=10*x for x in y if x > 1 for y in [3, 4, 5] if y < 5} == {2=20, 3=30, 4=40}
>> t3 := @{1=10, 2=20, 3=30}
>> t3.remove(3)
- >> t3[]
- = {1=10, 2=20}
+ assert t3[] == {1=10, 2=20}
do
>> plain := {1=10, 2=20, 3=30}
- >> plain[2]!
- = 20
- >> plain[2]!
- = 20
- >> plain[456] or -999
- = -999
- >> plain.has(2)
- = yes
- >> plain.has(456)
- = no
+ assert plain[2]! == 20
+ assert plain[2]! == 20
+ assert plain[456] or -999 == -999
+ assert plain.has(2) == yes
+ assert plain.has(456) == no
>> fallback := {4=40; fallback=plain}
- >> fallback.has(1)
- = yes
- >> fallback[1] or -999
- = 10
+ assert fallback.has(1) == yes
+ assert fallback[1] or -999 == 10
do
>> t4 := &{"one"= 1}
>> t4["one"] = 999
>> t4["two"] = 222
- >> t4[]
- = {"one"=999, "two"=222}
+ assert t4[] == {"one"=999, "two"=222}
do
assert {1=1, 2=2} == {2=2, 1=1}
assert {1=1, 2=2} != {1=1, 2=999}
- >> {1=1, 2=2} <> {2=2, 1=1}
- = Int32(0)
- >> ints : [{Int=Int}] = [{}, {0=0}, {99=99}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 2=-99, 3=3}, {1=1, 99=-99, 3=4}].sorted()
- = [{}, {0=0}, {1=1, 2=-99, 3=3}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 99=-99, 3=4}, {99=99}]
+ assert ({1=1, 2=2} <> {2=2, 1=1}) == Int32(0)
+ ints : [{Int=Int}] = [{}, {0=0}, {99=99}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 2=-99, 3=3}, {1=1, 99=-99, 3=4}]
+ assert ints.sorted() == [{}, {0=0}, {1=1, 2=-99, 3=3}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 99=-99, 3=4}, {99=99}]
do
# Default values:
counter := &{"x"=10; default=0}
- >> counter["x"]
- = 10
- >> counter["y"]
- = 0
- >> counter.has("x")
- = yes
- >> counter.has("y")
- = no
+ assert counter["x"] == 10
+ assert counter["y"] == 0
+ assert counter.has("x") == yes
+ assert counter.has("y") == no
>> counter["y"] += 1
- >> counter
- >> counter[]
- = {"x"=10, "y"=1; default=0}
diff --git a/test/text.tm b/test/text.tm
index 84c5a2a3..c12e7a78 100644
--- a/test/text.tm
+++ b/test/text.tm
@@ -2,309 +2,194 @@ func main()
str := "Hello Amélie!"
say("Testing strings like $str")
- >> str.upper()
- = "HELLO AMÉLIE!"
- >> str.lower()
- = "hello amélie!"
- >> str.lower().title()
- = "Hello Amélie!"
- >> str[1]
- = "H"
+ assert str.upper() == "HELLO AMÉLIE!"
+ assert str.lower() == "hello amélie!"
+ assert str.lower().title() == "Hello Amélie!"
+ assert str[1] == "H"
- >> "I".lower()
- = "i"
- >> "I".lower(language="tr_TR")
- = "ı"
+ assert "I".lower() == "i"
+ assert "I".lower(language="tr_TR") == "ı"
- >> "i".upper()
- = "I"
- >> "i".upper(language="tr_TR")
- = "İ"
+ assert "i".upper() == "I"
+ assert "i".upper(language="tr_TR") == "İ"
- >> "ian".title()
- = "Ian"
- >> "ian".title(language="tr_TR")
- = "İan"
+ assert "ian".title() == "Ian"
+ assert "ian".title(language="tr_TR") == "İan"
- >> "I".caseless_equals("ı")
- = no
- >> "I".caseless_equals("ı", language="tr_TR")
- = yes
+ assert "I".caseless_equals("ı") == no
+ assert "I".caseless_equals("ı", language="tr_TR") == yes
- >> str[9]
- = "é"
+ assert str[9] == "é"
- >> str[99]
- = none
+ assert str[99] == none
- >> "\{UE9}"
- = "é"
+ assert "\{UE9}" == "é"
- >> "\{U65}\{U301}"
- = "é"
+ assert "\{U65}\{U301}" == "é"
- >> "\{Penguin}".codepoint_names()
- = ["PENGUIN"]
+ assert "\{Penguin}".codepoint_names() == ["PENGUIN"]
- >> "\[31;1]"
- = "\e[31;1m"
+ assert "\[31;1]" == "\e[31;1m"
assert "\{UE9}" == "\{U65}\{U301}"
amelie := "Am\{UE9}lie"
- >> amelie.split()
- = ["A", "m", "é", "l", "i", "e"]
- >> amelie.utf32()
- = [65, 109, 233, 108, 105, 101]
- >> amelie.utf8()
- = [0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65]
- >> Text.from_utf8([0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65])!
- = "Amélie"
- >> Text.from_utf8([Byte(0xFF)])
- = none
+ assert amelie.split() == ["A", "m", "é", "l", "i", "e"]
+ assert amelie.utf32() == [65, 109, 233, 108, 105, 101]
+ assert amelie.utf8() == [0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65]
+ assert Text.from_utf8([0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65])! == "Amélie"
+ assert Text.from_utf8([Byte(0xFF)]) == none
amelie2 := "Am\{U65}\{U301}lie"
- >> amelie2.split()
- = ["A", "m", "é", "l", "i", "e"]
- >> amelie2.utf32()
- = [65, 109, 233, 108, 105, 101]
- >> amelie2.utf8()
- = [0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65]
-
- >> amelie.codepoint_names()
- = ["LATIN CAPITAL LETTER A", "LATIN SMALL LETTER M", "LATIN SMALL LETTER E WITH ACUTE", "LATIN SMALL LETTER L", "LATIN SMALL LETTER I", "LATIN SMALL LETTER E"]
- >> amelie2.codepoint_names()
- = ["LATIN CAPITAL LETTER A", "LATIN SMALL LETTER M", "LATIN SMALL LETTER E WITH ACUTE", "LATIN SMALL LETTER L", "LATIN SMALL LETTER I", "LATIN SMALL LETTER E"]
-
- >> "Hello".replace("e", "X")
- = "HXllo"
-
- >> "Hello".has("l")
- = yes
- >> "Hello".has("x")
- = no
-
- >> "Hello".replace("l", "")
- = "Heo"
- >> "xxxx".replace("x", "")
- = ""
- >> "xxxx".replace("y", "")
- = "xxxx"
- >> "One two three four five six".replace("e ", "")
- = "Ontwo threfour fivsix"
-
- >> amelie.has(amelie2)
- = yes
-
- >> multiline := "
+ assert amelie2.split() == ["A", "m", "é", "l", "i", "e"]
+ assert amelie2.utf32() == [65, 109, 233, 108, 105, 101]
+ assert amelie2.utf8() == [0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65]
+
+ assert amelie.codepoint_names() == ["LATIN CAPITAL LETTER A", "LATIN SMALL LETTER M", "LATIN SMALL LETTER E WITH ACUTE", "LATIN SMALL LETTER L", "LATIN SMALL LETTER I", "LATIN SMALL LETTER E"]
+ assert amelie2.codepoint_names() == ["LATIN CAPITAL LETTER A", "LATIN SMALL LETTER M", "LATIN SMALL LETTER E WITH ACUTE", "LATIN SMALL LETTER L", "LATIN SMALL LETTER I", "LATIN SMALL LETTER E"]
+
+ assert "Hello".replace("e", "X") == "HXllo"
+
+ assert "Hello".has("l") == yes
+ assert "Hello".has("x") == no
+
+ assert "Hello".replace("l", "") == "Heo"
+ assert "xxxx".replace("x", "") == ""
+ assert "xxxx".replace("y", "") == "xxxx"
+ assert "One two three four five six".replace("e ", "") == "Ontwo threfour fivsix"
+
+ assert amelie.has(amelie2) == yes
+
+ multiline := "
line one
line two
"
- = "line one\nline two"
+ assert multiline == "line one\nline two"
say("Interpolation tests:")
- >> "A $(1+2)"
- = "A 3"
- >> "A \$(1+2)"
- = "A \$(1+2)"
- >> 'A $(1+2)'
- = "A 3"
- >> `A @(1+2)`
- = "A 3"
+ assert "A $(1+2)" == "A 3"
+ assert "A \$(1+2)" == "A \$(1+2)"
+ assert 'A $(1+2)' == "A 3"
+ assert `A @(1+2)` == "A 3"
c := "É̩"
- >> c.codepoint_names()
- = ["LATIN CAPITAL LETTER E WITH ACUTE", "COMBINING VERTICAL LINE BELOW"]
+ assert c.codepoint_names() == ["LATIN CAPITAL LETTER E WITH ACUTE", "COMBINING VERTICAL LINE BELOW"]
assert c == Text.from_codepoint_names(c.codepoint_names())!
assert c == Text.from_utf32(c.utf32())!
assert c == Text.from_utf8(c.utf8())!
- >> "one\ntwo\nthree".lines()
- = ["one", "two", "three"]
- >> "one\ntwo\nthree\n".lines()
- = ["one", "two", "three"]
- >> "one\ntwo\nthree\n\n".lines()
- = ["one", "two", "three", ""]
- >> "one\r\ntwo\r\nthree\r\n".lines()
- = ["one", "two", "three"]
- >> "".lines()
- = []
+ assert "one\ntwo\nthree".lines() == ["one", "two", "three"]
+ assert "one\ntwo\nthree\n".lines() == ["one", "two", "three"]
+ assert "one\ntwo\nthree\n\n".lines() == ["one", "two", "three", ""]
+ assert "one\r\ntwo\r\nthree\r\n".lines() == ["one", "two", "three"]
+ assert "".lines() == []
say("Test splitting and joining text:")
- >> "one,, two,three".split(",")
- = ["one", "", " two", "three"]
- >> [t for t in "one,, two,three".by_split(",")]
- = ["one", "", " two", "three"]
- >> "one,, two,three".split_any(", ")
- = ["one", "two", "three"]
- >> [t for t in "one,, two,three".by_split_any(", ")]
- = ["one", "two", "three"]
- >> ",one,, two,three,".split(",")
- = ["", "one", "", " two", "three", ""]
- >> [t for t in ",one,, two,three,".by_split(",")]
- = ["", "one", "", " two", "three", ""]
- >> ",one,, two,three,".split_any(", ")
- = ["", "one", "two", "three", ""]
- >> [t for t in ",one,, two,three,".by_split_any(", ")]
- = ["", "one", "two", "three", ""]
-
- >> "abc".split()
- = ["a", "b", "c"]
-
- >> "one two three".split_any()
- = ["one", "two", "three"]
-
- >> ", ".join(["one", "two", "three"])
- = "one, two, three"
-
- >> "".join(["one", "two", "three"])
- = "onetwothree"
-
- >> "+".join(["one"])
- = "one"
-
- >> "+".join([])
- = ""
-
- >> "".split()
- = []
+ assert "one,, two,three".split(",") == ["one", "", " two", "three"]
+ assert [t for t in "one,, two,three".by_split(",")] == ["one", "", " two", "three"]
+ assert "one,, two,three".split_any(", ") == ["one", "two", "three"]
+ assert [t for t in "one,, two,three".by_split_any(", ")] == ["one", "two", "three"]
+ assert ",one,, two,three,".split(",") == ["", "one", "", " two", "three", ""]
+ assert [t for t in ",one,, two,three,".by_split(",")] == ["", "one", "", " two", "three", ""]
+ assert ",one,, two,three,".split_any(", ") == ["", "one", "two", "three", ""]
+ assert [t for t in ",one,, two,three,".by_split_any(", ")] == ["", "one", "two", "three", ""]
+
+ assert "abc".split() == ["a", "b", "c"]
+
+ assert "one two three".split_any() == ["one", "two", "three"]
+
+ assert ", ".join(["one", "two", "three"]) == "one, two, three"
+
+ assert "".join(["one", "two", "three"]) == "onetwothree"
+
+ assert "+".join(["one"]) == "one"
+
+ assert "+".join([]) == ""
+
+ assert "".split() == []
say("Test text slicing:")
- >> "abcdef".slice()
- = "abcdef"
- >> "abcdef".slice(from=3)
- = "cdef"
- >> "abcdef".slice(to=-2)
- = "abcde"
- >> "abcdef".slice(from=2, to=4)
- = "bcd"
- >> "abcdef".slice(from=5, to=1)
- = ""
-
- >> house := "家"
- = "家"
- >> house.length
- = 1
- >> house.codepoint_names()
- = ["CJK Unified Ideographs-5BB6"]
- >> house.utf32()
- = [23478]
-
- >> "🐧".codepoint_names()
- = ["PENGUIN"]
-
- >> Text.from_codepoint_names(["not a valid name here buddy"])
- = none
-
- >> "Hello".replace("ello", "i")
- = "Hi"
-
- >> "<tag>".translate({"<"="&lt;", ">"="&gt;"})
- = "&lt;tag&gt;"
-
- >> "Abc".repeat(3)
- = "AbcAbcAbc"
-
- >> "abcde".starts_with("ab")
- = yes
- >> "abcde".starts_with("bc")
- = no
-
- >> "abcde".ends_with("de")
- = yes
- >> "abcde".starts_with("cd")
- = no
-
- >> "abcde".without_prefix("ab")
- = "cde"
- >> "abcde".without_suffix("ab")
- = "abcde"
-
- >> "abcde".without_prefix("de")
- = "abcde"
- >> "abcde".without_suffix("de")
- = "abc"
-
- >> ("hello" ++ " " ++ "Amélie").reversed()
- = "eilémA olleh"
+ assert "abcdef".slice() == "abcdef"
+ assert "abcdef".slice(from=3) == "cdef"
+ assert "abcdef".slice(to=-2) == "abcde"
+ assert "abcdef".slice(from=2, to=4) == "bcd"
+ assert "abcdef".slice(from=5, to=1) == ""
+
+ house := "家"
+ assert house == "家"
+ assert house.length == 1
+ assert house.codepoint_names() == ["CJK Unified Ideographs-5BB6"]
+ assert house.utf32() == [23478]
+
+ assert "🐧".codepoint_names() == ["PENGUIN"]
+
+ assert Text.from_codepoint_names(["not a valid name here buddy"]) == none
+
+ assert "Hello".replace("ello", "i") == "Hi"
+
+ assert "<tag>".translate({"<"="&lt;", ">"="&gt;"}) == "&lt;tag&gt;"
+
+ assert "Abc".repeat(3) == "AbcAbcAbc"
+
+ assert "abcde".starts_with("ab") == yes
+ assert "abcde".starts_with("bc") == no
+
+ assert "abcde".ends_with("de") == yes
+ assert "abcde".starts_with("cd") == no
+
+ assert "abcde".without_prefix("ab") == "cde"
+ assert "abcde".without_suffix("ab") == "abcde"
+
+ assert "abcde".without_prefix("de") == "abcde"
+ assert "abcde".without_suffix("de") == "abc"
+
+ assert ("hello" ++ " " ++ "Amélie").reversed() == "eilémA olleh"
do
say("Testing concatenation-stability:")
ab := Text.from_codepoint_names(["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"])!
- >> ab.codepoint_names()
- = ["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"]
- >> ab.length
- = 1
+ assert ab.codepoint_names() == ["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"]
+ assert ab.length == 1
a := Text.from_codepoint_names(["LATIN SMALL LETTER E"])!
b := Text.from_codepoint_names(["COMBINING VERTICAL LINE BELOW"])!
- >> (a++b).codepoint_names()
- = ["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"]
+ assert (a++b).codepoint_names() == ["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"]
assert (a++b) == ab
- >> (a++b).length
- = 1
+ assert (a++b).length == 1
do
concat := "e" ++ Text.from_utf32([Int32(0x300)])!
- >> concat.length
- = 1
+ assert concat.length == 1
concat2 := concat ++ Text.from_utf32([Int32(0x302)])!
- >> concat2.length
- = 1
+ assert concat2.length == 1
concat3 := concat2 ++ Text.from_utf32([Int32(0x303)])!
- >> concat3.length
- = 1
+ assert concat3.length == 1
final := Text.from_utf32([Int32(0x65), Int32(0x300), Int32(0x302), Int32(0x303)])!
- >> final.length
- = 1
+ assert final.length == 1
assert concat3 == final
concat4 := Text.from_utf32([Int32(0x65), Int32(0x300)])! ++ Text.from_utf32([Int32(0x302), Int32(0x303)])!
- >> concat4.length
- = 1
+ assert concat4.length == 1
assert concat4 == final
- >> "x".left_pad(5)
- = " x"
- >> "x".right_pad(5)
- = "x "
- >> "x".middle_pad(5)
- = " x "
- >> "1234".left_pad(8, "XYZ")
- = "XYZX1234"
- >> "1234".right_pad(8, "XYZ")
- = "1234XYZX"
- >> "1234".middle_pad(9, "XYZ")
- = "XY1234XYZ"
-
- >> amelie.width()
- = 6
-
- # Unicode character width is somewhat platform dependent:
- # cowboy := "🤠"
- # >> cowboy.width()
- # = 2
- # >> cowboy.left_pad(4)
- # = " 🤠"
- # >> cowboy.right_pad(4)
- # = "🤠 "
- # >> cowboy.middle_pad(4)
- # = " 🤠 "
-
- >> " one, ".trim(" ,")
- = "one"
- >> " one, ".trim(" ,", left=no)
- = " one"
- >> " one, ".trim(" ,", right=no)
- = "one, "
- >> " ".trim(" ,")
- = ""
- >> " ".trim(" ,", left=no)
- = ""
+ assert "x".left_pad(5) == " x"
+ assert "x".right_pad(5) == "x "
+ assert "x".middle_pad(5) == " x "
+ assert "1234".left_pad(8, "XYZ") == "XYZX1234"
+ assert "1234".right_pad(8, "XYZ") == "1234XYZX"
+ assert "1234".middle_pad(9, "XYZ") == "XY1234XYZ"
+
+ assert amelie.width() == 6
+
+ assert " one, ".trim(" ,") == "one"
+ assert " one, ".trim(" ,", left=no) == " one"
+ assert " one, ".trim(" ,", right=no) == "one, "
+ assert " ".trim(" ,") == ""
+ assert " ".trim(" ,", left=no) == ""
do
test := "𤭢"
diff --git a/test/when.tm b/test/when.tm
index 57de4c2c..26afeb7d 100644
--- a/test/when.tm
+++ b/test/when.tm
@@ -8,11 +8,11 @@ func main()
else "Other"
) for x in ["A", "B", "C", "D"]
]
- >> answers
- = ["A or B", "A or B", "C", "Other"]
+ assert answers == ["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)
- = Int64(23)
+ assert (
+ when n is 1 Int64(1)
+ is 2 Int64(2)
+ is 21 + 2 Int64(23)
+ ) == Int64(23)