assertions_test.j
use convert;
use testing;
def struct Point { x as int, y as int };
func notANumber() { convert.toInt("abc"); }
func half(n as int) {
if ($n % 2 != 0) {
throw Error{kind: "value", message: "odd"};
}
return $n // 2;
}
func testAllSeven() {
testing.assertEqual([1, 2, 3], [1, 2, 3]);
testing.assertEqual(Point{x: 1, y: 2}, Point{x: 1, y: 2});
testing.assertNotEqual({"a": 1}, {"a": 2});
testing.assertTrue(len("abc") == 3);
testing.assertFalse(len("") > 0);
testing.assertContains("hello world", "world");
testing.assertContains([1, 2, 3], 2);
testing.assertContains({"a": 1}, "a");
testing.assertThrows("notANumber", "runtime");
testing.assertThrowsArgs("half", [3], "value");
}