Added string stripping functions
This commit is contained in:
35
tests/core.c
35
tests/core.c
@@ -6,8 +6,8 @@
|
||||
|
||||
static int int_eq(const void* x, const void* y) { return (*(int*)x == *(int*)y); }
|
||||
static void int_print(const void* x) { printf("'%i'", *((int*)x)); }
|
||||
static int string_eq(const void* x, const void* y) { return (strcmp(x, y) == 0); }
|
||||
static void string_print(const void* x) { printf("'%s'", (char*)x); }
|
||||
static int streq(const void* x, const void* y) { return (strcmp(x, y) == 0); }
|
||||
static void strprint(const void* x) { printf("'%s'", (char*)x); }
|
||||
|
||||
void test_ident(void) {
|
||||
|
||||
@@ -21,13 +21,13 @@ void test_ident(void) {
|
||||
free
|
||||
);
|
||||
|
||||
PT_ASSERT(mpc_test_pass(Ident, "test", "test", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_fail(Ident, " blah", "", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_pass(Ident, "anoth21er", "anoth21er", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_pass(Ident, "du__de", "du__de", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_fail(Ident, "some spaces", "", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_fail(Ident, "", "", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_fail(Ident, "18nums", "", string_eq, free, string_print));
|
||||
PT_ASSERT(mpc_test_pass(Ident, "test", "test", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_fail(Ident, " blah", "", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_pass(Ident, "anoth21er", "anoth21er", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_pass(Ident, "du__de", "du__de", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_fail(Ident, "some spaces", "", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_fail(Ident, "", "", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_fail(Ident, "18nums", "", streq, free, strprint));
|
||||
|
||||
mpc_delete(Ident);
|
||||
|
||||
@@ -69,7 +69,24 @@ void test_maths(void) {
|
||||
mpc_cleanup(4, Expr, Factor, Term, Maths);
|
||||
}
|
||||
|
||||
void test_strip(void) {
|
||||
|
||||
mpc_parser_t *Stripperl = mpc_apply(mpc_many(mpcf_strfold, mpc_any()), mpcf_strtriml);
|
||||
mpc_parser_t *Stripperr = mpc_apply(mpc_many(mpcf_strfold, mpc_any()), mpcf_strtrimr);
|
||||
mpc_parser_t *Stripper = mpc_apply(mpc_many(mpcf_strfold, mpc_any()), mpcf_strtrim);
|
||||
|
||||
PT_ASSERT(mpc_test_pass(Stripperl, " asdmlm dasd ", "asdmlm dasd ", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_pass(Stripperr, " asdmlm dasd ", " asdmlm dasd", streq, free, strprint));
|
||||
PT_ASSERT(mpc_test_pass(Stripper, " asdmlm dasd ", "asdmlm dasd", streq, free, strprint));
|
||||
|
||||
mpc_delete(Stripperl);
|
||||
mpc_delete(Stripperr);
|
||||
mpc_delete(Stripper);
|
||||
|
||||
}
|
||||
|
||||
void suite_core(void) {
|
||||
pt_add_test(test_ident, "Test Ident", "Suite Core");
|
||||
pt_add_test(test_maths, "Test Maths", "Suite Core");
|
||||
pt_add_test(test_strip, "Test Strip", "Suite Core");
|
||||
}
|
||||
|
Reference in New Issue
Block a user