mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
split out unit_test/test_mlrregex from unit_test/test_mlrutil
This commit is contained in:
parent
7396b40cf7
commit
e3f869fc21
5 changed files with 109 additions and 63 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -5,6 +5,7 @@ mlrp
|
|||
mlr-unit-tester
|
||||
test-argparse
|
||||
test-mlrutil
|
||||
test-mlrregex
|
||||
test-string-builder
|
||||
test-byte-readers
|
||||
test-peek-file-reader
|
||||
|
|
@ -66,6 +67,7 @@ test_byte_readers
|
|||
test_join_bucket_keeper
|
||||
test_lrec
|
||||
test_mlrutil
|
||||
test_mlrregex
|
||||
test_multiple_containers
|
||||
test_parse_trie
|
||||
test_peek_file_reader
|
||||
|
|
|
|||
|
|
@ -137,6 +137,12 @@ TEST_MULTIPLE_CONTAINERS_SRCS = \
|
|||
unit_test/test_multiple_containers.c
|
||||
|
||||
TEST_MLRUTIL_SRCS = \
|
||||
lib/mlr_globals.c \
|
||||
lib/mlrutil.c \
|
||||
lib/string_builder.c \
|
||||
unit_test/test_mlrutil.c
|
||||
|
||||
TEST_MLRREGEX_SRCS = \
|
||||
lib/mlr_globals.c \
|
||||
lib/mlrutil.c \
|
||||
lib/mlrregex.c \
|
||||
|
|
@ -263,8 +269,9 @@ mlrp: .always dsls
|
|||
# ================================================================
|
||||
tests: unit-test reg-test
|
||||
|
||||
unit-test: test-mlrutil test-argparse test-byte-readers test-peek-file-reader test-parse-trie test-lrec test-multiple-containers test-string-builder test-lrec-evaluators test-join-bucket-keeper
|
||||
unit-test: test-mlrutil test-mlrregex test-argparse test-byte-readers test-peek-file-reader test-parse-trie test-lrec test-multiple-containers test-string-builder test-lrec-evaluators test-join-bucket-keeper
|
||||
./test-mlrutil
|
||||
./test-mlrregex
|
||||
./test-argparse
|
||||
./test-byte-readers
|
||||
./test-peek-file-reader
|
||||
|
|
@ -307,6 +314,9 @@ test-multiple-containers: .always
|
|||
test-mlrutil: .always
|
||||
$(CCDEBUG) -D__TEST_MLRUTIL_MAIN__ $(TEST_MLRUTIL_SRCS) -o test-mlrutil
|
||||
|
||||
test-mlrregex: .always
|
||||
$(CCDEBUG) -D__TEST_MLRREGEX_MAIN__ $(TEST_MLRREGEX_SRCS) -o test-mlrregex
|
||||
|
||||
test-string-builder: .always
|
||||
$(CCDEBUG) -D__TEST_STRING_BUILDER_MAIN__ $(TEST_STRING_BUILDER_SRCS) -o test-string-builder
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
TESTS= $(check_PROGRAMS)
|
||||
check_PROGRAMS = test_mlrutil \
|
||||
test_mlrregex \
|
||||
test_argparse \
|
||||
test_byte_readers \
|
||||
test_peek_file_reader \
|
||||
|
|
@ -29,6 +30,9 @@ all_ldadd= \
|
|||
test_mlrutil_CFLAGS= -std=gnu99 -g ${AM_CFLAGS}
|
||||
test_mlrutil_LDADD= ${all_ldadd}
|
||||
|
||||
test_mlrregex_CFLAGS= -std=gnu99 -g ${AM_CFLAGS}
|
||||
test_mlrregex_LDADD= ${all_ldadd}
|
||||
|
||||
test_argparse_CFLAGS= -std=gnu99 -g ${AM_CFLAGS}
|
||||
test_argparse_LDADD= ${all_ldadd}
|
||||
|
||||
|
|
|
|||
92
c/unit_test/test_mlrregex.c
Normal file
92
c/unit_test/test_mlrregex.c
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lib/minunit.h"
|
||||
#include "lib/mlrutil.h"
|
||||
#include "lib/mlrregex.h"
|
||||
|
||||
int tests_run = 0;
|
||||
int tests_failed = 0;
|
||||
int assertions_run = 0;
|
||||
int assertions_failed = 0;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static char * test_interpolate_regex_captures() {
|
||||
int was_allocated = FALSE;
|
||||
|
||||
char* output = interpolate_regex_captures("hello", NULL, &was_allocated);
|
||||
mu_assert_lf(streq(output, "hello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
|
||||
string_array_t* psa = string_array_alloc(0);
|
||||
output = interpolate_regex_captures("hello", psa, &was_allocated);
|
||||
mu_assert_lf(streq(output, "hello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
// captures are indexed 1-up so the X is a placeholder at index 0
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("hello", psa, &was_allocated);
|
||||
mu_assert_lf(streq(output, "hello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\3ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "hcello"));
|
||||
mu_assert_lf(was_allocated == TRUE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\1ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "haello"));
|
||||
mu_assert_lf(was_allocated == TRUE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\4ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "h\\4ello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\0ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "h\\0ello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\3e\\1l\\2l\\4o", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "hcealbl\\4o"));
|
||||
mu_assert_lf(was_allocated == TRUE);
|
||||
string_array_free(psa);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ================================================================
|
||||
static char * all_tests() {
|
||||
mu_run_test(test_interpolate_regex_captures);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("TEST_MLRREGEX ENTER\n");
|
||||
char *result = all_tests();
|
||||
printf("\n");
|
||||
if (result != 0) {
|
||||
printf("Not all unit tests passed\n");
|
||||
}
|
||||
else {
|
||||
printf("TEST_MLRREGEX: ALL UNIT TESTS PASSED\n");
|
||||
}
|
||||
printf("Tests passed: %d of %d\n", tests_run - tests_failed, tests_run);
|
||||
printf("Assertions passed: %d of %d\n", assertions_run - assertions_failed, assertions_run);
|
||||
|
||||
return result != 0;
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
#include <string.h>
|
||||
#include "lib/minunit.h"
|
||||
#include "lib/mlrutil.h"
|
||||
#include "lib/mlrregex.h"
|
||||
|
||||
int tests_run = 0;
|
||||
int tests_failed = 0;
|
||||
|
|
@ -143,66 +142,6 @@ static char * test_unbackslash() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static char * test_interpolate_regex_captures() {
|
||||
int was_allocated = FALSE;
|
||||
|
||||
char* output = interpolate_regex_captures("hello", NULL, &was_allocated);
|
||||
mu_assert_lf(streq(output, "hello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
|
||||
string_array_t* psa = string_array_alloc(0);
|
||||
output = interpolate_regex_captures("hello", psa, &was_allocated);
|
||||
mu_assert_lf(streq(output, "hello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
// captures are indexed 1-up so the X is a placeholder at index 0
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("hello", psa, &was_allocated);
|
||||
mu_assert_lf(streq(output, "hello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\3ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "hcello"));
|
||||
mu_assert_lf(was_allocated == TRUE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\1ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "haello"));
|
||||
mu_assert_lf(was_allocated == TRUE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\4ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "h\\4ello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\0ello", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "h\\0ello"));
|
||||
mu_assert_lf(was_allocated == FALSE);
|
||||
string_array_free(psa);
|
||||
|
||||
psa = string_array_from_line(mlr_strdup_or_die("X,a,b,c"), ',');
|
||||
output = interpolate_regex_captures("h\\3e\\1l\\2l\\4o", psa, &was_allocated);
|
||||
printf("output=[%s]\n", output);
|
||||
mu_assert_lf(streq(output, "hcealbl\\4o"));
|
||||
mu_assert_lf(was_allocated == TRUE);
|
||||
string_array_free(psa);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ================================================================
|
||||
static char * all_tests() {
|
||||
mu_run_test(test_canonical_mod);
|
||||
|
|
@ -212,7 +151,6 @@ static char * all_tests() {
|
|||
mu_run_test(test_scanners);
|
||||
mu_run_test(test_paste);
|
||||
mu_run_test(test_unbackslash);
|
||||
mu_run_test(test_interpolate_regex_captures);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue