static void test_strbuf(void) {
struct strbuf *sb;
_cleanup_strv_free_ char **l;
- ssize_t a, b, c, d, e, f, g;
+ ssize_t a, b, c, d, e, f, g, h;
sb = strbuf_new();
e = add_string(sb, "aldo"); /* duplicate */
f = add_string(sb, "do"); /* duplicate */
g = add_string(sb, "waldorf"); /* not a duplicate: matches from tail */
+ h = add_string(sb, "");
/* check the content of the buffer directly */
l = strv_parse_nulstr(sb->buf, sb->len);
assert_se(streq(l[2], "foo"));
assert_se(streq(l[3], "bar"));
assert_se(streq(l[4], "waldorf"));
+ assert_se(l[5] == NULL);
assert_se(sb->nodes_count == 5); /* root + 4 non-duplicates */
- assert_se(sb->dedup_count == 3);
- assert_se(sb->in_count == 7);
+ assert_se(sb->dedup_count == 4);
+ assert_se(sb->in_count == 8);
assert_se(sb->in_len == 29); /* length of all strings added */
assert_se(sb->dedup_len == 11); /* length of all strings duplicated */
assert_se(e == 2);
assert_se(f == 4);
assert_se(g == 15);
+ assert_se(h == 0);
assert_se(streq(sb->buf + a, "waldo"));
assert_se(streq(sb->buf + b, "foo"));
assert_se(streq(sb->buf + e, "aldo"));
assert_se(streq(sb->buf + f, "do"));
assert_se(streq(sb->buf + g, "waldorf"));
+ assert_se(streq(sb->buf + h, ""));
strbuf_complete(sb);
assert_se(sb->root == NULL);