| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/tools/profile_reset/jtl_parser.h" | 5 #include "chrome/tools/profile_reset/jtl_parser.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 {"// \"//not a literal//\" // comment", ""}, | 146 {"// \"//not a literal//\" // comment", ""}, |
| 147 {"\"literal\" // \"//not a literal//\" // comment", "\"literal\""}, | 147 {"\"literal\" // \"//not a literal//\" // comment", "\"literal\""}, |
| 148 {"\"//not a comment//\" // \"//not a literal//\" // comment", | 148 {"\"//not a comment//\" // \"//not a literal//\" // comment", |
| 149 "\"//not a comment//\""}, | 149 "\"//not a comment//\""}, |
| 150 {"\"literal // \"not a literal nor a comment", | 150 {"\"literal // \"not a literal nor a comment", |
| 151 "\"literal // \"notaliteralnoracomment"}, | 151 "\"literal // \"notaliteralnoracomment"}, |
| 152 {"\"literal // \"not a literal nor a comment//\"", | 152 {"\"literal // \"not a literal nor a comment//\"", |
| 153 "\"literal // \"notaliteralnoracomment"} | 153 "\"literal // \"notaliteralnoracomment"} |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 156 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 157 SCOPED_TRACE(cases[i].source_code); | 157 SCOPED_TRACE(cases[i].source_code); |
| 158 scoped_ptr<JtlParser> parser( | 158 scoped_ptr<JtlParser> parser( |
| 159 CreateParserFromVerboseText(cases[i].source_code)); | 159 CreateParserFromVerboseText(cases[i].source_code)); |
| 160 EXPECT_EQ(cases[i].compacted_source_code, parser->compacted_source()); | 160 EXPECT_EQ(cases[i].compacted_source_code, parser->compacted_source()); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 TEST(JtlParser, MismatchedDoubleQuotesBeforeEndOfLine) { | 164 TEST(JtlParser, MismatchedDoubleQuotesBeforeEndOfLine) { |
| 165 struct TestCase { | 165 struct TestCase { |
| 166 const char* source_code; | 166 const char* source_code; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 179 {"\"\"\" // not a comment\n\"", 0}, | 179 {"\"\"\" // not a comment\n\"", 0}, |
| 180 {"\"\"\" // \" neither a literal nor a comment\"\n\"", 0}, | 180 {"\"\"\" // \" neither a literal nor a comment\"\n\"", 0}, |
| 181 {"\"\" // comment\n\"// not a comment", 1}, | 181 {"\"\" // comment\n\"// not a comment", 1}, |
| 182 {"\" // not a comment\"\n\"// not a comment", 1}, | 182 {"\" // not a comment\"\n\"// not a comment", 1}, |
| 183 {"foo(\"bar\");\nfoo(\"mismatched);", 1}, | 183 {"foo(\"bar\");\nfoo(\"mismatched);", 1}, |
| 184 {"foo(\n\"bar\", \"mismatched);", 1}, | 184 {"foo(\n\"bar\", \"mismatched);", 1}, |
| 185 {"foo(\n\"bar\", \"mismatched); //comment", 1}, | 185 {"foo(\n\"bar\", \"mismatched); //comment", 1}, |
| 186 {"foo(\n\"bar\", \"mismatched);\ngood(\"bar\")", 1} | 186 {"foo(\n\"bar\", \"mismatched);\ngood(\"bar\")", 1} |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 189 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 190 SCOPED_TRACE(cases[i].source_code); | 190 SCOPED_TRACE(cases[i].source_code); |
| 191 std::string compacted_source_code; | 191 std::string compacted_source_code; |
| 192 std::vector<size_t> newline_indices; | 192 std::vector<size_t> newline_indices; |
| 193 size_t error_line_number; | 193 size_t error_line_number; |
| 194 EXPECT_FALSE(JtlParser::RemoveCommentsAndAllWhitespace( | 194 EXPECT_FALSE(JtlParser::RemoveCommentsAndAllWhitespace( |
| 195 cases[i].source_code, | 195 cases[i].source_code, |
| 196 &compacted_source_code, | 196 &compacted_source_code, |
| 197 &newline_indices, | 197 &newline_indices, |
| 198 &error_line_number)); | 198 &error_line_number)); |
| 199 EXPECT_EQ(cases[i].error_line_number, error_line_number); | 199 EXPECT_EQ(cases[i].error_line_number, error_line_number); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 {"foo2().", "foo2", "[]", false}, | 218 {"foo2().", "foo2", "[]", false}, |
| 219 {"foo3(true);", "foo3", "[true]", true}, | 219 {"foo3(true);", "foo3", "[true]", true}, |
| 220 {"foo4(false).", "foo4", "[false]", false}, | 220 {"foo4(false).", "foo4", "[false]", false}, |
| 221 {"foo5(\"bar\").", "foo5", "[\"bar\"]", false}, | 221 {"foo5(\"bar\").", "foo5", "[\"bar\"]", false}, |
| 222 {"foo6(\" b a r \").", "foo6", "[\" b a r \"]", false}, | 222 {"foo6(\" b a r \").", "foo6", "[\" b a r \"]", false}, |
| 223 {"foo7(true, \"bar\").", "foo7", "[true,\"bar\"]", false}, | 223 {"foo7(true, \"bar\").", "foo7", "[true,\"bar\"]", false}, |
| 224 {"foo8(\"bar\", false, true);", "foo8", "[\"bar\",false,true]", true}, | 224 {"foo8(\"bar\", false, true);", "foo8", "[\"bar\",false,true]", true}, |
| 225 {"foo9(\"bar\", \" b a r \");", "foo9", "[\"bar\",\" b a r \"]", true} | 225 {"foo9(\"bar\", \" b a r \");", "foo9", "[\"bar\",\" b a r \"]", true} |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 228 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 229 SCOPED_TRACE(cases[i].expected_name); | 229 SCOPED_TRACE(cases[i].expected_name); |
| 230 scoped_ptr<JtlParser> parser( | 230 scoped_ptr<JtlParser> parser( |
| 231 CreateParserFromVerboseText(cases[i].source_code)); | 231 CreateParserFromVerboseText(cases[i].source_code)); |
| 232 ExpectNextOperation(parser.get(), | 232 ExpectNextOperation(parser.get(), |
| 233 cases[i].expected_name, | 233 cases[i].expected_name, |
| 234 cases[i].expected_args, | 234 cases[i].expected_args, |
| 235 cases[i].expected_ends_sentence); | 235 cases[i].expected_ends_sentence); |
| 236 EXPECT_TRUE(parser->HasFinished()); | 236 EXPECT_TRUE(parser->HasFinished()); |
| 237 } | 237 } |
| 238 } | 238 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 260 {"prev().foo1(\"\");next(true);", "foo1", "[\"\"]", true}, | 260 {"prev().foo1(\"\");next(true);", "foo1", "[\"\"]", true}, |
| 261 {"prev().foo2(\" \");next(true);", "foo2", "[\" \"]", true}, | 261 {"prev().foo2(\" \");next(true);", "foo2", "[\" \"]", true}, |
| 262 {"prev().foo3(\",\",true);next(true);", "foo3", "[\",\",true]", true}, | 262 {"prev().foo3(\",\",true);next(true);", "foo3", "[\",\",true]", true}, |
| 263 {"prev().foo4(\")\",true);next(true);", "foo4", "[\")\",true]", true}, | 263 {"prev().foo4(\")\",true);next(true);", "foo4", "[\")\",true]", true}, |
| 264 {"prev().foo5(\";\",true);next(true);", "foo5", "[\";\",true]", true}, | 264 {"prev().foo5(\";\",true);next(true);", "foo5", "[\";\",true]", true}, |
| 265 {"prev().foo6(\"/\",true).next(true);", "foo6", "[\"/\",true]", false}, | 265 {"prev().foo6(\"/\",true).next(true);", "foo6", "[\"/\",true]", false}, |
| 266 {"prev().foo7(\"//\",true).next(true);", "foo7", "[\"//\",true]", false}, | 266 {"prev().foo7(\"//\",true).next(true);", "foo7", "[\"//\",true]", false}, |
| 267 {"prev().foo8(\".\",true).next(true);", "foo8", "[\".\",true]", false}, | 267 {"prev().foo8(\".\",true).next(true);", "foo8", "[\".\",true]", false}, |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 270 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 271 SCOPED_TRACE(cases[i].expected_name); | 271 SCOPED_TRACE(cases[i].expected_name); |
| 272 scoped_ptr<JtlParser> parser( | 272 scoped_ptr<JtlParser> parser( |
| 273 CreateParserFromVerboseText(cases[i].source_code)); | 273 CreateParserFromVerboseText(cases[i].source_code)); |
| 274 ExpectNextOperation(parser.get(), "prev", "[]", false); | 274 ExpectNextOperation(parser.get(), "prev", "[]", false); |
| 275 ExpectNextOperation(parser.get(), | 275 ExpectNextOperation(parser.get(), |
| 276 cases[i].expected_name, | 276 cases[i].expected_name, |
| 277 cases[i].expected_args, | 277 cases[i].expected_args, |
| 278 cases[i].expected_ends_sentence); | 278 cases[i].expected_ends_sentence); |
| 279 ExpectNextOperation(parser.get(), "next", "[true]", true); | 279 ExpectNextOperation(parser.get(), "next", "[true]", true); |
| 280 EXPECT_TRUE(parser->HasFinished()); | 280 EXPECT_TRUE(parser->HasFinished()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 298 {"bad_quotes1(missing both, true).good();", "bad_quotes1"}, | 298 {"bad_quotes1(missing both, true).good();", "bad_quotes1"}, |
| 299 {"bad_quotes2(true, \"missing one).good(); //\"", "bad_quotes2"}, | 299 {"bad_quotes2(true, \"missing one).good(); //\"", "bad_quotes2"}, |
| 300 {"bad_quotes3(\"too\" \"much\", true).good();", "bad_quotes3"}, | 300 {"bad_quotes3(\"too\" \"much\", true).good();", "bad_quotes3"}, |
| 301 {"bad_missing_separator1", "bad_missing_separator1"}, | 301 {"bad_missing_separator1", "bad_missing_separator1"}, |
| 302 {"bad_missing_separator2()good();", "bad_missing_separator2"}, | 302 {"bad_missing_separator2()good();", "bad_missing_separator2"}, |
| 303 {"bad_parenthesis1(true.good();", "bad_parenthesis1"}, | 303 {"bad_parenthesis1(true.good();", "bad_parenthesis1"}, |
| 304 {"bad_parenthesis2(true.good());", "bad_parenthesis2"}, | 304 {"bad_parenthesis2(true.good());", "bad_parenthesis2"}, |
| 305 {"bad_parenthesis3).good();", "bad_parenthesis3"} | 305 {"bad_parenthesis3).good();", "bad_parenthesis3"} |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 308 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 309 SCOPED_TRACE(cases[i].operation_name); | 309 SCOPED_TRACE(cases[i].operation_name); |
| 310 scoped_ptr<JtlParser> parser( | 310 scoped_ptr<JtlParser> parser( |
| 311 CreateParserFromVerboseText(cases[i].source_code)); | 311 CreateParserFromVerboseText(cases[i].source_code)); |
| 312 ExpectNextOperationToFail(parser.get(), 0, cases[i].operation_name); | 312 ExpectNextOperationToFail(parser.get(), 0, cases[i].operation_name); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 TEST(JtlParser, SecondOperationIsIllFormed) { | 316 TEST(JtlParser, SecondOperationIsIllFormed) { |
| 317 struct TestCase { | 317 struct TestCase { |
| 318 const char* source_code; | 318 const char* source_code; |
| 319 const char* bad_operation_name; | 319 const char* bad_operation_name; |
| 320 } cases[] = { | 320 } cases[] = { |
| 321 {"\ngood(true,false)\n.bad_args(,);", "bad_args"}, | 321 {"\ngood(true,false)\n.bad_args(,);", "bad_args"}, |
| 322 {"\ngood(true,false)\n.bad_quotes1(missing both, true).good();", | 322 {"\ngood(true,false)\n.bad_quotes1(missing both, true).good();", |
| 323 "bad_quotes1"}, | 323 "bad_quotes1"}, |
| 324 {"\ngood(true,false)\n.bad_quotes2(\"missing one, true).good(); //\"", | 324 {"\ngood(true,false)\n.bad_quotes2(\"missing one, true).good(); //\"", |
| 325 "bad_quotes2"}, | 325 "bad_quotes2"}, |
| 326 {"\ngood(true,false)\n.bad_quotes3(\"too\" \"many\", true).good();", | 326 {"\ngood(true,false)\n.bad_quotes3(\"too\" \"many\", true).good();", |
| 327 "bad_quotes3"}, | 327 "bad_quotes3"}, |
| 328 {"\ngood(true,false)\n.bad_separator1()/good();", "bad_separator1"}, | 328 {"\ngood(true,false)\n.bad_separator1()/good();", "bad_separator1"}, |
| 329 {"\ngood(true,false)\n.missing_separator1", "missing_separator1"}, | 329 {"\ngood(true,false)\n.missing_separator1", "missing_separator1"}, |
| 330 {"\ngood(true,false)\n.missing_separator2()good();", | 330 {"\ngood(true,false)\n.missing_separator2()good();", |
| 331 "missing_separator2"}, | 331 "missing_separator2"}, |
| 332 {"\ngood(true,false)\n.bad_parens1(true.good();", "bad_parens1"}, | 332 {"\ngood(true,false)\n.bad_parens1(true.good();", "bad_parens1"}, |
| 333 {"\ngood(true,false)\n.bad_parens2(true.good());", "bad_parens2"}, | 333 {"\ngood(true,false)\n.bad_parens2(true.good());", "bad_parens2"}, |
| 334 {"\ngood(true,false)\n.bad_parens3).good();", "bad_parens3"} | 334 {"\ngood(true,false)\n.bad_parens3).good();", "bad_parens3"} |
| 335 }; | 335 }; |
| 336 | 336 |
| 337 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 337 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 338 SCOPED_TRACE(cases[i].bad_operation_name); | 338 SCOPED_TRACE(cases[i].bad_operation_name); |
| 339 scoped_ptr<JtlParser> parser( | 339 scoped_ptr<JtlParser> parser( |
| 340 CreateParserFromVerboseText(cases[i].source_code)); | 340 CreateParserFromVerboseText(cases[i].source_code)); |
| 341 ExpectNextOperation(parser.get(), "good", "[true,false]", false); | 341 ExpectNextOperation(parser.get(), "good", "[true,false]", false); |
| 342 ExpectNextOperationToFail(parser.get(), 2, cases[i].bad_operation_name); | 342 ExpectNextOperationToFail(parser.get(), 2, cases[i].bad_operation_name); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 } // namespace | 346 } // namespace |
| OLD | NEW |