17 #include <gtest/gtest.h>
25 TEST(ParserTest, FileNotFound) {
32 TEST(ParserTest, EmptyFile) {
44 TEST(ParserTest, DescriptionPropertyIgnored) {
49 " {\"search\": \"foo\", \"replace\": \"bar\", \"description\": \"def\"}"
57 TEST(ParserTest, InvalidJson) {
61 " {\"search\": \"[0-9]\", \"replace\": \"#\"}"
70 " {\"search\": \"[0-9]\", \"replace\": \"#\"}"
80 " {\"search\": \"[0-9]\", \"replace\": \"#\"}"
90 " {\"earch\": \"[0-9]\", \"replace\": \"#\"}"
106 " {\"search\": \"[0-9]\", \"replace\": \"#\"}"
112 int bad_value_count = 6;
113 string bad_values[][2] = {
117 {
"\"string\"",
"String"},
121 ASSERT_EQ(
sizeof(
string) * bad_value_count * 2,
sizeof(bad_values));
122 for (
int i = 0; i < bad_value_count; ++i) {
123 rules_file.
OverwriteContents(Substitute(
"{ \"version\": $0 }", bad_values[i][0]));
126 error, Substitute(
"must be an Integer but is a $0", bad_values[i][1]).c_str());
132 " {\"search\": \"[0-9]\", \"replace\": \"#\"}"
144 " {\"search\": \"[0-9\", \"replace\": \"#\"}"
151 TEST(ParserTest, BadCaseSensitivtyValue) {
156 " {\"search\": \"[0-9\", \"replace\": \"#\", \"caseSensitive\": 1}"
163 TEST(ParserTest, RuleNumberInErrorMessage) {
168 " {\"search\": \"[0-9]\", \"replace\": \"#\"},"
169 " {\"search\": \"[0-\", \"replace\": \"error\"},"
170 " {\"search\": \"[A-Z]\", \"replace\": \"_\"}"
175 "Error parsing redaction rule #2; search regex is invalid; missing ]");
180 int main(
int argc,
char **argv) {
182 #ifndef ADDRESS_SANITIZER
183 ::testing::InitGoogleTest(&argc, argv);
184 return RUN_ALL_TESTS();
const char * name() const
Returns the absolute path to the file.
string SetRedactionRulesFromFile(const string &rules_file_path)
int main(int argc, char **argv)
#define ASSERT_UNREDACTED(string)
void OverwriteContents(const std::string &contents)
#define ASSERT_REDACTED_EQ(actual, expected)
#define ASSERT_ERROR_MESSAGE_CONTAINS(error, expected)