Skip to content

Commit

Permalink
Merge pull request #996 from hintjens/master
Browse files Browse the repository at this point in the history
Problem: zrex selftest tag is missing
  • Loading branch information
jemc committed Apr 22, 2015
2 parents b3eba5d + 64782af commit d17ff87
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
10 changes: 5 additions & 5 deletions doc/zlist.doc
Expand Up @@ -215,9 +215,9 @@ This is the class self test code:
item = (char *) zlist_pop (list);
assert (item == bread);
item = (char *) zlist_pop (list);
assert (item == cheese);
item = (char *) zlist_pop (list);
assert (item == wine);
item = (char *) zlist_pop (list);
assert (item == cheese);
assert (zlist_size (list) == 0);

assert (zlist_size (sub_list) == 3);
Expand All @@ -235,11 +235,11 @@ This is the class self test code:
// Set equals function otherwise equals will not work as autofree copies strings
zlist_comparefn (list, s_compare);
zlist_push (list, bread);
zlist_append (list, cheese);
zlist_append (list, cheese);
assert (zlist_size (list) == 2);
zlist_append (list, wine);
zlist_append (list, wine);
assert (zlist_exists (list, wine));
zlist_remove (list, wine);
zlist_remove (list, wine);
assert (!zlist_exists (list, wine));
assert (streq ((const char *) zlist_first (list), bread));
item = (char *) zlist_pop (list);
Expand Down
10 changes: 5 additions & 5 deletions doc/zlist.txt
Expand Up @@ -227,9 +227,9 @@ char *item;
item = (char *) zlist_pop (list);
assert (item == bread);
item = (char *) zlist_pop (list);
assert (item == cheese);
item = (char *) zlist_pop (list);
assert (item == wine);
item = (char *) zlist_pop (list);
assert (item == cheese);
assert (zlist_size (list) == 0);

assert (zlist_size (sub_list) == 3);
Expand All @@ -247,11 +247,11 @@ zlist_autofree (list);
// Set equals function otherwise equals will not work as autofree copies strings
zlist_comparefn (list, s_compare);
zlist_push (list, bread);
zlist_append (list, cheese);
zlist_append (list, cheese);
assert (zlist_size (list) == 2);
zlist_append (list, wine);
zlist_append (list, wine);
assert (zlist_exists (list, wine));
zlist_remove (list, wine);
zlist_remove (list, wine);
assert (!zlist_exists (list, wine));
assert (streq ((const char *) zlist_first (list), bread));
item = (char *) zlist_pop (list);
Expand Down
44 changes: 43 additions & 1 deletion doc/zrex.doc
Expand Up @@ -88,5 +88,47 @@ This is the class interface:

This is the class self test code:

Please add @selftest section in ../src/zrex.c.
// This shows the pattern of matching many lines to a single pattern
zrex_t *rex = zrex_new ("\\d+-\\d+-\\d+");
assert (rex);
assert (zrex_valid (rex));
bool matches = zrex_matches (rex, "123-456-789");
assert (matches);
assert (zrex_hits (rex) == 1);
assert (streq (zrex_hit (rex, 0), "123-456-789"));
assert (zrex_hit (rex, 1) == NULL);
zrex_destroy (&rex);

// Here we pick out hits using capture groups
rex = zrex_new ("(\\d+)-(\\d+)-(\\d+)");
assert (rex);
assert (zrex_valid (rex));
matches = zrex_matches (rex, "123-456-ABC");
assert (!matches);
matches = zrex_matches (rex, "123-456-789");
assert (matches);
assert (zrex_hits (rex) == 4);
assert (streq (zrex_hit (rex, 0), "123-456-789"));
assert (streq (zrex_hit (rex, 1), "123"));
assert (streq (zrex_hit (rex, 2), "456"));
assert (streq (zrex_hit (rex, 3), "789"));
zrex_destroy (&rex);

// This shows the pattern of matching one line against many
// patterns and then handling the case when it hits
rex = zrex_new (NULL); // No initial pattern
assert (rex);
char *input = "Mechanism: CURVE";
matches = zrex_eq (rex, input, "Version: (.+)");
assert (!matches);
assert (zrex_hits (rex) == 0);
matches = zrex_eq (rex, input, "Mechanism: (.+)");
assert (matches);
assert (zrex_hits (rex) == 2);
const char *mechanism;
zrex_fetch (rex, &mechanism, NULL);
assert (streq (zrex_hit (rex, 1), "CURVE"));
assert (streq (mechanism, "CURVE"));
zrex_destroy (&rex);


44 changes: 43 additions & 1 deletion doc/zrex.txt
Expand Up @@ -100,5 +100,47 @@ EXAMPLE
-------
.From zrex_test method
----
Please add @selftest section in ../src/zrex.c.
// This shows the pattern of matching many lines to a single pattern
zrex_t *rex = zrex_new ("\\d+-\\d+-\\d+");
assert (rex);
assert (zrex_valid (rex));
bool matches = zrex_matches (rex, "123-456-789");
assert (matches);
assert (zrex_hits (rex) == 1);
assert (streq (zrex_hit (rex, 0), "123-456-789"));
assert (zrex_hit (rex, 1) == NULL);
zrex_destroy (&rex);

// Here we pick out hits using capture groups
rex = zrex_new ("(\\d+)-(\\d+)-(\\d+)");
assert (rex);
assert (zrex_valid (rex));
matches = zrex_matches (rex, "123-456-ABC");
assert (!matches);
matches = zrex_matches (rex, "123-456-789");
assert (matches);
assert (zrex_hits (rex) == 4);
assert (streq (zrex_hit (rex, 0), "123-456-789"));
assert (streq (zrex_hit (rex, 1), "123"));
assert (streq (zrex_hit (rex, 2), "456"));
assert (streq (zrex_hit (rex, 3), "789"));
zrex_destroy (&rex);

// This shows the pattern of matching one line against many
// patterns and then handling the case when it hits
rex = zrex_new (NULL); // No initial pattern
assert (rex);
char *input = "Mechanism: CURVE";
matches = zrex_eq (rex, input, "Version: (.+)");
assert (!matches);
assert (zrex_hits (rex) == 0);
matches = zrex_eq (rex, input, "Mechanism: (.+)");
assert (matches);
assert (zrex_hits (rex) == 2);
const char *mechanism;
zrex_fetch (rex, &mechanism, NULL);
assert (streq (zrex_hit (rex, 1), "CURVE"));
assert (streq (mechanism, "CURVE"));
zrex_destroy (&rex);

----

0 comments on commit d17ff87

Please sign in to comment.