Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: third_party/re2/re2/testing/exhaustive_tester.h

Issue 1544433002: Replace RE2 import with a dependency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-Added LICENSE and OWNERS file Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2009 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 #ifndef RE2_TESTING_EXHAUSTIVE_TESTER_H__
6 #define RE2_TESTING_EXHAUSTIVE_TESTER_H__
7
8 #include <string>
9 #include <vector>
10 #include "util/util.h"
11 #include "re2/testing/regexp_generator.h"
12 #include "re2/testing/string_generator.h"
13
14 namespace re2 {
15
16 #if !defined(NDEBUG)
17 // We are in a debug build.
18 const bool RE2_DEBUG_MODE = true;
19 #elif ADDRESS_SANITIZER || MEMORY_SANITIZER || THREAD_SANITIZER
20 // Not a debug build, but still under sanitizers.
21 const bool RE2_DEBUG_MODE = true;
22 #else
23 const bool RE2_DEBUG_MODE = false;
24 #endif
25
26 // Exhaustive regular expression test: generate all regexps within parameters,
27 // then generate all strings of a given length over a given alphabet,
28 // then check that NFA, DFA, and PCRE agree about whether each regexp matches
29 // each possible string, and if so, where the match is.
30 //
31 // Can also be used in a "random" mode that generates a given number
32 // of random regexp and strings, allowing testing of larger expressions
33 // and inputs.
34 class ExhaustiveTester : public RegexpGenerator {
35 public:
36 ExhaustiveTester(int maxatoms,
37 int maxops,
38 const vector<string>& alphabet,
39 const vector<string>& ops,
40 int maxstrlen,
41 const vector<string>& stralphabet,
42 const string& wrapper,
43 const string& topwrapper)
44 : RegexpGenerator(maxatoms, maxops, alphabet, ops),
45 strgen_(maxstrlen, stralphabet),
46 wrapper_(wrapper),
47 topwrapper_(topwrapper),
48 regexps_(0), tests_(0), failures_(0),
49 randomstrings_(0), stringseed_(0), stringcount_(0) { }
50
51 int regexps() { return regexps_; }
52 int tests() { return tests_; }
53 int failures() { return failures_; }
54
55 // Needed for RegexpGenerator interface.
56 void HandleRegexp(const string& regexp);
57
58 // Causes testing to generate random input strings.
59 void RandomStrings(int32 seed, int32 count) {
60 randomstrings_ = true;
61 stringseed_ = seed;
62 stringcount_ = count;
63 }
64
65 private:
66 StringGenerator strgen_;
67 string wrapper_; // Regexp wrapper - either empty or has one %s.
68 string topwrapper_; // Regexp top-level wrapper.
69 int regexps_; // Number of HandleRegexp calls
70 int tests_; // Number of regexp tests.
71 int failures_; // Number of tests failed.
72
73 bool randomstrings_; // Whether to use random strings
74 int32 stringseed_; // If so, the seed.
75 int stringcount_; // If so, how many to generate.
76 DISALLOW_COPY_AND_ASSIGN(ExhaustiveTester);
77 };
78
79 // Runs an exhaustive test on the given parameters.
80 void ExhaustiveTest(int maxatoms, int maxops,
81 const vector<string>& alphabet,
82 const vector<string>& ops,
83 int maxstrlen, const vector<string>& stralphabet,
84 const string& wrapper,
85 const string& topwrapper);
86
87 // Runs an exhaustive test using the given parameters and
88 // the basic egrep operators.
89 void EgrepTest(int maxatoms, int maxops, const string& alphabet,
90 int maxstrlen, const string& stralphabet,
91 const string& wrapper);
92
93 } // namespace re2
94
95 #endif // RE2_TESTING_EXHAUSTIVE_TESTER_H__
OLDNEW
« no previous file with comments | « third_party/re2/re2/testing/exhaustive_test.cc ('k') | third_party/re2/re2/testing/exhaustive_tester.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698