Skip to content

Commit

Permalink
test::eq/ne/gt syntax (#1928)
Browse files Browse the repository at this point in the history
* test::eq/ne/gt syntax

* renamed @almost to test::eq_approx
  • Loading branch information
alexveden authored Feb 5, 2025
1 parent ef72e19 commit 3a502fe
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 92 deletions.
30 changes: 15 additions & 15 deletions lib/std/core/test.c3
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ fn double! divide(int a, int b)

fn void! test_div() @test
{
test::is_equal(2, divide(6, 3)!);
test::is_not_equal(1, 2);
test::is_almost_equal(m::divide(1, 3)!, 0.333, places: 3);
test::is_greater_equal(3, 3);
test::is_greater(2, divide(3, 3)!);
test::is_less(2, 3);
test::is_less_equal(2, 3);
test::eq(2, divide(6, 3)!);
test::ne(1, 2);
test::ge(3, 3);
test::gt(2, divide(3, 3)!);
test::lt(2, 3);
test::le(2, 3);
test::eq_approx(m::divide(1, 3)!, 0.333, places: 3);
test::@check(2 == 2, "divide: %d", divide(6, 3)!);
test::@error(m::divide(3, 0), MathError.DIVISION_BY_ZERO);
}
Expand All @@ -50,7 +50,7 @@ import std::math, std::io, libc;
@require runtime::test_context != null "Only allowed in @test functions"
@require setup_fn != null "setup_fn must always be set"
*>
macro setup(TestFn setup_fn, TestFn teardown_fn = null)
macro @setup(TestFn setup_fn, TestFn teardown_fn = null)
{
runtime::test_context.setup_fn = setup_fn;
runtime::test_context.teardown_fn = teardown_fn;
Expand Down Expand Up @@ -108,7 +108,7 @@ macro @error(#funcresult, anyfault error_expected)
@param right `right argument of any comparable type`
@require runtime::test_context != null "Only allowed in @test functions"
*>
macro is_equal(left, right)
macro eq(left, right)
{
if (!equals(left, right))
{
Expand All @@ -127,7 +127,7 @@ macro is_equal(left, right)
@require delta >= 0, delta <= 1 "delta must be a small number"
@require runtime::test_context != null "Only allowed in @test functions"
*>
fn void is_almost_equal(double left, double right, uint places = 7, double delta = 0, bool equal_nan = true)
macro void eq_approx(double left, double right, uint places = 7, double delta = 0, bool equal_nan = true)
{
double diff = left - right;
double eps = delta;
Expand All @@ -147,7 +147,7 @@ fn void is_almost_equal(double left, double right, uint places = 7, double delta
@param right `right argument of any comparable type`
@require runtime::test_context != null "Only allowed in @test functions"
*>
macro void is_not_equal(left, right)
macro void ne(left, right)
{
if (equals(left, right))
{
Expand All @@ -162,7 +162,7 @@ macro void is_not_equal(left, right)
@param right `right argument of any comparable type`
@require runtime::test_context != null "Only allowed in @test functions"
*>
macro is_greater(left, right)
macro gt(left, right)
{
if (!builtin::greater(left, right))
{
Expand All @@ -177,7 +177,7 @@ macro is_greater(left, right)
@param right `right argument of any comparable type`
@require runtime::test_context != null "Only allowed in @test functions"
*>
macro is_greater_equal(left, right)
macro ge(left, right)
{
if (!builtin::greater_eq(left, right))
{
Expand All @@ -192,7 +192,7 @@ macro is_greater_equal(left, right)
@param right `right argument of any comparable type`
@require runtime::test_context != null "Only allowed in @test functions"
*>
macro is_less(left, right)
macro lt(left, right)
{
if (!builtin::less(left, right))
{
Expand All @@ -207,7 +207,7 @@ macro is_less(left, right)
@param right `right argument of any comparable type`
@require runtime::test_context != null "Only allowed in @test functions"
*>
macro is_less_equal(left, right)
macro le(left, right)
{
if (!builtin::less_eq(left, right))
{
Expand Down
4 changes: 2 additions & 2 deletions test/unit/regression/ct_slice.c3
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn void slice_bytes()
fn void slice_string()
{
String $a = "abcd";
test::is_equal($a, "abcd");
test::eq($a, "abcd");
var $c = $a[1:0];
String c = $c;
assert($c == "");
Expand All @@ -35,4 +35,4 @@ fn void slice_untyped()
assert(v3 == String[1] { "hello" });
int[] v4 = $v[0:1];
assert(v4 == int[] { 1 });
}
}
Loading

0 comments on commit 3a502fe

Please sign in to comment.