aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sb.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov@twistea.su>2025-04-01 01:44:47 +0300
committerjustanothercatgirl <sotov@twistea.su>2025-04-01 01:44:47 +0300
commita5f1cb5ce34f31b9c46de94e55b5f85d571b792f (patch)
tree105116fd5b812124812c6658727b96814fa41b05 /tests/sb.c
parent08b786a6770c172f433e28b0eb1e893f4fbae40a (diff)
Added stringbuilder and STE
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;
+}