OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/json/json_parser.h" | 5 #include "base/json/json_parser.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.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/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 // Test line and column counting | 212 // Test line and column counting |
213 const char* big_json = "[\n0,\n1,\n2,\n3,4,5,6 7,\n8,\n9\n]"; | 213 const char* big_json = "[\n0,\n1,\n2,\n3,4,5,6 7,\n8,\n9\n]"; |
214 // error here ---------------------------------^ | 214 // error here ---------------------------------^ |
215 root.reset(JSONReader::ReadAndReturnError(big_json, JSON_PARSE_RFC, | 215 root.reset(JSONReader::ReadAndReturnError(big_json, JSON_PARSE_RFC, |
216 &error_code, &error_message)); | 216 &error_code, &error_message)); |
217 EXPECT_FALSE(root.get()); | 217 EXPECT_FALSE(root.get()); |
218 EXPECT_EQ(JSONParser::FormatErrorMessage(5, 10, JSONReader::kSyntaxError), | 218 EXPECT_EQ(JSONParser::FormatErrorMessage(5, 10, JSONReader::kSyntaxError), |
219 error_message); | 219 error_message); |
220 EXPECT_EQ(JSONReader::JSON_SYNTAX_ERROR, error_code); | 220 EXPECT_EQ(JSONReader::JSON_SYNTAX_ERROR, error_code); |
221 | 221 |
222 // Test line and column counting with "\r\n" line ending | |
223 const char* big_json_crlf = | |
Mark Mentovai
2013/02/04 17:41:00
This and line 212 should both be “const char xxx[]
| |
224 "[\r\n0,\r\n1,\r\n2,\r\n3,4,5,6 7,\r\n8,\r\n9\r\n]"; | |
Mark Mentovai
2013/02/04 17:41:00
This file uses four (not two) spaces of extra inde
| |
225 // error here --------------------^ | |
226 root.reset(JSONReader::ReadAndReturnError(big_json_crlf, JSON_PARSE_RFC, | |
227 &error_code, &error_message)); | |
Mark Mentovai
2013/02/04 17:41:00
You haven’t cleared error_message or error_code fr
| |
228 EXPECT_FALSE(root.get()); | |
229 EXPECT_EQ(JSONParser::FormatErrorMessage(5, 10, JSONReader::kSyntaxError), | |
230 error_message); | |
231 EXPECT_EQ(JSONReader::JSON_SYNTAX_ERROR, error_code); | |
232 | |
222 // Test each of the error conditions | 233 // Test each of the error conditions |
223 root.reset(JSONReader::ReadAndReturnError("{},{}", JSON_PARSE_RFC, | 234 root.reset(JSONReader::ReadAndReturnError("{},{}", JSON_PARSE_RFC, |
224 &error_code, &error_message)); | 235 &error_code, &error_message)); |
225 EXPECT_FALSE(root.get()); | 236 EXPECT_FALSE(root.get()); |
226 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 3, | 237 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 3, |
227 JSONReader::kUnexpectedDataAfterRoot), error_message); | 238 JSONReader::kUnexpectedDataAfterRoot), error_message); |
228 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, error_code); | 239 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, error_code); |
229 | 240 |
230 std::string nested_json; | 241 std::string nested_json; |
231 for (int i = 0; i < 101; ++i) { | 242 for (int i = 0; i < 101; ++i) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 std::string error_message; | 308 std::string error_message; |
298 int error_code = 0; | 309 int error_code = 0; |
299 scoped_ptr<Value> root( | 310 scoped_ptr<Value> root( |
300 JSONReader::ReadAndReturnError(kUtf8Data, JSON_PARSE_RFC, &error_code, | 311 JSONReader::ReadAndReturnError(kUtf8Data, JSON_PARSE_RFC, &error_code, |
301 &error_message)); | 312 &error_message)); |
302 EXPECT_TRUE(root.get()) << error_message; | 313 EXPECT_TRUE(root.get()) << error_message; |
303 } | 314 } |
304 | 315 |
305 } // namespace internal | 316 } // namespace internal |
306 } // namespace base | 317 } // namespace base |
OLD | NEW |