aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sb.c
blob: 8542a88ab60b5ceeb989588547625f121dadd416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
}