summaryrefslogtreecommitdiffhomepage
path: root/misc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'misc/tests')
-rw-r--r--misc/tests/cregex_test.c25
-rw-r--r--misc/tests/cspan_test.c38
-rw-r--r--misc/tests/ctest.h3
3 files changed, 34 insertions, 32 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;");
}
}
diff --git a/misc/tests/cspan_test.c b/misc/tests/cspan_test.c
index 5d46f579..ce267b14 100644
--- a/misc/tests/cspan_test.c
+++ b/misc/tests/cspan_test.c
@@ -9,11 +9,11 @@ CTEST(cspan, subdim) {
int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
intspan3 m = cspan_md(array, 2, 2, 3);
- for (size_t i = 0; i < m.shape[0]; ++i) {
+ for (int i = 0; i < m.shape[0]; ++i) {
intspan2 sub_i = cspan_submd3(&m, i);
- for (size_t j = 0; j < m.shape[1]; ++j) {
+ for (int j = 0; j < m.shape[1]; ++j) {
intspan sub_i_j = cspan_submd2(&sub_i, j);
- for (size_t k = 0; k < m.shape[2]; ++k) {
+ for (int k = 0; k < m.shape[2]; ++k) {
ASSERT_EQ(*cspan_at(&sub_i_j, k), *cspan_at(&m, i, j, k));
}
}
@@ -24,18 +24,18 @@ CTEST(cspan, slice) {
int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
intspan2 m1 = cspan_md(array, 3, 4);
- size_t sum1 = 0;
- for (size_t i = 0; i < m1.shape[0]; ++i) {
- for (size_t j = 0; j < m1.shape[1]; ++j) {
+ int sum1 = 0;
+ for (int i = 0; i < m1.shape[0]; ++i) {
+ for (int j = 0; j < m1.shape[1]; ++j) {
sum1 += *cspan_at(&m1, i, j);
}
}
intspan2 m2 = cspan_slice(intspan2, &m1, {c_ALL}, {2,4});
- size_t sum2 = 0;
- for (size_t i = 0; i < m2.shape[0]; ++i) {
- for (size_t j = 0; j < m2.shape[1]; ++j) {
+ int sum2 = 0;
+ for (int i = 0; i < m2.shape[0]; ++i) {
+ for (int j = 0; j < m2.shape[1]; ++j) {
sum2 += *cspan_at(&m2, i, j);
}
}
@@ -43,11 +43,12 @@ CTEST(cspan, slice) {
ASSERT_EQ(45, sum2);
}
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
CTEST(cspan, slice2) {
- c_auto (cstack_int, stack)
+ cstack_int stack = {0};
+ c_defer (cstack_int_drop(&stack))
{
c_forrange (i, 10*20*30)
cstack_int_push(&stack, i);
@@ -55,10 +56,10 @@ CTEST(cspan, slice2) {
intspan3 ms3 = cspan_md(stack.data, 10, 20, 30);
ms3 = cspan_slice(intspan3, &ms3, {1,4}, {3,7}, {20,24});
- size_t sum = 0;
- for (size_t i = 0; i < ms3.shape[0]; ++i) {
- for (size_t j = 0; j < ms3.shape[1]; ++j) {
- for (size_t k = 0; k < ms3.shape[2]; ++k) {
+ int sum = 0;
+ for (int i = 0; i < ms3.shape[0]; ++i) {
+ for (int j = 0; j < ms3.shape[1]; ++j) {
+ for (int k = 0; k < ms3.shape[2]; ++k) {
sum += *cspan_at(&ms3, i, j, k);
}
}
@@ -74,7 +75,7 @@ CTEST(cspan, slice2) {
#define i_type Tiles
-#define i_val intspan3
+#define i_key intspan3
#include <stc/cstack.h>
CTEST_FIXTURE(cspan_cube) {
@@ -112,10 +113,9 @@ CTEST_TEARDOWN(cspan_cube) {
CTEST_F(cspan_cube, slice3) {
- intptr_t n = cstack_int_size(&_self->stack);
- //printf("\ntiles: %zi, cells: %zi\n", Tiles_size(&_self->tiles), n);
+ long long n = cstack_int_size(&_self->stack);
+ long long sum = 0;
- int64_t sum = 0;
// iterate each 3d tile in sequence
c_foreach (i, Tiles, _self->tiles)
c_foreach (t, intspan3, *i.ref)
diff --git a/misc/tests/ctest.h b/misc/tests/ctest.h
index 373cda0e..6b1b1084 100644
--- a/misc/tests/ctest.h
+++ b/misc/tests/ctest.h
@@ -408,7 +408,8 @@ void assert_dbl_compare(const char* cmp, double exp, double real, double tol, co
void assert_pointers(const char* cmp, const void* exp, const void* real, const char* caller, int line) {
if ((exp == real) != (cmp[0] == '=')) {
- CTEST_ERR("%s:%d assertion failed (0x%02llx) %s (0x%02llx)", caller, line, (unsigned long long)exp , cmp, (unsigned long long)real);
+ CTEST_ERR("%s:%d assertion failed (0x%02llx) %s (0x%02llx)", caller, line,
+ (unsigned long long)(uintptr_t)exp , cmp, (unsigned long long)(uintptr_t)real);
}
}