]> git.ozlabs.org Git - ccan/blobdiff - ccan/bytestring/test/run.c
bytestring: Add bytestring_slice function
[ccan] / ccan / bytestring / test / run.c
index 2d86926d06301b2c5ed8dd9d5242cd31aa3bb2b2..97fa8c5cc5d41e7d570cc1ac68c1b30a6057b068 100644 (file)
@@ -12,7 +12,7 @@ int main(void)
        struct bytestring bs, bs1, bs2, bs3, bs4, bs5;
 
        /* This is how many tests you plan to run */
-       plan_tests(16);
+       plan_tests(22);
 
        bs = bytestring(str1, sizeof(str1) - 1);
        ok1(bs.ptr == str1);
@@ -42,7 +42,14 @@ int main(void)
        ok1(bytestring_byte(bs2, 4) == 'd');
        ok1(bytestring_byte(bs2, 5) == 'e');
        ok1(bytestring_byte(bs2, 6) == 'f');
-       
+
+       ok1(bytestring_eq(bytestring_slice(bs, 0, 4), BYTESTRING("test")));
+       ok1(bytestring_eq(bytestring_slice(bs, 5, 8), BYTESTRING("str")));
+       ok1(bytestring_eq(bytestring_slice(bs2, 2, 5), BYTESTRING("c\0d")));
+       ok1(bytestring_eq(bytestring_slice(bs2, 0, -1U), bs2));
+       ok1(bytestring_eq(bytestring_slice(bs2, 10, 20), bytestring_NULL));
+       ok1(bytestring_eq(bytestring_slice(bs2, 2, 1), bytestring_NULL));
+
        /* This exits depending on whether all tests passed */
        return exit_status();
 }