-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from katef/sv/re_strings-endids
Add endid support to `re_strings`.
- Loading branch information
Showing
15 changed files
with
228 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.include "../../share/mk/top.mk" | ||
|
||
TEST.tests/re_strings != ls -1 tests/re_strings/re_strings*.c | ||
TEST_SRCDIR.tests/re_strings = tests/re_strings | ||
TEST_OUTDIR.tests/re_strings = ${BUILD}/tests/re_strings | ||
|
||
.for n in ${TEST.tests/re_strings:T:R:C/^re_strings//} | ||
test:: ${TEST_OUTDIR.tests/re_strings}/res${n} | ||
SRC += ${TEST_SRCDIR.tests/re_strings}/re_strings${n}.c | ||
CFLAGS.${TEST_SRCDIR.tests/re_strings}/re_strings${n}.c = -UNDEBUG | ||
|
||
${TEST_OUTDIR.tests/re_strings}/run${n}: ${TEST_OUTDIR.tests/re_strings}/re_strings${n}.o ${TEST_OUTDIR.tests/re_strings}/testutil.o | ||
${CC} ${CFLAGS} -o ${TEST_OUTDIR.tests/re_strings}/run${n} ${TEST_OUTDIR.tests/re_strings}/re_strings${n}.o ${TEST_OUTDIR.tests/re_strings}/testutil.o ${BUILD}/lib/libfsm.a ${BUILD}/lib/libre.a | ||
|
||
${TEST_OUTDIR.tests/re_strings}/re_strings${n}.o: tests/re_strings/testutil.h | ||
|
||
${TEST_OUTDIR.tests/re_strings}/res${n}: ${TEST_OUTDIR.tests/re_strings}/run${n} | ||
( ${TEST_OUTDIR.tests/re_strings}/run${n} 1>&2 && echo PASS || echo FAIL ) > ${TEST_OUTDIR.tests/re_strings}/res${n} | ||
|
||
.for lib in ${LIB:Mlibfsm} ${LIB:Mlibre} | ||
${TEST_OUTDIR.tests/re_strings}/run${n}: ${BUILD}/lib/${lib:R}.a | ||
.endfor | ||
.endfor | ||
|
||
${TEST_OUTDIR.tests/re_strings}/testutil.o: tests/re_strings/testutil.c | ||
${CC} ${CFLAGS} -c -o ${TEST_OUTDIR.tests/re_strings}/testutil.o tests/re_strings/testutil.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "testutil.h" | ||
|
||
const char *strings[] = { | ||
"aa", | ||
"ab", | ||
"ac", | ||
"ba", | ||
"bb", | ||
"bc", | ||
"ca", | ||
"cb", | ||
"cc", | ||
NULL, | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
return run_test(strings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "testutil.h" | ||
|
||
const char *strings[] = { | ||
"first", | ||
"duplicate", | ||
"duplicate", | ||
"duplicate", | ||
"last", | ||
NULL, | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
return run_test(strings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "testutil.h" | ||
|
||
const char *strings[] = { | ||
"duplicate", | ||
"duplicate", | ||
"duplicate", | ||
NULL, | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
return run_test(strings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "testutil.h" | ||
|
||
const char *strings[] = { | ||
/* empty */ | ||
NULL, | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
return run_test(strings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "testutil.h" | ||
|
||
#include <stdbool.h> | ||
#include <assert.h> | ||
|
||
#include "fsm/fsm.h" | ||
#include "fsm/options.h" | ||
|
||
#include "re/re.h" | ||
#include "re/strings.h" | ||
|
||
static struct fsm_options opt; | ||
|
||
#define MAX_INPUTS 100 | ||
static fsm_end_id_t id_buf[MAX_INPUTS]; | ||
|
||
int | ||
run_test(const char **strings) | ||
{ | ||
struct re_strings *s = re_strings_new(); | ||
assert(s != NULL); | ||
|
||
fsm_end_id_t id = 0; | ||
const char **input = strings; | ||
while (*input != NULL) { | ||
if (!re_strings_add_str(s, *input, &id)) { | ||
assert(!"re_strings_add_str"); | ||
} | ||
|
||
input++; | ||
id++; | ||
assert(id < MAX_INPUTS); | ||
} | ||
|
||
const int flags = 0; /* not anchored */ | ||
|
||
struct fsm *fsm = re_strings_build(s, &opt, flags); | ||
assert(fsm != NULL); | ||
|
||
/* Each literal string input should match, and the set of | ||
* matching endids should include the expected one. */ | ||
id = 0; | ||
input = strings; | ||
while (*input != NULL) { | ||
fsm_state_t end; | ||
const char **string = input; | ||
const int res = fsm_exec(fsm, fsm_sgetc, string, &end, NULL); | ||
assert(res > 0); /* match */ | ||
|
||
size_t written; | ||
enum fsm_getendids_res eres = fsm_getendids(fsm, end, | ||
MAX_INPUTS, id_buf, &written); | ||
assert(eres == FSM_GETENDIDS_FOUND); | ||
bool found = false; | ||
for (size_t i = 0; i < written; i++) { | ||
if (id_buf[i] == id) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
assert(found); | ||
|
||
input++; | ||
id++; | ||
} | ||
|
||
re_strings_free(s); | ||
fsm_free(fsm); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef TESTUTIL_H | ||
#define TESTUTIL_H | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
int | ||
run_test(const char **strings); | ||
|
||
#endif |