]> git.ozlabs.org Git - ccan/blob - ccan/opt/test/run-consume_words.c
ccan: add test for line-wrapping usage message.
[ccan] / ccan / opt / test / run-consume_words.c
1 #include <ccan/tap/tap.h>
2 #include <ccan/opt/opt.c>
3 #include <ccan/opt/usage.c>
4 #include <ccan/opt/helpers.c>
5 #include <ccan/opt/parse.c>
6
7 /* Test consume_words helper. */
8 int main(int argc, char *argv[])
9 {
10         size_t start, len;
11
12         plan_tests(13);
13
14         /* Every line over width. */
15         len = consume_words("hello world", 1, &start);
16         ok1(start == 0);
17         ok1(len == strlen("hello"));
18         len = consume_words(" world", 1, &start);
19         ok1(start == 1);
20         ok1(len == strlen("world"));
21         ok1(consume_words("", 1, &start) == 0);
22
23         /* Same with width where won't both fit. */
24         len = consume_words("hello world", 5, &start);
25         ok1(start == 0);
26         ok1(len == strlen("hello"));
27         len = consume_words(" world", 5, &start);
28         ok1(start == 1);
29         ok1(len == strlen("world"));
30         ok1(consume_words("", 5, &start) == 0);
31
32         len = consume_words("hello world", 11, &start);
33         ok1(start == 0);
34         ok1(len == strlen("hello world"));
35         ok1(consume_words("", 11, &start) == 0);
36         return exit_status();
37 }