Skip to content

Commit

Permalink
Added assertions for <, <=, >, >= (integer types)
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Jul 19, 2024
1 parent 9e45933 commit b3b9367
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions include/carbon_should.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,62 @@
} \
}

#define carbon_should_be_lt(expected, actual) \
{ \
if ((int) (expected) <= (int) (actual)) { \
CARBON_ERROR("%s:%d :: FAILED -> got '%d >= %d', expected '%d < %d'", \
__FILE__, \
__LINE__, \
(int) (actual), \
(int) (expected), \
(int) (actual), \
(int) (expected)); \
return 0; \
} \
}

#define carbon_should_be_le(expected, actual) \
{ \
if ((int) (expected) < (int) (actual)) { \
CARBON_ERROR("%s:%d :: FAILED -> got '%d > %d', expected '%d <= %d'", \
__FILE__, \
__LINE__, \
(int) (actual), \
(int) (expected), \
(int) (actual), \
(int) (expected)); \
return 0; \
} \
}

#define carbon_should_be_gt(expected, actual) \
{ \
if ((int) (expected) >= (int) (actual)) { \
CARBON_ERROR("%s:%d :: FAILED -> got '%d <= %d', expected '%d > %d'", \
__FILE__, \
__LINE__, \
(int) (actual), \
(int) (expected), \
(int) (actual), \
(int) (expected)); \
return 0; \
} \
}

#define carbon_should_be_ge(expected, actual) \
{ \
if ((int) (expected) > (int) (actual)) { \
CARBON_ERROR("%s:%d :: FAILED -> got '%d < %d', expected '%d >= %d'", \
__FILE__, \
__LINE__, \
(int) (actual), \
(int) (expected), \
(int) (actual), \
(int) (expected)); \
return 0; \
} \
}

#define carbon_should_be_p(expected, actual) \
{ \
if ((void *) (expected) != (void *) (actual)) { \
Expand Down

0 comments on commit b3b9367

Please sign in to comment.