trailer.c 2.55 KB
Newer Older
1 2 3
#include "clar_libgit2.h"
#include "message.h"

4
static void assert_trailers(const char *message, git_message_trailer *trailers)
5
{
6
	git_message_trailer_array arr;
7
	size_t i;
8

9
	int rc = git_message_trailers(&arr, message);
10

11 12
	cl_assert_equal_i(0, rc);

13
	for(i=0; i<arr.count; i++) {
14 15 16
		cl_assert_equal_s(arr.trailers[i].key, trailers[i].key);
		cl_assert_equal_s(arr.trailers[i].value, trailers[i].value);
	}
17 18

	cl_assert_equal_i(0, rc);
19 20

	git_message_trailer_array_free(&arr);
21 22 23 24
}

void test_message_trailer__simple(void)
{
25
	git_message_trailer trailers[] = {
26 27 28 29
		{"Signed-off-by", "foo@bar.com"},
		{"Signed-off-by", "someone@else.com"},
		{NULL, NULL},
	};
30

31 32 33 34 35
	assert_trailers(
		"Message\n"
		"\n"
		"Signed-off-by: foo@bar.com\n"
		"Signed-off-by: someone@else.com\n"
36
	, trailers);
37 38 39 40
}

void test_message_trailer__no_whitespace(void)
{
41
	git_message_trailer trailers[] = {
42 43 44
		{"Key", "value"},
		{NULL, NULL},
	};
45

46 47 48 49
	assert_trailers(
		"Message\n"
		"\n"
		"Key:value\n"
50
	, trailers);
51 52 53 54
}

void test_message_trailer__extra_whitespace(void)
{
55
	git_message_trailer trailers[] = {
56 57 58
		{"Key", "value"},
		{NULL, NULL},
	};
59

60 61 62 63
	assert_trailers(
		"Message\n"
		"\n"
		"Key   :   value\n"
64
	, trailers);
65 66 67 68
}

void test_message_trailer__no_newline(void)
{
69
	git_message_trailer trailers[] = {
70 71 72
		{"Key", "value"},
		{NULL, NULL},
	};
73

74 75 76 77
	assert_trailers(
		"Message\n"
		"\n"
		"Key: value"
78
	, trailers);
79 80 81 82
}

void test_message_trailer__not_last_paragraph(void)
{
83
	git_message_trailer trailers[] = {
84 85
		{NULL, NULL},
	};
86

87 88 89 90 91 92
	assert_trailers(
		"Message\n"
		"\n"
		"Key: value\n"
		"\n"
		"More stuff\n"
93
	, trailers);
94 95 96 97
}

void test_message_trailer__conflicts(void)
{
98
	git_message_trailer trailers[] = {
99 100 101
		{"Key", "value"},
		{NULL, NULL},
	};
102

103 104 105 106 107 108 109
	assert_trailers(
		"Message\n"
		"\n"
		"Key: value\n"
		"\n"
		"Conflicts:\n"
		"\tfoo.c\n"
110
	, trailers);
111 112 113 114
}

void test_message_trailer__patch(void)
{
115
	git_message_trailer trailers[] = {
116 117 118
		{"Key", "value"},
		{NULL, NULL},
	};
119

120 121 122 123 124 125 126
	assert_trailers(
		"Message\n"
		"\n"
		"Key: value\n"
		"\n"
		"---\n"
		"More: stuff\n"
127
	, trailers);
128 129 130 131
}

void test_message_trailer__continuation(void)
{
132
	git_message_trailer trailers[] = {
133 134 135 136 137
		{"A", "b\n c"},
		{"D", "e\n f: g h"},
		{"I", "j"},
		{NULL, NULL},
	};
138

139 140 141 142 143 144 145 146
	assert_trailers(
		"Message\n"
		"\n"
		"A: b\n"
		" c\n"
		"D: e\n"
		" f: g h\n"
		"I: j\n"
147
	, trailers);
148 149 150 151
}

void test_message_trailer__invalid(void)
{
152
	git_message_trailer trailers[] = {
153 154 155 156
		{"Signed-off-by", "some@one.com"},
		{"Another", "trailer"},
		{NULL, NULL},
	};
157

158 159 160 161 162 163
	assert_trailers(
		"Message\n"
		"\n"
		"Signed-off-by: some@one.com\n"
		"Not a trailer\n"
		"Another: trailer\n"
164
	, trailers);
165
}