summaryrefslogtreecommitdiffhomepage
path: root/misc/tests/cregex_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/tests/cregex_test.c')
-rw-r--r--misc/tests/cregex_test.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/misc/tests/cregex_test.c b/misc/tests/cregex_test.c
index aa4b2a65..a83b7593 100644
--- a/misc/tests/cregex_test.c
+++ b/misc/tests/cregex_test.c
@@ -1,9 +1,10 @@
-#define i_extern
+#define i_import
#include <stc/cregex.h>
#include <stc/csview.h>
+#include <stc/algo/raii.h>
#include "ctest.h"
-#define M_START(m) ((m).str - inp)
+#define M_START(m) ((m).buf - inp)
#define M_END(m) (M_START(m) + (m).size)
@@ -14,7 +15,7 @@ CTEST(cregex, compile_match_char)
ASSERT_EQ(re.error, 0);
csview match;
- ASSERT_EQ(cregex_find(&re, inp="äsdf", &match, CREG_M_FULLMATCH), CREG_OK);
+ ASSERT_EQ(cregex_find(&re, inp="äsdf", &match, CREG_FULLMATCH), CREG_OK);
ASSERT_EQ(M_START(match), 0);
ASSERT_EQ(M_END(match), 5); // ä is two bytes wide
@@ -192,14 +193,14 @@ CTEST(cregex, search_all)
int res;
ASSERT_EQ(re.error, CREG_OK);
inp="ab,ab,ab";
- res = cregex_find(&re, inp, &m, CREG_M_NEXT);
+ res = cregex_find(&re, inp, &m, CREG_NEXT);
ASSERT_EQ(M_START(m), 0);
- res = cregex_find(&re, inp, &m, CREG_M_NEXT);
+ res = cregex_find(&re, inp, &m, CREG_NEXT);
ASSERT_EQ(res, CREG_OK);
ASSERT_EQ(M_START(m), 3);
- res = cregex_find(&re, inp, &m, CREG_M_NEXT);
+ res = cregex_find(&re, inp, &m, CREG_NEXT);
ASSERT_EQ(M_START(m), 6);
- res = cregex_find(&re, inp, &m, CREG_M_NEXT);
+ res = cregex_find(&re, inp, &m, CREG_NEXT);
ASSERT_NE(res, CREG_OK);
}
}
@@ -208,7 +209,7 @@ CTEST(cregex, captures_len)
{
c_auto (cregex, re) {
re = cregex_from("(ab(cd))(ef)");
- ASSERT_EQ(cregex_captures(&re), 4);
+ ASSERT_EQ(cregex_captures(&re), 3);
}
}
@@ -217,7 +218,7 @@ CTEST(cregex, captures_cap)
const char* inp;
c_auto (cregex, re) {
re = cregex_from("(ab)((cd)+)");
- ASSERT_EQ(cregex_captures(&re), 4);
+ ASSERT_EQ(cregex_captures(&re), 3);
csview cap[5];
ASSERT_EQ(cregex_find(&re, inp="xxabcdcde", cap), CREG_OK);
@@ -237,7 +238,7 @@ CTEST(cregex, captures_cap)
static bool add_10_years(int i, csview match, cstr* out) {
if (i == 1) { // group 1 matches year
int year;
- sscanf(match.str, "%4d", &year); // scan 4 chars only
+ sscanf(match.buf, "%4d", &year); // scan 4 chars only
cstr_printf(out, "%04d", year + 10);
return true;
}
@@ -272,14 +273,14 @@ CTEST(cregex, replace)
// Compile RE separately
re = cregex_from(pattern);
- ASSERT_EQ(cregex_captures(&re), 4);
+ ASSERT_EQ(cregex_captures(&re), 3);
// European date format.
cstr_take(&str, cregex_replace(&re, input, "$3.$2.$1"));
ASSERT_STREQ(cstr_str(&str), "start date: 31.12.2015, end date: 28.02.2022");
// Strip out everything but the matches
- cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, CREG_R_STRIP));
+ cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, CREG_STRIP));
ASSERT_STREQ(cstr_str(&str), "31.12.2015;28.02.2022;");
}
}