OLD | NEW |
1 // Copyright 2008 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2008 The RE2 Authors. All Rights Reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Random testing of regular expression matching. | 5 // Random testing of regular expression matching. |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include "util/test.h" | 8 #include "util/test.h" |
9 #include "re2/testing/exhaustive_tester.h" | 9 #include "re2/testing/exhaustive_tester.h" |
10 | 10 |
11 DEFINE_int32(regexpseed, 404, "Random regexp seed."); | 11 DEFINE_int32(regexpseed, 404, "Random regexp seed."); |
12 DEFINE_int32(regexpcount, 100, "How many random regexps to generate."); | 12 DEFINE_int32(regexpcount, 100, "How many random regexps to generate."); |
13 DEFINE_int32(stringseed, 200, "Random string seed."); | 13 DEFINE_int32(stringseed, 200, "Random string seed."); |
14 DEFINE_int32(stringcount, 100, "How many random strings to generate."); | 14 DEFINE_int32(stringcount, 100, "How many random strings to generate."); |
15 | 15 |
16 namespace re2 { | 16 namespace re2 { |
17 | 17 |
18 // Runs a random test on the given parameters. | 18 // Runs a random test on the given parameters. |
19 // (Always uses the same random seeds for reproducibility. | 19 // (Always uses the same random seeds for reproducibility. |
20 // Can give different seeds on command line.) | 20 // Can give different seeds on command line.) |
21 static void RandomTest(int maxatoms, int maxops, | 21 static void RandomTest(int maxatoms, int maxops, |
22 const vector<string>& alphabet, | 22 const vector<string>& alphabet, |
23 const vector<string>& ops, | 23 const vector<string>& ops, |
24 int maxstrlen, const vector<string>& stralphabet, | 24 int maxstrlen, const vector<string>& stralphabet, |
25 const string& wrapper) { | 25 const string& wrapper) { |
26 // Limit to smaller test cases in debug mode, | 26 // Limit to smaller test cases in debug mode, |
27 // because everything is so much slower. | 27 // because everything is so much slower. |
28 if (DEBUG_MODE) { | 28 if (RE2_DEBUG_MODE) { |
29 maxatoms--; | 29 maxatoms--; |
30 maxops--; | 30 maxops--; |
31 maxstrlen /= 2; | 31 maxstrlen /= 2; |
32 } | 32 } |
33 | 33 |
34 ExhaustiveTester t(maxatoms, maxops, alphabet, ops, | 34 ExhaustiveTester t(maxatoms, maxops, alphabet, ops, |
35 maxstrlen, stralphabet, wrapper, ""); | 35 maxstrlen, stralphabet, wrapper, ""); |
36 t.RandomStrings(FLAGS_stringseed, FLAGS_stringcount); | 36 t.RandomStrings(FLAGS_stringseed, FLAGS_stringcount); |
37 t.GenerateRandom(FLAGS_regexpseed, FLAGS_regexpcount); | 37 t.GenerateRandom(FLAGS_regexpseed, FLAGS_regexpcount); |
38 printf("%d regexps, %d tests, %d failures [%d/%d str]\n", | 38 printf("%d regexps, %d tests, %d failures [%d/%d str]\n", |
(...skipping 47 matching lines...) Loading... |
86 vector<string> atoms = Split(" ", | 86 vector<string> atoms = Split(" ", |
87 ". (?:^) (?:$) \\a \\f \\n \\r \\t \\v " | 87 ". (?:^) (?:$) \\a \\f \\n \\r \\t \\v " |
88 "\\d \\D \\s \\S \\w \\W (?:\\b) (?:\\B) " | 88 "\\d \\D \\s \\S \\w \\W (?:\\b) (?:\\B) " |
89 "a (a) b c - \\\\"); | 89 "a (a) b c - \\\\"); |
90 vector<string> alphabet = Explode("abc123\001\002\003\t\r\n\v\f\a"); | 90 vector<string> alphabet = Explode("abc123\001\002\003\t\r\n\v\f\a"); |
91 RandomTest(10, 10, atoms, ops, 20, alphabet, ""); | 91 RandomTest(10, 10, atoms, ops, 20, alphabet, ""); |
92 } | 92 } |
93 | 93 |
94 } // namespace re2 | 94 } // namespace re2 |
95 | 95 |
OLD | NEW |