33 |
// functionality. |
// functionality. |
34 |
|
|
35 |
#include <stdio.h> |
#include <stdio.h> |
36 |
|
#include <string> |
37 |
#include <vector> |
#include <vector> |
38 |
#include <pcre_stringpiece.h> |
#include <pcre_stringpiece.h> |
39 |
#include <pcre_scanner.h> |
#include <pcre_scanner.h> |
40 |
|
|
41 |
|
#define FLAGS_unittest_stack_size 49152 |
42 |
|
|
43 |
// Dies with a fatal error if the two values are not equal. |
// Dies with a fatal error if the two values are not equal. |
44 |
#define CHECK_EQ(a, b) do { \ |
#define CHECK_EQ(a, b) do { \ |
45 |
if ( (a) != (b) ) { \ |
if ( (a) != (b) ) { \ |
119 |
comments.resize(0); |
comments.resize(0); |
120 |
} |
} |
121 |
|
|
122 |
|
static void TestBigComment() { |
123 |
|
string input; |
124 |
|
for (int i = 0; i < 1024; ++i) { |
125 |
|
char buf[1024]; |
126 |
|
snprintf(buf, sizeof(buf), " # Comment %d\n", i); |
127 |
|
input += buf; |
128 |
|
} |
129 |
|
input += "name = value;\n"; |
130 |
|
|
131 |
|
Scanner s(input.c_str()); |
132 |
|
s.SetSkipExpression("\\s+|#.*\n"); |
133 |
|
|
134 |
|
string name; |
135 |
|
string value; |
136 |
|
s.Consume("(\\w+) = (\\w+);", &name, &value); |
137 |
|
CHECK_EQ(name, "name"); |
138 |
|
CHECK_EQ(value, "value"); |
139 |
|
} |
140 |
|
|
141 |
|
// TODO: also test scanner and big-comment in a thread with a |
142 |
|
// small stack size |
143 |
|
|
144 |
int main(int argc, char** argv) { |
int main(int argc, char** argv) { |
145 |
TestScanner(); |
TestScanner(); |
146 |
|
TestBigComment(); |
147 |
|
|
148 |
// Done |
// Done |
149 |
printf("OK\n"); |
printf("OK\n"); |