Skip to content

Commit

Permalink
Improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Nov 24, 2017
1 parent 910c1a8 commit 0c357a6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/b6b_test_cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,16 @@ int main()
assert(b6b_as_float(o));
assert(o->f == 1339.333);

b6b_unref(b6b_list_pop(o, b6b_list_first(o)));
b6b_unref(s);
assert(b6b_list_empty(o));

s = b6b_str_copy("123\0abc", 7);
assert(s);
assert(b6b_list_add(o, s));
assert(!b6b_as_float(o));
b6b_unref(s);

b6b_unref(o);

return EXIT_SUCCESS;
Expand Down
4 changes: 4 additions & 0 deletions tests/b6b_test_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ int main()
{
struct b6b_interp interp;

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$dict.get {a b c d}}", 21) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$dict.get {a b c d} c}", 23) == B6B_OK);
assert(b6b_as_str(interp.fg->_));
Expand Down
24 changes: 23 additions & 1 deletion tests/b6b_test_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <limits.h>

#include <b6b.h>

int main()
{
struct b6b_interp interp;
int occ[5] = {0, 0, 0, 0, 0};
char stmt[128];
int len, occ[5] = {0, 0, 0, 0, 0};

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$randint 1 10}", 15) == B6B_OK);
Expand Down Expand Up @@ -56,6 +59,21 @@ int main()
assert(b6b_call_copy(&interp, "{$randint -8 -10}", 17) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
len = sprintf(stmt, "{$randint %d %d}", INT_MIN, INT_MAX);
assert(b6b_call_copy(&interp, stmt, (size_t)len) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
len = sprintf(stmt, "{$randint %lld 0}", (long long)INT_MIN - 1);
assert(b6b_call_copy(&interp, stmt, (size_t)len) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
len = sprintf(stmt, "{$randint 0 %llu}", (unsigned long long)INT_MAX + 1);
assert(b6b_call_copy(&interp, stmt, (size_t)len) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
do {
assert(b6b_call_copy(&interp, "{$randint -2 2}", 15) == B6B_OK);
Expand All @@ -76,6 +94,10 @@ int main()
} while (!occ[1] || !occ[2]);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$choice}", 9) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$choice {}}", 12) == B6B_ERR);
b6b_interp_destroy(&interp);
Expand Down

0 comments on commit 0c357a6

Please sign in to comment.