X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Frun-consume_words.c;h=c1eaf56aa2678fc972671861a100f233c665a22f;hp=ae4d5d3eae220049b5b1d548419b6af79947530c;hb=e7e57cbf6725debd99238ccd8e3bf273a8d7e61c;hpb=3d45cf27cf586c9afe078ceb06fee115ea246a92 diff --git a/ccan/opt/test/run-consume_words.c b/ccan/opt/test/run-consume_words.c index ae4d5d3e..c1eaf56a 100644 --- a/ccan/opt/test/run-consume_words.c +++ b/ccan/opt/test/run-consume_words.c @@ -5,33 +5,60 @@ #include /* Test consume_words helper. */ -int main(int argc, char *argv[]) +int main(void) { - unsigned int start, len; + size_t prefix, len; + bool start = true; - plan_tests(13); + plan_tests(27); /* Every line over width. */ - len = consume_words("hello world", 1, &start); - ok1(start == 0); + len = consume_words("hello world", 1, &prefix, &start); + ok1(prefix == 0); + ok1(!start); ok1(len == strlen("hello")); - len = consume_words(" world", 1, &start); - ok1(start == 1); + len = consume_words(" world", 1, &prefix, &start); + ok1(prefix == 1); ok1(len == strlen("world")); - ok1(consume_words("", 1, &start) == 0); + ok1(!start); + ok1(consume_words("", 1, &prefix, &start) == 0); /* Same with width where won't both fit. */ - len = consume_words("hello world", 5, &start); - ok1(start == 0); + start = true; + len = consume_words("hello world", 5, &prefix, &start); + ok1(!start); + ok1(prefix == 0); ok1(len == strlen("hello")); - len = consume_words(" world", 5, &start); - ok1(start == 1); + len = consume_words(" world", 5, &prefix, &start); + ok1(!start); + ok1(prefix == 1); ok1(len == strlen("world")); - ok1(consume_words("", 5, &start) == 0); + ok1(consume_words("", 5, &prefix, &start) == 0); - len = consume_words("hello world", 11, &start); - ok1(start == 0); + start = true; + len = consume_words("hello world", 11, &prefix, &start); + ok1(!start); + ok1(prefix == 0); ok1(len == strlen("hello world")); - ok1(consume_words("", 11, &start) == 0); + ok1(consume_words("", 11, &prefix, &start) == 0); + + /* Now try a literal, should not be broken */ + start = true; + len = consume_words(" hello world", 5, &prefix, &start); + ok1(!start); + ok1(prefix == 1); + ok1(len == strlen("hello world")); + + /* A literal after an explicit \n also not broken */ + start = true; + len = consume_words("hi\n hello world", 5, &prefix, &start); + ok1(start); + ok1(prefix == 0); + ok1(len == strlen("hi\n")); + len = consume_words(" hello world", 5, &prefix, &start); + ok1(!start); + ok1(prefix == 1); + ok1(len == strlen("hello world")); + return exit_status(); }