aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sb.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sb.c')
-rw-r--r--tests/sb.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/sb.c b/tests/sb.c
new file mode 100644
index 0000000..8542a88
--- /dev/null
+++ b/tests/sb.c
@@ -0,0 +1,37 @@
+#define STRINGBUILDER_IMPLEMENTATION
+#include "../include/stringbuilder.h"
+
+#include <stdio.h>
+
+#define PRINTF(sb) printf("jac_sb { .data = \"%s\", .size = %zu, .cap = %zu }\n", sb.data, sb.size, sb.cap)
+
+int main() {
+ jac_sb sb = jac_sb_from_buf("Hello, world!");
+ PRINTF(sb);
+ for (size_t i = 0; i < 10; ++i) {
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ jac_sb_append_buf(&sb, " Actually this is a very long sentence that will probably cause several reallocations ");
+ }
+ // PRINTF(sb);
+ jac_sb_free(sb);
+
+ sb = jac_sb_empty();
+ jac_sb_append_buf(&sb, "<!DOCTYPE html><html><body><ul>");
+ for (size_t i = 0; i < 50; ++i)
+ jac_sb_snprintf(&sb, "<li>element %i</li>\n", i);
+ jac_sb_append_buf(&sb, "</ul></body></html>");
+ for (size_t i = 0; i < 2048; ++i)
+ jac_sb_putc(&sb, 69);
+ PRINTF(sb);
+ if (sb.size != 3088 || sb.cap != 4096) return 1;
+ jac_sb_free(sb);
+ return 0;
+}