From a5f1cb5ce34f31b9c46de94e55b5f85d571b792f Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Tue, 1 Apr 2025 01:44:47 +0300 Subject: Added stringbuilder and STE --- tests/sb.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/sb.c (limited to 'tests/sb.c') 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 + +#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, ""); + 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; +} -- cgit v1.2.3-70-g09d2