1 #ifndef TEST_OUTPUT_TEST_H
2 #define TEST_OUTPUT_TEST_H
3 
4 #undef NDEBUG
5 #include <initializer_list>
6 #include <memory>
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
11 #include "../src/re.h"
12 #include "benchmark/benchmark.h"
13 
14 #define CONCAT2(x, y) x##y
15 #define CONCAT(x, y) CONCAT2(x, y)
16 
17 #define ADD_CASES(...) int CONCAT(dummy, __LINE__) = ::AddCases(__VA_ARGS__)
18 
19 #define SET_SUBSTITUTIONS(...) \
20   int CONCAT(dummy, __LINE__) = ::SetSubstitutions(__VA_ARGS__)
21 
22 enum MatchRules {
23   MR_Default,  // Skip non-matching lines until a match is found.
24   MR_Next,     // Match must occur on the next line.
25   MR_Not  // No line between the current position and the next match matches
26           // the regex
27 };
28 
29 struct TestCase {
30   TestCase(std::string re, int rule = MR_Default);
31 
32   std::string regex_str;
33   int match_rule;
34   std::string substituted_regex;
35   std::shared_ptr<benchmark::Regex> regex;
36 };
37 
38 enum TestCaseID {
39   TC_ConsoleOut,
40   TC_ConsoleErr,
41   TC_JSONOut,
42   TC_JSONErr,
43   TC_CSVOut,
44   TC_CSVErr,
45 
46   TC_NumID  // PRIVATE
47 };
48 
49 // Add a list of test cases to be run against the output specified by
50 // 'ID'
51 int AddCases(TestCaseID ID, std::initializer_list<TestCase> il);
52 
53 // Add or set a list of substitutions to be performed on constructed regex's
54 // See 'output_test_helper.cc' for a list of default substitutions.
55 int SetSubstitutions(
56     std::initializer_list<std::pair<std::string, std::string>> il);
57 
58 // Run all output tests.
59 void RunOutputTests(int argc, char* argv[]);
60 
61 // ========================================================================= //
62 // --------------------------- Misc Utilities ------------------------------ //
63 // ========================================================================= //
64 
65 namespace {
66 
67 const char* const dec_re = "[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?";
68 
69 }  //  end namespace
70 
71 #endif  // TEST_OUTPUT_TEST_H
72