-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_capitol.c
116 lines (93 loc) · 2.87 KB
/
test_capitol.c
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
#include "test-framework/unity.h"
#include "capitol.h"
#include <stdlib.h>
void setUp(void)
{
}
void tearDown(void)
{
}
static void check_token(cite_token_t expected, cite_token_t actual)
{
TEST_ASSERT_EQUAL(expected.congress, actual.congress);
TEST_ASSERT_EQUAL_STRING(expected.object_type, actual.object_type);
TEST_ASSERT_EQUAL(expected.number, actual.number);
TEST_ASSERT_EQUAL_STRING(expected.version, actual.version);
}
static void check_citation(citation_t expected, citation_t actual)
{
TEST_ASSERT_EQUAL(expected.congress, actual.congress);
TEST_ASSERT_EQUAL(expected.chamber, actual.chamber);
TEST_ASSERT_EQUAL(expected.object_type, actual.object_type);
TEST_ASSERT_EQUAL(expected.number, actual.number);
TEST_ASSERT_EQUAL_STRING(expected.version, actual.version);
}
static void test_tokenize_no_version(void)
{
cite_token_t expected = (cite_token_t) { 118, "hr", 8070, NULL };
cite_token_t actual = tokenize("118hr8070");
check_token(expected, actual);
}
static void test_tokenize_with_version(void)
{
cite_token_t expected = { 118, "hr", 8070, "ih" };
cite_token_t actual = tokenize("118hr8070ih");
check_token(expected, actual);
}
static void test_parse_no_version(void)
{
cite_token_t token = tokenize("118hr8070");
citation_t expected = { 118, HOUSE, BILL, 8070, NULL };
citation_t actual = parse(token);
check_citation(expected, actual);
}
static void test_parse_with_version(void)
{
cite_token_t token = tokenize("118hr8070ih");
citation_t expected = { 118, HOUSE, BILL, 8070, "ih" };
citation_t actual = parse(token);
check_citation(expected, actual);
}
static void test_url_no_version(void)
{
citation_t token = { 118, HOUSE, BILL, 8070, NULL };
char *expected = "https://www.congress.gov/bill/118th-congress/house-bill/8070";
char out[256];
url(token, out);
TEST_ASSERT_EQUAL_STRING(expected, out);
}
static void test_url_with_version(void)
{
citation_t token = { 118, HOUSE, BILL, 8070, "ih" };
char *expected = "https://www.congress.gov/bill/118th-congress/house-bill/8070/text/ih";
char out[256];
url(token, out);
TEST_ASSERT_EQUAL_STRING(expected, out);
}
static void test_convert_no_version(void)
{
char *expected = "https://www.congress.gov/bill/118th-congress/house-bill/8070";
char out[256];
convert_citation("118hr8070", out);
TEST_ASSERT_EQUAL_STRING(expected, out);
}
static void test_convert_with_version(void)
{
char *expected = "https://www.congress.gov/bill/118th-congress/house-bill/8070/text/ih";
char out[256];
convert_citation("118hr8070ih", out);
TEST_ASSERT_EQUAL_STRING(expected, out);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_tokenize_no_version);
RUN_TEST(test_tokenize_with_version);
RUN_TEST(test_parse_no_version);
RUN_TEST(test_parse_with_version);
RUN_TEST(test_url_no_version);
RUN_TEST(test_url_with_version);
RUN_TEST(test_convert_no_version);
RUN_TEST(test_convert_with_version);
return UNITY_END();
}