aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compile.c10
-rw-r--r--test/enums.tm6
-rw-r--r--test/functions.tm6
-rw-r--r--test/integers.tm6
-rw-r--r--test/lists.tm6
-rw-r--r--test/nums.tm33
-rw-r--r--test/optionals.tm6
-rw-r--r--test/paths.tm12
-rw-r--r--test/serialization.tm47
-rw-r--r--test/structs.tm24
-rw-r--r--test/tables.tm6
-rw-r--r--test/text.tm21
12 files changed, 68 insertions, 115 deletions
diff --git a/src/compile.c b/src/compile.c
index 5aa1ab33..3bc2fa4a 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -113,8 +113,10 @@ static bool promote(env_t *env, ast_t *ast, CORD *code, type_t *actual, type_t *
// Automatic optional checking for nums:
if (needed->tag == NumType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == NumType) {
+ int64_t line = get_line_number(ast->file, ast->start);
*code = CORD_all("({ ", compile_declaration(actual, "opt"), " = ", *code, "; ",
"if unlikely (", check_none(actual, "opt"), ")\n",
+ "#line ", String(line), "\n",
"fail_source(", CORD_quoted(ast->file->filename), ", ",
String((int64_t)(ast->start - ast->file->text)), ", ",
String((int64_t)(ast->end - ast->file->text)), ", ",
@@ -1308,10 +1310,14 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
ast_t *rhs_var = FakeAST(InlineCCode, .chunks=new(ast_list_t, .ast=FakeAST(TextLiteral, "_rhs")), .type=operand_t);
ast_t *var_comparison = new(ast_t, .file=expr->file, .start=expr->start, .end=expr->end, .tag=expr->tag,
.__data.Equals={.lhs=lhs_var, .rhs=rhs_var});
+ int64_t line = get_line_number(ast->file, ast->start);
return CORD_all("{ // assertion\n",
compile_declaration(operand_t, "_lhs"), " = ", compile_to_type(env, cmp.lhs, operand_t), ";\n",
+ "\n#line ", String(line), "\n",
compile_declaration(operand_t, "_rhs"), " = ", compile_to_type(env, cmp.rhs, operand_t), ";\n",
+ "\n#line ", String(line), "\n",
"if (!(", compile_condition(env, var_comparison), "))\n",
+ "#line ", String(line), "\n",
CORD_all(
"fail_source(", CORD_quoted(ast->file->filename), ", ",
String((int64_t)(expr->start - expr->file->text)), ", ",
@@ -1324,8 +1330,10 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
}
default: {
+ int64_t line = get_line_number(ast->file, ast->start);
return CORD_all(
"if (!(", compile_condition(env, expr), "))\n",
+ "#line ", String(line), "\n",
"fail_source(", CORD_quoted(ast->file->filename), ", ",
String((int64_t)(expr->start - expr->file->text)), ", ",
String((int64_t)(expr->end - expr->file->text)), ", ",
@@ -2826,8 +2834,10 @@ CORD compile(env_t *env, ast_t *ast)
ast_t *value = Match(ast, NonOptional)->value;
type_t *t = get_type(env, value);
CORD value_code = compile(env, value);
+ int64_t line = get_line_number(ast->file, ast->start);
return CORD_all("({ ", compile_declaration(t, "opt"), " = ", value_code, "; ",
"if unlikely (", check_none(t, "opt"), ")\n",
+ "#line ", String(line), "\n",
"fail_source(", CORD_quoted(ast->file->filename), ", ",
String((int64_t)(value->start - value->file->text)), ", ",
String((int64_t)(value->end - value->file->text)), ", ",
diff --git a/test/enums.tm b/test/enums.tm
index 901298a8..080e5d97 100644
--- a/test/enums.tm
+++ b/test/enums.tm
@@ -29,8 +29,7 @@ func main()
>> one.Two
= no
- >> Foo.One(10) == Foo.One(10)
- = yes
+ assert Foo.One(10) == Foo.One(10)
>> Foo.One(10) == Foo.Zero
= no
@@ -38,8 +37,7 @@ func main()
>> Foo.One(10) == Foo.One(-1)
= no
- >> Foo.One(10) < Foo.Two(1, 2)
- = yes
+ assert Foo.One(10) < Foo.Two(1, 2)
>> x := Foo.One(123)
>> t := |x|
diff --git a/test/functions.tm b/test/functions.tm
index 17ca1e85..7ceca977 100644
--- a/test/functions.tm
+++ b/test/functions.tm
@@ -8,8 +8,6 @@ func main()
>> add(3, 5)
= 8
- >> cached_heap(1) == cached_heap(1)
- = yes
- >> cached_heap(1) == cached_heap(2)
- = no
+ assert cached_heap(1) == cached_heap(1)
+ assert cached_heap(1) != cached_heap(2)
diff --git a/test/integers.tm b/test/integers.tm
index 3035ad3b..ee560952 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -85,8 +85,7 @@ func main()
interesting_denominators := [-99, -20, -17, -1, 1, 17, 20, 99]
for n in interesting_numerators
for d in interesting_denominators
- >> (n/d)*d + (n mod d) == n
- = yes
+ assert (n/d)*d + (n mod d) == n
>> (0).next_prime()
= 2
@@ -94,7 +93,7 @@ func main()
= 11
#>> (11).prev_prime()
#= 7
- >> (and: p.is_prime() for p in [
+ assert (and: p.is_prime() for p in [
2, 3, 5, 7,
137372146048179869781170214707,
811418847921670560768224995279,
@@ -107,7 +106,6 @@ func main()
121475876690852432982324195553,
771958616175795150904761471637,
])!
- = yes
>> (or: p.is_prime() for p in [
-1, 0, 1, 4, 6,
diff --git a/test/lists.tm b/test/lists.tm
index 6281532c..fef23f5d 100644
--- a/test/lists.tm
+++ b/test/lists.tm
@@ -111,16 +111,14 @@ func main()
heap_order : @[Int]
repeat
heap_order.insert(heap.heap_pop() or stop)
- >> heap_order[] == heap_order.sorted()
- = yes
+ assert heap_order[] == heap_order.sorted()
heap_order[] = []
for i in 10
heap.heap_push((i*13337) mod 37)
>> heap
repeat
heap_order.insert(heap.heap_pop() or stop)
- >> heap_order[] == heap_order.sorted()
- = yes
+ assert heap_order[] == heap_order.sorted()
do
>> [i*10 for i in 5].from(3)
diff --git a/test/nums.tm b/test/nums.tm
index 3653f18a..362f590f 100644
--- a/test/nums.tm
+++ b/test/nums.tm
@@ -19,29 +19,20 @@ func main()
>> Num.INF
= Num.INF
- >> Num.INF.isinf()
- = yes
+ assert Num.INF.isinf()
>> none_num : Num? = none
= none
- >> none_num == none_num
- = yes
- >> none_num < none_num
- = no
- >> none_num > none_num
- = no
- >> none_num != none_num
- = no
+ 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)
- >> none_num == 0.0
- = no
- >> none_num < 0.0
- = yes
- >> none_num > 0.0
- = no
- >> none_num != 0.0
- = yes
+ 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)
@@ -53,10 +44,8 @@ func main()
# >> 0./0.
# = none
- >> Num.PI.cos()!.near(-1)
- = yes
- >> Num.PI.sin()!.near(0)
- = yes
+ assert Num.PI.cos()!.near(-1)
+ assert Num.PI.sin()!.near(0)
>> Num.INF.near(-Num.INF)
= no
diff --git a/test/optionals.tm b/test/optionals.tm
index 8e075855..7bdd2fd1 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -241,10 +241,8 @@ func main()
= 123
# Test comparisons, hashing, equality:
- >> (none == 5?)
- = no
- >> (5? == 5?)
- = yes
+ assert none != 5?
+ assert 5? == 5?
>> nones : |Int?| = |none, none|
>> also_nones : |Int?| = |none|
>> nones == also_nones
diff --git a/test/paths.tm b/test/paths.tm
index 14a15299..d92d4623 100644
--- a/test/paths.tm
+++ b/test/paths.tm
@@ -1,9 +1,7 @@
# Tests for file paths
func main()
- >> (/).exists()
- = yes
- >> (~/).exists()
- = yes
+ assert (/).exists()
+ assert (~/).exists()
>> (~/Downloads/file(1).txt)
= (~/Downloads/file(1).txt)
@@ -16,8 +14,7 @@ func main()
= (~/example.txt)
>> tmpdir := (/tmp/tomo-test-path-XXXXXX).unique_directory()
- >> (/tmp).subdirectories().has(tmpdir)
- = yes
+ assert (/tmp).subdirectories().has(tmpdir)
>> tmpfile := (tmpdir++(./one.txt))
>> tmpfile.write("Hello world")
@@ -26,8 +23,7 @@ func main()
= "Hello world!"?
>> tmpfile.read_bytes()!
= [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21]
- >> tmpdir.files().has(tmpfile)
- = yes
+ assert tmpdir.files().has(tmpfile)
if tmp_lines := tmpfile.by_line() then
>> [line for line in tmp_lines]
diff --git a/test/serialization.tm b/test/serialization.tm
index 12917f98..8e1a4a1c 100644
--- a/test/serialization.tm
+++ b/test/serialization.tm
@@ -7,39 +7,32 @@ func main()
do
>> obj := Int64(123)
>> bytes := obj.serialized()
- >> deserialize(bytes -> Int64) == obj
- = yes
+ assert deserialize(bytes -> Int64) == obj
do
>> obj := 5
>> bytes := obj.serialized()
- >> deserialize(bytes -> Int) == obj
- = yes
+ assert deserialize(bytes -> Int) == obj
do
>> obj := 9999999999999999999999999999999999999999999999999999
>> bytes := obj.serialized()
- >> deserialize(bytes -> Int) == obj
- = yes
+ assert deserialize(bytes -> Int) == obj
do
>> obj := "Héllo"
>> bytes := obj.serialized()
- >> deserialize(bytes -> Text)
- >> deserialize(bytes -> Text) == obj
- = yes
+ assert deserialize(bytes -> Text) == obj
do
>> obj := [Int64(10), Int64(20), Int64(30)].reversed()
>> bytes := obj.serialized()
- >> deserialize(bytes -> [Int64]) == obj
- = yes
+ assert deserialize(bytes -> [Int64]) == obj
do
>> obj := yes
>> bytes := obj.serialized()
- >> deserialize(bytes -> Bool) == obj
- = yes
+ assert deserialize(bytes -> Bool) == obj
do
>> obj := @[10, 20]
@@ -47,52 +40,44 @@ func main()
>> roundtrip := deserialize(bytes -> @[Int])
>> roundtrip == obj
= no
- >> roundtrip[] == obj[]
- = yes
+ assert roundtrip[] == obj[]
do
>> obj := {"A"=10, "B"=20; fallback={"C"=30}}
>> bytes := obj.serialized()
>> roundtrip := deserialize(bytes -> {Text=Int})
- >> roundtrip == obj
- = yes
- >> roundtrip.fallback == obj.fallback
- = yes
+ assert roundtrip == obj
+ assert roundtrip.fallback == obj.fallback
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))
+ >> roundtrip := deserialize(bytes -> @Foo)
+ assert "$roundtrip" == "$obj"
do
>> obj := MyEnum.Two(123, "OKAY")
>> bytes := obj.serialized()
- >> deserialize(bytes -> MyEnum) == obj
- = yes
+ assert deserialize(bytes -> MyEnum) == obj
do
>> obj := "Hello"?
>> bytes := obj.serialized()
- >> deserialize(bytes -> Text?) == obj
- = yes
+ assert deserialize(bytes -> Text?) == obj
do
>> obj := |10, 20, 30|
>> bytes := obj.serialized()
- >> deserialize(bytes -> |Int|) == obj
- = yes
+ assert deserialize(bytes -> |Int|) == obj
do
>> obj : Num? = none
>> bytes := obj.serialized()
- >> deserialize(bytes -> Num?) == obj
- = yes
+ assert deserialize(bytes -> Num?) == obj
do
cases := [0, -1, 1, 10, 100000, 999999999999999999999999999]
for i in cases
>> bytes := i.serialized()
- >> deserialize(bytes -> Int) == i
- = yes
+ assert deserialize(bytes -> Int) == i
diff --git a/test/structs.tm b/test/structs.tm
index c340f1c9..a58a9ef7 100644
--- a/test/structs.tm
+++ b/test/structs.tm
@@ -15,23 +15,18 @@ func test_literals()
= Pair(x=10, y=20)
>> y := Pair(y=20, 10)
= Pair(x=10, y=20)
- >> x == y
- = yes
- >> x == Pair(-1, -2)
- = no
+ assert x == y
+ assert x != Pair(-1, -2)
func test_metamethods()
>> x := Pair(10, 20)
>> y := Pair(100, 200)
>> x == y
= no
- >> x == Pair(10, 20)
- = yes
- >> x == Pair(10, 30)
- = no
+ assert x == Pair(10, 20)
+ assert x != Pair(10, 30)
- >> x < Pair(11, 20)
- = yes
+ assert x < Pair(11, 20)
>> set := |x|
>> set.has(x)
= yes
@@ -43,12 +38,9 @@ func test_mixed()
>> y := Mixed(99, "Hello")
>> x == y
= no
- >> x == Mixed(10, "Hello")
- = yes
- >> x == Mixed(10, "Bye")
- = no
- >> x < Mixed(11, "Hello")
- = yes
+ assert x == Mixed(10, "Hello")
+ assert x != Mixed(10, "Bye")
+ assert x < Mixed(11, "Hello")
>> set := |x|
>> set.has(x)
= yes
diff --git a/test/tables.tm b/test/tables.tm
index 9419d875..2254a7a0 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -89,10 +89,8 @@ func main()
= &{"one"=999, "two"=222}
do
- >> {1=1, 2=2} == {2=2, 1=1}
- = yes
- >> {1=1, 2=2} == {1=1, 2=999}
- = no
+ 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)
diff --git a/test/text.tm b/test/text.tm
index 9634f17d..ff55555d 100644
--- a/test/text.tm
+++ b/test/text.tm
@@ -46,8 +46,7 @@ func main()
>> "\[31;1]"
= "\e[31;1m"
- >> "\{UE9}" == "\{U65}\{U301}"
- = yes
+ assert "\{UE9}" == "\{U65}\{U301}"
amelie := "Am\{UE9}lie"
>> amelie.split()
@@ -120,12 +119,9 @@ func main()
c := "É̩"
>> c.codepoint_names()
= ["LATIN CAPITAL LETTER E WITH ACUTE", "COMBINING VERTICAL LINE BELOW"]
- >> c == Text.from_codepoint_names(c.codepoint_names())!
- = yes
- >> c == Text.from_codepoints(c.utf32_codepoints())
- = yes
- >> c == Text.from_bytes(c.bytes())!
- = yes
+ assert c == Text.from_codepoint_names(c.codepoint_names())!
+ assert c == Text.from_codepoints(c.utf32_codepoints())
+ assert c == Text.from_bytes(c.bytes())!
>> "one\ntwo\nthree".lines()
= ["one", "two", "three"]
@@ -248,8 +244,7 @@ func main()
b := Text.from_codepoint_names(["COMBINING VERTICAL LINE BELOW"])!
>> (a++b).codepoint_names()
= ["LATIN SMALL LETTER E", "COMBINING VERTICAL LINE BELOW"]
- >> (a++b) == ab
- = yes
+ assert (a++b) == ab
>> (a++b).length
= 1
@@ -270,14 +265,12 @@ func main()
final := Text.from_codepoints([Int32(0x65), Int32(0x300), Int32(0x302), Int32(0x303)])
>> final.length
= 1
- >> concat3 == final
- = yes
+ assert concat3 == final
concat4 := Text.from_codepoints([Int32(0x65), Int32(0x300)]) ++ Text.from_codepoints([Int32(0x302), Int32(0x303)])
>> concat4.length
= 1
- >> concat4 == final
- = yes
+ assert concat4 == final
>> "x".left_pad(5)
= " x"