git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
bb43efb76b6602c40838acb7f5496cba832d8896 blob 3312 bytes (raw)

  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
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
#include "cache.h"
#include "json-writer.h"

const char *expect_obj1 = "{\"a\":\"abc\",\"b\":42,\"c\":true}";
const char *expect_obj2 = "{\"a\":-1,\"b\":2147483647,\"c\":0}";
const char *expect_obj3 = "{\"a\":0,\"b\":4294967295,\"c\":18446744073709551615}";
const char *expect_obj4 = "{\"t\":true,\"f\":false,\"n\":null}";
const char *expect_obj5 = "{\"abc\\tdef\":\"abc\\\\def\"}";

struct strbuf obj1 = STRBUF_INIT;
struct strbuf obj2 = STRBUF_INIT;
struct strbuf obj3 = STRBUF_INIT;
struct strbuf obj4 = STRBUF_INIT;
struct strbuf obj5 = STRBUF_INIT;

void make_obj1(void)
{
	jw_object_begin(&obj1);
	jw_object_append_string(&obj1, "a", "abc");
	jw_object_append_int(&obj1, "b", 42);
	jw_object_append_true(&obj1, "c");
	jw_object_end(&obj1);
}

void make_obj2(void)
{
	jw_object_begin(&obj2);
	jw_object_append_int(&obj2, "a", -1);
	jw_object_append_int(&obj2, "b", 0x7fffffff);
	jw_object_append_int(&obj2, "c", 0);
	jw_object_end(&obj2);
}

void make_obj3(void)
{
	jw_object_begin(&obj3);
	jw_object_append_uint64(&obj3, "a", 0);
	jw_object_append_uint64(&obj3, "b", 0xffffffff);
	jw_object_append_uint64(&obj3, "c", 0xffffffffffffffff);
	jw_object_end(&obj3);
}

void make_obj4(void)
{
	jw_object_begin(&obj4);
	jw_object_append_true(&obj4, "t");
	jw_object_append_false(&obj4, "f");
	jw_object_append_null(&obj4, "n");
	jw_object_end(&obj4);
}

void make_obj5(void)
{
	jw_object_begin(&obj5);
	jw_object_append_string(&obj5, "abc" "\x09" "def", "abc" "\\" "def");
	jw_object_end(&obj5);
}

const char *expect_arr1 = "[\"abc\",42,true]";
const char *expect_arr2 = "[-1,2147483647,0]";
const char *expect_arr3 = "[0,4294967295,18446744073709551615]";
const char *expect_arr4 = "[true,false,null]";

struct strbuf arr1 = STRBUF_INIT;
struct strbuf arr2 = STRBUF_INIT;
struct strbuf arr3 = STRBUF_INIT;
struct strbuf arr4 = STRBUF_INIT;

void make_arr1(void)
{
	jw_array_begin(&arr1);
	jw_array_append_string(&arr1, "abc");
	jw_array_append_int(&arr1, 42);
	jw_array_append_true(&arr1);
	jw_array_end(&arr1);
}

void make_arr2(void)
{
	jw_array_begin(&arr2);
	jw_array_append_int(&arr2, -1);
	jw_array_append_int(&arr2, 0x7fffffff);
	jw_array_append_int(&arr2, 0);
	jw_array_end(&arr2);
}

void make_arr3(void)
{
	jw_array_begin(&arr3);
	jw_array_append_uint64(&arr3, 0);
	jw_array_append_uint64(&arr3, 0xffffffff);
	jw_array_append_uint64(&arr3, 0xffffffffffffffff);
	jw_array_end(&arr3);
}

void make_arr4(void)
{
	jw_array_begin(&arr4);
	jw_array_append_true(&arr4);
	jw_array_append_false(&arr4);
	jw_array_append_null(&arr4);
	jw_array_end(&arr4);
}

char *expect_nest1 =
	"{\"obj1\":{\"a\":\"abc\",\"b\":42,\"c\":true},\"arr1\":[\"abc\",42,true]}";

struct strbuf nest1 = STRBUF_INIT;

void make_nest1(void)
{
	jw_object_begin(&nest1);
	jw_object_append_object(&nest1, "obj1", obj1.buf);
	jw_object_append_array(&nest1, "arr1", arr1.buf);
	jw_object_end(&nest1);
}

void cmp(const char *test, const struct strbuf *buf, const char *exp)
{
	if (!strcmp(buf->buf, exp))
		return;

	printf("error[%s]: observed '%s' expected '%s'\n",
	       test, buf->buf, exp);
	exit(1);
}

#define t(v) do { make_##v(); cmp(#v, &v, expect_##v); } while (0)

int cmd_main(int argc, const char **argv)
{
	t(obj1);
	t(obj2);
	t(obj3);
	t(obj4);
	t(obj5);

	t(arr1);
	t(arr2);
	t(arr3);
	t(arr4);

	t(nest1);

	return 0;
}
debug log:

solving bb43efb ...
found bb43efb in https://public-inbox.org/git/20180316194057.77513-3-git@jeffhostetler.com/

applying [1/1] https://public-inbox.org/git/20180316194057.77513-3-git@jeffhostetler.com/
diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c
new file mode 100644
index 0000000..bb43efb

Checking patch t/helper/test-json-writer.c...
Applied patch t/helper/test-json-writer.c cleanly.

index at:
100644 bb43efb76b6602c40838acb7f5496cba832d8896	t/helper/test-json-writer.c

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).