diff options
| -rw-r--r-- | CHANGES.md | 15 | ||||
| -rw-r--r-- | src/stdlib/stdlib.c | 47 | ||||
| -rw-r--r-- | test/defer.tm | 4 | ||||
| -rw-r--r-- | test/lists.tm | 36 | ||||
| -rw-r--r-- | test/sets.tm | 13 | ||||
| -rw-r--r-- | test/structs.tm | 1 | ||||
| -rw-r--r-- | test/tables.tm | 12 |
7 files changed, 65 insertions, 63 deletions
@@ -9,13 +9,14 @@ - Programs can use `--version` as a CLI flag to print a Tomo program's version number and exit. - Added `tomo --prefix` to print the Tomo install prefix. -- Sets now support infix operations for `and`, `or`, `xor`, and `-` -- Added Path.sibling() -- Added Path.has_extension() -- Added Table.with_fallback() -- Added Int*.get_bit() and Byte.get_bit() -- Improved space efficiency of Text that contains non-ASCII codepoints -- Fixed bugs: +- Sets now support infix operations for `and`, `or`, `xor`, and `-`. +- Added Path.sibling(). +- Added Path.has_extension(). +- Added Table.with_fallback(). +- Added Int*.get_bit() and Byte.get_bit(). +- Improved space efficiency of Text that contains non-ASCII codepoints. +- Doctests now use equality checking instead of converting to text. +- Fixed the following bugs: - Negative integers weren't converting to text properly. - Mutation of a collection during iteration was violating value semantics. - `extend` statements weren't properly checking that the type name was valid. diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index fa41cda6..2b4bd99c 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -517,34 +517,33 @@ public void end_inspect(const void *expr, const TypeInfo_t *type) __attribute__((nonnull)) public void test_value(const char *filename, int64_t start, int64_t end, const void *expr, const void *expected, const TypeInfo_t *type) { - Text_t expr_text = generic_as_text(expr, USE_COLOR, type); - Text_t expected_text = generic_as_text(expected, USE_COLOR, type); + if (generic_equal(expr, expected, type)) + return; - bool success = Text$equal_values(expr_text, expected_text); - if (!success) { - print_stacktrace(stderr, 2); - fprint(stderr, ""); - fflush(stderr); - - start_inspect(filename, start, end); - end_inspect(expr, type); - fflush(stdout); + print_stacktrace(stderr, 2); + fprint(stderr, ""); + fflush(stderr); - if (USE_COLOR) { - fprint(stderr, - "\n\x1b[31;7m ==================== TEST FAILED ==================== \x1b[0;1m\n\n" - "You expected: \x1b[m", expected_text, "\x1b[0m\n" - "\x1b[1m But I got:\x1b[m ", expr_text, "\n"); - } else { - fprint(stderr, - "\n==================== TEST FAILED ====================\n\n" - "You expected: ", expected_text, "\n" - " But I got: ", expr_text, "\n"); - } + start_inspect(filename, start, end); + end_inspect(expr, type); + fflush(stdout); - fflush(stderr); - raise(SIGABRT); + Text_t expr_text = generic_as_text(expr, USE_COLOR, type); + Text_t expected_text = generic_as_text(expected, USE_COLOR, type); + if (USE_COLOR) { + fprint(stderr, + "\n\x1b[31;7m ==================== TEST FAILED ==================== \x1b[0;1m\n\n" + "You expected: \x1b[m", expected_text, "\x1b[0m\n" + "\x1b[1m But I got:\x1b[m ", expr_text, "\n"); + } else { + fprint(stderr, + "\n==================== TEST FAILED ====================\n\n" + "You expected: ", expected_text, "\n" + " But I got: ", expr_text, "\n"); } + + fflush(stderr); + raise(SIGABRT); } public void say(Text_t text, bool newline) diff --git a/test/defer.tm b/test/defer.tm index 6c204851..8cab3122 100644 --- a/test/defer.tm +++ b/test/defer.tm @@ -6,8 +6,8 @@ func main() nums.insert(x) x = 999 - >> nums - = @[123] + >> nums[] + = [123] >> x = 999 diff --git a/test/lists.tm b/test/lists.tm index fef23f5d..f918b6f7 100644 --- a/test/lists.tm +++ b/test/lists.tm @@ -65,14 +65,14 @@ func main() >> list := @[10, 20] >> copy := list[] >> list.insert(30) - >> list - = @[10, 20, 30] + >> list[] + = [10, 20, 30] >> copy = [10, 20] >> list[1] = 999 - >> list - = @[999, 20, 30] + >> list[] + = [999, 20, 30] do >> list := &[10, 20, 30] @@ -88,19 +88,19 @@ func main() # Sorted function doesn't mutate original: >> nums.sorted() = [-20, 10, 30] - >> nums - = @[10, -20, 30] + >> nums[] + = [10, -20, 30] # Sort function does mutate in place: >> nums.sort() - >> nums - = @[-20, 10, 30] + >> nums[] + = [-20, 10, 30] # Custom sort functions: >> nums.sort(func(x,y:&Int) x.abs() <> y.abs()) - >> nums - = @[10, -20, 30] + >> nums[] + = [10, -20, 30] >> nums.sort(func(x,y:&Int) y[] <> x[]) - >> nums - = @[30, 10, -20] + >> nums[] + = [30, 10, -20] >> ["A", "B", "C"].sample(10, [1.0, 0.5, 0.0]) @@ -175,14 +175,14 @@ func main() >> nums := &[10, 20, 30, 40, 50] >> nums.pop() = 50? - >> nums - = &[10, 20, 30, 40] + >> nums[] + = [10, 20, 30, 40] >> nums.pop(2) = 20? - >> nums - = &[10, 30, 40] + >> nums[] + = [10, 30, 40] >> nums.clear() - >> nums - = &[] + >> nums[] + = [] >> nums.pop() = none diff --git a/test/sets.tm b/test/sets.tm index 85e53463..b30c2ce3 100644 --- a/test/sets.tm +++ b/test/sets.tm @@ -1,7 +1,8 @@ func main() - >> t1 := @|10, 20, 30, 10| - = @|10, 20, 30| + t1 := @|10, 20, 30, 10| + >> t1[] + = |10, 20, 30| >> t1.has(10) = yes >> t1.has(-999) @@ -29,11 +30,11 @@ func main() = no >> t1.add_all(t2) - >> t1 - = @|10, 20, 30, 40| + >> t1[] + = |10, 20, 30, 40| >> t1.remove_all(t2) - >> t1 - = @|10, 20| + >> t1[] + = |10, 20| >> |3, i for i in 5| = |3, 1, 2, 4, 5| diff --git a/test/structs.tm b/test/structs.tm index a58a9ef7..40c1b566 100644 --- a/test/structs.tm +++ b/test/structs.tm @@ -63,6 +63,7 @@ func main() >> @LinkedList(10, @LinkedList(20)) >> my_pass := Password("Swordfish") + = Password("Swordfish") >> "$my_pass" = "Password(...)" >> users_by_password := {my_pass="User1", Password("xxx")="User2"} diff --git a/test/tables.tm b/test/tables.tm index 2254a7a0..1f4244f9 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -59,8 +59,8 @@ func main() >> t3 := @{1=10, 2=20, 3=30} >> t3.remove(3) - >> t3 - = @{1=10, 2=20} + >> t3[] + = {1=10, 2=20} do >> plain := {1=10, 2=20, 3=30} @@ -85,8 +85,8 @@ func main() >> t4 := &{"one"= 1} >> t4["one"] = 999 >> t4["two"] = 222 - >> t4 - = &{"one"=999, "two"=222} + >> t4[] + = {"one"=999, "two"=222} do assert {1=1, 2=2} == {2=2, 1=1} @@ -114,5 +114,5 @@ func main() >> counter["y"] += 1 >> counter - >> counter - = &{"x"=10, "y"=1; default=0} + >> counter[] + = {"x"=10, "y"=1; default=0} |
