summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/regex2.c4
-rw-r--r--examples/regex_match.c2
-rw-r--r--examples/splitstr.c44
-rw-r--r--examples/utf8replace_c.c3
-rw-r--r--include/stc/cregex.h4
-rw-r--r--include/stc/csview.h5
-rw-r--r--tests/cregex_test.c390
7 files changed, 164 insertions, 288 deletions
diff --git a/examples/regex2.c b/examples/regex2.c
index 30602444..f0869d24 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -14,7 +14,7 @@ int main()
{"!((abc|123)+)!", "!123abcabc!"}
};
- c_auto (cregex, re)
+ c_with (cregex re = cregex_init(), cregex_drop(&re))
c_forrange (i, c_arraylen(s))
{
int res = cregex_compile(&re, s[i].pattern, 0);
@@ -26,7 +26,7 @@ int main()
c_foreach_match (j, &re, s[i].input) {
c_forrange (k, cregex_captures(&re))
- printf(" submatch %d: %.*s\n", (int)k, c_ARGsv(j.ref[k]));
+ printf(" submatch %d: %.*s\n", (int)k, c_ARGsv(j.match[k]));
puts("");
}
}
diff --git a/examples/regex_match.c b/examples/regex_match.c
index 1e87affb..1e463104 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -22,7 +22,7 @@ int main()
// extract and convert all numbers in str to floats
c_foreach_match (i, &re, str)
- cstack_float_push(&vec, atof(i.ref->str));
+ cstack_float_push(&vec, atof(i.match[0].str));
c_foreach (i, cstack_float, vec)
printf(" %g\n", *i.ref);
diff --git a/examples/splitstr.c b/examples/splitstr.c
index c483fbe0..f2a1dad1 100644
--- a/examples/splitstr.c
+++ b/examples/splitstr.c
@@ -1,39 +1,23 @@
#include <stdio.h>
+#define i_implement // cstr functions
+#include <stc/cstr.h>
#include <stc/csview.h>
+#include <stc/cregex.h>
-void print_split(csview input, csview sep)
+int main()
{
- size_t pos = 0;
- while (pos <= input.size) {
- csview tok = csview_token(input, sep, &pos);
- // print non-null-terminated csview
- printf("[%.*s]\n", c_ARGsv(tok));
- }
-}
+ puts("Split with c_foreach_token (csview):");
-#include <stc/cstr.h>
-#define i_val_str
-#include <stc/cstack.h>
+ c_foreach_token (i, "Hello World C99!", " ")
+ printf("'%.*s'\n", c_ARGsv(i.token));
-cstack_str string_split(csview input, csview sep)
-{
- cstack_str out = cstack_str_init();
- size_t pos = 0;
- while (pos <= input.size) {
- csview tok = csview_token(input, sep, &pos);
- cstack_str_push(&out, cstr_from_sv(tok));
- }
- return out;
-}
-int main()
-{
- print_split(c_sv("//This is a//double-slash//separated//string"), c_sv("//"));
- puts("");
- print_split(c_sv("This has no matching separator"), c_sv("xx"));
- puts("");
+ puts("\nSplit with c_foreach_match (regex):");
- c_with (cstack_str s = string_split(c_sv("Split,this,,string,now,"), c_sv(",")), cstack_str_drop(&s))
- c_foreach (i, cstack_str, s)
- printf("[%s]\n", cstr_str(i.ref));
+ c_with (cregex re = cregex_from("[^ ]+", 0), cregex_drop(&re))
+ c_foreach_match (i, &re, " Hello World C99! ")
+ printf("'%.*s'\n", c_ARGsv(i.match[0]));
}
+
+#include "../src/cregex.c"
+#include "../src/utf8code.c"
diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c
index e7659cfd..b43aab6f 100644
--- a/examples/utf8replace_c.c
+++ b/examples/utf8replace_c.c
@@ -8,8 +8,7 @@ int main() {
printf("%s\n", cstr_str(&hello));
/* replace second smiley at utf8 codepoint pos 7 */
- cstr_u8_replace(&hello, cstr_find(&hello, "๐Ÿ˜€rld"), 1, c_sv("๐Ÿจ"));
-
+ cstr_u8_replace(&hello, cstr_u8_to_pos(&hello, 7), 1, c_sv("๐Ÿจ"));
printf("%s\n", cstr_str(&hello));
cstr_replace(&hello, "๐Ÿจ", "รธ", 1);
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index 4812bff2..f0dd13aa 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -73,12 +73,12 @@ typedef struct {
typedef struct {
const cregex* re;
const char* input;
- csview ref[cre_MAXCAPTURES];
+ csview match[cre_MAXCAPTURES];
} cregex_iter;
#define c_foreach_match(it, Re, Input) \
for (cregex_iter it = {Re, Input}; \
- cregex_find(it.input, it.re, it.ref, cre_m_next) == cre_success;)
+ cregex_find(it.input, it.re, it.match, cre_m_next) == cre_success;)
static inline
cregex cregex_init(void) {
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 555dd538..bfbf1c61 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -103,6 +103,11 @@ STC_API csview csview_substr_ex(csview sv, intptr_t pos, size_t n);
STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
STC_API csview csview_token(csview sv, csview sep, size_t* start);
+#define c_foreach_token(it, input, sep) \
+ for (struct { csview token, _sep, _inp; size_t start; } \
+ it = {.token=csview_from(input), ._sep=csview_from(sep), ._inp=it.token, .start=0} \
+ ; it.start <= it._inp.size && (it.token = csview_token(it._inp, it._sep, &it.start)).str ; )
+
/* csview interaction with cstr: */
#ifdef CSTR_H_INCLUDED
diff --git a/tests/cregex_test.c b/tests/cregex_test.c
index c17f1dd2..7cd87e89 100644
--- a/tests/cregex_test.c
+++ b/tests/cregex_test.c
@@ -2,38 +2,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
-//#include <check.h>
+#include <stc/csview.h>
+#include <stc/stctest.h>
#include <stc/cregex.h>
#define START_TEST(f) void f(void)
#define END_TEST
-#define ck_assert(x) assert(x)
-#define ck_assert_uint_ne(a, b) assert(a != b)
-#define ck_assert_uint_eq(a, b) if (!((a) == (b))) printf("%u == %u: ", a, b), assert((a) == (b))
-#define ck_assert_int_ne(a, b) assert(a != b)
-#define ck_assert_int_eq(a, b) assert(a == b)
-#define ck_assert_ptr_ne(a, b) assert(a != b)
-#define ck_assert_ptr_eq(a, b) assert(a == b)
-
+#define M_START(re, m) ((m).str - (re).input)
+#define M_END(re, m) (M_START(re, m) + (m).size)
START_TEST(compile_match_char)
{
- cregex re = cregex_new("รคsdf");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- cregex_find match;
- ck_assert(cregex_find(&re, "รคsdf", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 5); // รค is two bytes wide
+ cregex re = cregex_from("รคsdf", 0);
+ EXPECT_EQ(re.error, 0);
- ck_assert(cregex_find(&re, "zรคsdf", &match));
- ck_assert_uint_eq(match.start, 1);
- ck_assert_uint_eq(match.end, 6);
+ csview match;
+ EXPECT_TRUE(cregex_find("รคsdf", &re, &match, 0));
+ EXPECT_EQ(M_START(re, match), 0);
+ EXPECT_EQ(M_END(re, match), 5); // รค is two bytes wide
- ck_assert(cregex_find(&re, "รคsdf", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 5);
+ EXPECT_EQ(cregex_find("zรคsdf", &re, &match, 0), 1);
+ EXPECT_EQ(M_START(re, match), 1);
+ EXPECT_EQ(M_END(re, match), 6);
cregex_drop(&re);
}
@@ -41,16 +32,16 @@ END_TEST
START_TEST(compile_match_anchors)
{
- cregex re[1] = {cregex_new("^รคs.f$")};
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ cregex re = cregex_from("^รคs.f$", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(re, "รคsdf", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 5);
+ csview match;
+ EXPECT_TRUE(cregex_find("รคsdf", &re, &match, 0));
+ EXPECT_EQ(M_START(re, match), 0);
+ EXPECT_EQ(M_END(re, match), 5);
- ck_assert(cregex_find(re, "รคsโ™ฅf", &match));
- ck_assert(cregex_find(re, "รคsรถf", &match));
+ EXPECT_TRUE(cregex_is_match("รคsโ™ฅf", &re));
+ EXPECT_TRUE(cregex_is_match("รคsรถf", &re));
cregex_drop(re);
}
@@ -59,90 +50,48 @@ END_TEST
START_TEST(compile_match_quantifiers)
{
c_auto (cregex, re) {
- re = cregex_new("รค+");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ re = cregex_from("รค+", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(&re, "รครคb", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 4);
+ csview match;
+ EXPECT_EQ(cregex_find("รครคb", &re, &match, 0), 1);
+ EXPECT_EQ(M_START(re, match), 0);
+ EXPECT_EQ(M_END(re, match), 4);
- ck_assert(cregex_find(&re, "bรคbb", &match));
- ck_assert_uint_eq(match.start, 1);
- ck_assert_uint_eq(match.end, 3);
+ EXPECT_EQ(cregex_find("bรคbb", &re, &match, 0), 1);
+ EXPECT_EQ(M_START(re, match), 1);
+ EXPECT_EQ(M_END(re, match), 3);
- ck_assert(!cregex_find(&re, "bbb", &match));
+ EXPECT_FALSE(cregex_find("bbb", &re, &match, 0));
}
c_auto (cregex, re) {
- re = cregex_new("bรค*");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- cregex_find match;
- ck_assert(cregex_find(&re, "bรครคb", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 5);
+ re = cregex_from("bรค*", 0);
+ EXPECT_EQ(re.error, 0);
- ck_assert(cregex_find(&re, "bรคbb", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 3);
+ csview match;
+ EXPECT_EQ(cregex_find("bรครคb", &re, &match, 0), 1);
+ EXPECT_EQ(M_START(re, match), 0);
+ EXPECT_EQ(M_END(re, match), 5);
- ck_assert(cregex_find(&re, "bbb", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 1);
- }
-}
-END_TEST
+ EXPECT_EQ(cregex_find("bรคbb", &re, &match, 0), 1);
+ EXPECT_EQ(M_START(re, match), 0);
+ EXPECT_EQ(M_END(re, match), 3);
-START_TEST(compile_match_complex_quants)
-{
- c_auto (cregex, re1, re2, re3, re4)
- {
- re1 = cregex_new("รค{1,3}");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- re2 = cregex_new("รค{1}");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- re3 = cregex_new("รค{,}");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- re4 = cregex_new("รค{,3}");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- cregex_find match;
- ck_assert(cregex_find(&re1, "รครคb", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 4);
- ck_assert(cregex_find(&re1, "รครครคb", &match));
- ck_assert(cregex_find(&re1, "รคb", &match));
- ck_assert(!cregex_find(&re1, "b", &match));
-
- ck_assert(cregex_find(&re2, "รครค", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 2);
- ck_assert(cregex_find(&re2, "bbรคb", &match));
- ck_assert(!cregex_find(&re2, "bbbb", &match));
-
- ck_assert(cregex_find(&re3, "รครครครครครครครครครคb", &match));
- ck_assert_uint_eq(match.start, 0);
- ck_assert_uint_eq(match.end, 20);
- ck_assert(cregex_find(&re3, "b", &match));
-
- ck_assert(cregex_find(&re4, "bรค", &match));
- ck_assert(cregex_find(&re4, "bรครค", &match));
- ck_assert(cregex_find(&re4, "bรครครค", &match));
+ EXPECT_EQ(cregex_find("bbb", &re, &match, 0), 1);
+ EXPECT_EQ(M_START(re, match), 0);
+ EXPECT_EQ(M_END(re, match), 1);
}
}
END_TEST
START_TEST(compile_match_escaped_chars)
{
- cregex re = cregex_new("\\n\\r\\t\\{");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ cregex re = cregex_from("\\n\\r\\t\\{", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(&re, "\n\r\t{", &match));
- ck_assert(!cregex_find(&re, "\n\r\t", &match));
+ csview match;
+ EXPECT_EQ(cregex_find("\n\r\t{", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("\n\r\t", &re, &match, 0), 0);
cregex_drop(&re);
}
@@ -152,24 +101,24 @@ START_TEST(compile_match_class_simple)
{
c_auto (cregex, re1, re2, re3)
{
- re1 = cregex_new("\\s");
- ck_assert_int_eq(cregex_error(), cregex_OK);
- re2 = cregex_new("\\w");
- ck_assert_int_eq(cregex_error(), cregex_OK);
- re3 = cregex_new("\\D");
- ck_assert_int_eq(cregex_error(), cregex_OK);
-
- cregex_find match;
- ck_assert(cregex_find(&re1, " ", &match));
- ck_assert(cregex_find(&re1, "\r", &match));
- ck_assert(cregex_find(&re1, "\n", &match));
-
- ck_assert(cregex_find(&re2, "a", &match));
- ck_assert(cregex_find(&re2, "0", &match));
- ck_assert(cregex_find(&re2, "_", &match));
-
- ck_assert(cregex_find(&re3, "k", &match));
- ck_assert(!cregex_find(&re3, "0", &match));
+ re1 = cregex_from("\\s", 0);
+ EXPECT_EQ(re1.error, 0);
+ re2 = cregex_from("\\w", 0);
+ EXPECT_EQ(re2.error, 0);
+ re3 = cregex_from("\\D", 0);
+ EXPECT_EQ(re3.error, 0);
+
+ csview match;
+ EXPECT_EQ(cregex_find(" ", &re1, &match, 0), 1);
+ EXPECT_EQ(cregex_find("\r", &re1, &match, 0), 1);
+ EXPECT_EQ(cregex_find("\n", &re1, &match, 0), 1);
+
+ EXPECT_EQ(cregex_find("a", &re2, &match, 0), 1);
+ EXPECT_EQ(cregex_find("0", &re2, &match, 0), 1);
+ EXPECT_EQ(cregex_find("_", &re2, &match, 0), 1);
+
+ EXPECT_EQ( cregex_find("k", &re3, &match, 0), 1);
+ EXPECT_EQ(cregex_find("0", &re3, &match, 0), 0);
}
}
END_TEST
@@ -178,32 +127,32 @@ START_TEST(compile_match_or)
{
c_auto (cregex, re, re2)
{
- re = cregex_new("as|df");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ re = cregex_from("as|df", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(&re, "as", &match));
- ck_assert(cregex_find(&re, "df", &match));
+ csview match;
+ EXPECT_EQ(cregex_find("as", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("df", &re, &match, 0), 1);
- re2 = cregex_new("(as|df)");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ re2 = cregex_from("(as|df)", 0);
+ EXPECT_EQ(re2.error, 0);
- ck_assert(cregex_find(&re2, "as", &match));
- ck_assert(cregex_find(&re2, "df", &match));
+ EXPECT_EQ(cregex_find(&re2, "as", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find(&re2, "df", &re, &match, 0), 1);
}
}
END_TEST
START_TEST(compile_match_class_complex_0)
{
- cregex re = cregex_new("[asdf]");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ cregex re = cregex_from("[asdf]", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(&re, "a", &match));
- ck_assert(cregex_find(&re, "s", &match));
- ck_assert(cregex_find(&re, "d", &match));
- ck_assert(cregex_find(&re, "f", &match));
+ csview match;
+ EXPECT_EQ(cregex_find("a", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("s", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("d", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("f", &re, &match, 0), 1);
cregex_drop(&re);
}
@@ -211,15 +160,15 @@ END_TEST
START_TEST(compile_match_class_complex_1)
{
- cregex re = cregex_new("[a-zรค0-9รถA-Z]");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ cregex re = cregex_from("[a-zรค0-9รถA-Z]", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(&re, "a", &match));
- ck_assert(cregex_find(&re, "5", &match));
- ck_assert(cregex_find(&re, "A", &match));
- ck_assert(cregex_find(&re, "รค", &match));
- ck_assert(cregex_find(&re, "รถ", &match));
+ csview match;
+ EXPECT_EQ(cregex_find("a", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("5", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("A", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("รค", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("รถ", &re, &match, 0), 1);
cregex_drop(&re);
}
@@ -227,53 +176,34 @@ END_TEST
START_TEST(compile_match_cap)
{
- cregex re = cregex_new("(abc)d");
- ck_assert_int_eq(cregex_error(), cregex_OK);
+ cregex re = cregex_from("(abc)d", 0);
+ EXPECT_EQ(re.error, 0);
- cregex_find match;
- ck_assert(cregex_find(&re, "abcd", &match));
- ck_assert(cregex_find(&re, "llljabcdkk", &match));
- ck_assert(!cregex_find(&re, "abc", &match));
+ csview match;
+ EXPECT_EQ(cregex_find("abcd", &re, &match, 0)), 1;
+ EXPECT_EQ(cregex_find("llljabcdkk", &re, &match, 0), 1);
+ EXPECT_EQ(cregex_find("abc", &re, &match, 0), 0);
cregex_drop(&re);
}
END_TEST
-START_TEST(invalid_quantifier)
-{
- ck_assert_ptr_eq(cregex_new("+").nodes, NULL);
- ck_assert_int_eq(cregex_error(), cregex_EARLY_QUANTIFIER);
-}
-END_TEST
-
-/* Test that invalid utf8 sequences cause a
- * cregex_INVALID_UTF8 error */
-START_TEST(invalid_utf8)
-{
- char s1[3] = "รค";
- s1[1] = 65; // invalid continuation byte
-
- ck_assert_ptr_eq(cregex_new(s1).nodes, NULL);
- ck_assert_int_eq(cregex_error(), cregex_INVALID_UTF8);
-}
-END_TEST
-
START_TEST(search_all)
{
c_auto (cregex, re)
{
- re = cregex_new("ab");
- cregex_find m = {0};
- bool res;
+ re = cregex_from("ab", 0);
+ csview m = {0};
+ int res;
- res = cregex_find_next(&re, "ab,ab,ab", &m);
- ck_assert(res && m.start == 0);
- res = cregex_find_next(&re, "ab,ab,ab", &m);
- ck_assert(res && m.start == 3);
- res = cregex_find_next(&re, "ab,ab,ab", &m);
- ck_assert(res && m.start == 6);
- res = cregex_find_next(&re, "ab,ab,ab", &m);
- ck_assert(!res);
+ res = cregex_find("ab,ab,ab", &m, cre_m_next);
+ EXPECT_TRUE(res==1 && M_START(re, m) == 0);
+ res = cregex_find("ab,ab,ab", &m, cre_m_next);
+ EXPECT_TRUE(res==1 && M_START(re, m) == 3);
+ res = cregex_find("ab,ab,ab", &m, cre_m_next);
+ EXPECT_TRUE(res==1 && M_START(re, m) == 6);
+ res = cregex_find("ab,ab,ab", &m, cre_m_next);
+ EXPECT_NE(res, 1);
}
}
END_TEST
@@ -281,8 +211,8 @@ END_TEST
START_TEST(captures_len)
{
c_auto (cregex, re) {
- cregex re = cregex_new("(ab(cd))(ef)");
- ck_assert_uint_eq(cregex_capture_size(re), 3);
+ cregex re = cregex_from("(ab(cd))(ef)", 0);
+ EXPECT_EQ(cregex_captures(&re), 3);
}
}
END_TEST
@@ -290,83 +220,41 @@ END_TEST
START_TEST(captures_cap)
{
c_auto (cregex, re) {
- re = cregex_new("(ab)((cd)+)");
- ck_assert_uint_eq(cregex_capture_size(re), 3);
-
- cregex_find match;
- ck_assert(cregex_find(&re, "xxabcdcde", &match));
-
- cregex_find cap0, cap1, cap2;
- cregex_capture(&re, 0, &cap0);
- cregex_capture(&re, 1, &cap1);
- cregex_capture(&re, 2, &cap2);
-
- ck_assert_uint_eq(cap0.start, 2);
- ck_assert_uint_eq(cap0.end, 8);
- ck_assert_uint_eq(cap1.start, 2);
- ck_assert_uint_eq(cap1.end, 4);
- ck_assert_uint_eq(cap2.start, 4);
- ck_assert_uint_eq(cap2.end, 8);
-
- ck_assert(!cregex_findes(&re, "abcdcde"));
- ck_assert(cregex_findes(&re, "abcdcdcd"));
+ re = cregex_from("(ab)((cd)+)", 0);
+ EXPECT_EQ(cregex_captures(&re), 3);
+
+ csview cap[5];
+ EXPECT_EQ(cregex_find("xxabcdcde", &re, cap, 0), 1);
+ EXPECT_TRUE(csview_equals(cap.match[0], c_sv("abcdcd")));
+ /*
+ EXPECT_EQ(cap0.end, 8);
+ EXPECT_EQ(cap1.start, 2);
+ EXPECT_EQ(cap1.end, 4);
+ EXPECT_EQ(cap2.start, 4);
+ EXPECT_EQ(cap2.end, 8);
+ */
+ EXPECT_FALSE(cregex_is_match("abcdcde", &re));
+ EXPECT_TRUE(cregex_is_match("abcdcdcd", &re));
}
}
END_TEST
-/*
-Suite *cregex_test_suite(void)
-{
- Suite *ret = suite_create("mregexp");
- TCase *tcase = tcase_create("mregexp");
-
- tcase_add_test(tcase, compile_match_char);
- tcase_add_test(tcase, invalid_utf8);
- tcase_add_test(tcase, compile_match_anchors);
- tcase_add_test(tcase, compile_match_quantifiers);
- tcase_add_test(tcase, invalid_quantifier);
- tcase_add_test(tcase, compile_match_complex_quants);
- tcase_add_test(tcase, compile_match_escaped_chars);
- tcase_add_test(tcase, compile_match_class_simple);
- tcase_add_test(tcase, compile_match_class_complex_0);
- tcase_add_test(tcase, compile_match_class_complex_1);
- tcase_add_test(tcase, compile_match_cap);
- tcase_add_test(tcase, search_all);
- //tcase_add_test(tcase, captures_len);
- //tcase_add_test(tcase, captures_cap);
- tcase_add_test(tcase, compile_match_or);
-
- suite_add_tcase(ret, tcase);
- return ret;
-}
-
-int main(void)
-{
- SRunner *sr = srunner_create(cregex_test_suite());
- srunner_run_all(sr, CK_NORMAL);
- int fails = srunner_ntests_failed(sr);
- srunner_free(sr);
- return fails ? EXIT_FAILURE : EXIT_SUCCESS;
-}
-*/
int main()
{
- compile_match_char();
- invalid_utf8();
- compile_match_anchors();
- compile_match_quantifiers();
- invalid_quantifier();
- compile_match_complex_quants();
- compile_match_escaped_chars();
- compile_match_class_simple();
- compile_match_class_complex_0();
- compile_match_class_complex_1();
- compile_match_cap();
- search_all();
- //captures_len();
- //captures_cap();
- compile_match_or();
- printf("All tests succesful.\n");
+ RUN_TEST(compile_match_char);
+ RUN_TEST(compile_match_anchors);
+ RUN_TEST(compile_match_quantifiers);
+ RUN_TEST(compile_match_escaped_chars);
+ RUN_TEST(compile_match_class_simple);
+ RUN_TEST(compile_match_class_complex_0);
+ RUN_TEST(compile_match_class_complex_1);
+ RUN_TEST(compile_match_cap);
+ RUN_TEST(search_all);
+ RUN_TEST(captures_len);
+ RUN_TEST(captures_cap);
+ RUN_TEST(compile_match_or);
+ return REPORT_TESTS();
}
-#endif \ No newline at end of file
+#endif
+