-
Notifications
You must be signed in to change notification settings - Fork 13
/
test-snippets.c
143 lines (109 loc) · 4.02 KB
/
test-snippets.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
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
#include "test.h"
#include "whistlepig.h"
const char* text = "sing to me of the man, muse, the man of twists and turns \
driven time and again off course, once he had plundered \
the hallowed heights of troy. \
many cities of men he saw and learned their minds, \
many pains he suffered, heartsick on the open sea, \
fighting to save his life and bring his comrades home. \
but he could not save them from disaster, hard as he strove — \
the recklessness of their own ways destroyed them all, \
the blind fools, they devoured the cattle of the sun \
and the sungod blotted out the day of their return. \
launch out on his story, muse, daughter of zeus, \
start from where you will — sing for our time too.";
TEST(empty_queries) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
ASSERT_EQUALS_UINT(0, num_results);
return NO_ERROR;
}
TEST(terms) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("sing", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
ASSERT_EQUALS_UINT(2, num_results);
ASSERT_EQUALS_UINT(0, start_offsets[0]);
ASSERT_EQUALS_UINT(4, end_offsets[0]);
return NO_ERROR;
}
TEST(conjuctions) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("sing muse", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
ASSERT_EQUALS_UINT(4, num_results);
ASSERT_EQUALS_UINT(0, start_offsets[0]);
ASSERT_EQUALS_UINT(4, end_offsets[0]);
ASSERT_EQUALS_UINT(23, start_offsets[1]);
ASSERT_EQUALS_UINT(27, end_offsets[1]);
ASSERT_EQUALS_UINT(549, start_offsets[2]);
ASSERT_EQUALS_UINT(553, end_offsets[2]);
ASSERT_EQUALS_UINT(603, start_offsets[3]);
ASSERT_EQUALS_UINT(607, end_offsets[3]);
return NO_ERROR;
}
TEST(disjunctions) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("sing OR muse", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
ASSERT_EQUALS_UINT(4, num_results);
// same as above
ASSERT_EQUALS_UINT(0, start_offsets[0]);
ASSERT_EQUALS_UINT(4, end_offsets[0]);
ASSERT_EQUALS_UINT(23, start_offsets[1]);
ASSERT_EQUALS_UINT(27, end_offsets[1]);
ASSERT_EQUALS_UINT(549, start_offsets[2]);
ASSERT_EQUALS_UINT(553, end_offsets[2]);
ASSERT_EQUALS_UINT(603, start_offsets[3]);
ASSERT_EQUALS_UINT(607, end_offsets[3]);
return NO_ERROR;
}
TEST(phrases) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("\"sing to me of the man\"", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
ASSERT_EQUALS_UINT(1, num_results);
ASSERT_EQUALS_UINT(0, start_offsets[0]);
ASSERT_EQUALS_UINT(21, end_offsets[0]);
return NO_ERROR;
}
TEST(negations) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("-sing", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
ASSERT_EQUALS_UINT(0, num_results);
return NO_ERROR;
}
TEST(conjunctions_with_negations) {
wp_query* q;
uint32_t num_results;
pos_t start_offsets[10];
pos_t end_offsets[10];
RELAY_ERROR(wp_query_parse("devoured -sing", "body", &q));
RELAY_ERROR(wp_snippetize_string(q, "body", text, 10, &num_results, start_offsets, end_offsets));
//printf("got %d results\n", num_results);
ASSERT_EQUALS_UINT(1, num_results);
//printf("got %d--%d\n", start_offsets[0], end_offsets[0]);
ASSERT_EQUALS_UINT(441, start_offsets[0]);
ASSERT_EQUALS_UINT(449, end_offsets[0]);
return NO_ERROR;
}