| 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 |
|
#ifdef _WIN32 |
| 42 |
|
# define snprintf _snprintf |
| 43 |
|
#endif |
| 44 |
|
|
| 45 |
|
#define FLAGS_unittest_stack_size 49152 |
| 46 |
|
|
| 47 |
// Dies with a fatal error if the two values are not equal. |
// Dies with a fatal error if the two values are not equal. |
| 48 |
#define CHECK_EQ(a, b) do { \ |
#define CHECK_EQ(a, b) do { \ |
| 49 |
if ( (a) != (b) ) { \ |
if ( (a) != (b) ) { \ |
| 75 |
s.Consume(re, &var, &number); |
s.Consume(re, &var, &number); |
| 76 |
CHECK_EQ(var, "alpha"); |
CHECK_EQ(var, "alpha"); |
| 77 |
CHECK_EQ(number, 1); |
CHECK_EQ(number, 1); |
| 78 |
|
CHECK_EQ(s.LineNumber(), 3); |
| 79 |
s.GetNextComments(&comments); |
s.GetNextComments(&comments); |
| 80 |
CHECK_EQ(comments.size(), 1); |
CHECK_EQ(comments.size(), 1); |
| 81 |
CHECK_EQ(comments[0].as_string(), " // this sets alpha\n"); |
CHECK_EQ(comments[0].as_string(), " // this sets alpha\n"); |
| 123 |
comments.resize(0); |
comments.resize(0); |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
|
static void TestBigComment() { |
| 127 |
|
string input; |
| 128 |
|
for (int i = 0; i < 1024; ++i) { |
| 129 |
|
char buf[1024]; |
| 130 |
|
snprintf(buf, sizeof(buf), " # Comment %d\n", i); |
| 131 |
|
input += buf; |
| 132 |
|
} |
| 133 |
|
input += "name = value;\n"; |
| 134 |
|
|
| 135 |
|
Scanner s(input.c_str()); |
| 136 |
|
s.SetSkipExpression("\\s+|#.*\n"); |
| 137 |
|
|
| 138 |
|
string name; |
| 139 |
|
string value; |
| 140 |
|
s.Consume("(\\w+) = (\\w+);", &name, &value); |
| 141 |
|
CHECK_EQ(name, "name"); |
| 142 |
|
CHECK_EQ(value, "value"); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
// TODO: also test scanner and big-comment in a thread with a |
| 146 |
|
// small stack size |
| 147 |
|
|
| 148 |
int main(int argc, char** argv) { |
int main(int argc, char** argv) { |
| 149 |
TestScanner(); |
TestScanner(); |
| 150 |
|
TestBigComment(); |
| 151 |
|
|
| 152 |
// Done |
// Done |
| 153 |
printf("OK\n"); |
printf("OK\n"); |