Skip to content

Commit

Permalink
Added tests for choice
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Nov 24, 2017
1 parent 8299383 commit 793583e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/b6b_test_rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,35 @@ 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 {}}", 12) == B6B_ERR);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$choice a}", 11) == B6B_OK);
assert(b6b_as_str(interp.fg->_));
assert(interp.fg->_->slen == 1);
assert(strcmp(interp.fg->_->s, "a") == 0);
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
assert(b6b_call_copy(&interp, "{$choice {a b}}", 15) == B6B_OK);
assert(b6b_as_str(interp.fg->_));
assert(interp.fg->_->slen == 1);
assert((strcmp(interp.fg->_->s, "a") == 0) ||
(strcmp(interp.fg->_->s, "b") == 0));
b6b_interp_destroy(&interp);

assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE));
occ[0] = occ[1] = occ[2] = occ[3] = occ[4] = 0;
do {
assert(b6b_call_copy(&interp, "{$choice {0 1 2 3 4}}", 21) == B6B_OK);
assert(b6b_as_int(interp.fg->_));
assert(interp.fg->_->i >= 0);
assert(interp.fg->_->i <= 4);
++occ[interp.fg->_->i];
} while (!occ[0] || !occ[1] || !occ[2] || !occ[3] || !occ[4]);
b6b_interp_destroy(&interp);

return EXIT_SUCCESS;
}

0 comments on commit 793583e

Please sign in to comment.