| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "base/json_reader.h" | 6 #include "base/json_reader.h" |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 ASSERT_DOUBLE_EQ(9.87654321, real_val); | 301 ASSERT_DOUBLE_EQ(9.87654321, real_val); |
| 302 Value* null_val = NULL; | 302 Value* null_val = NULL; |
| 303 ASSERT_TRUE(dict_val->Get(L"null", &null_val)); | 303 ASSERT_TRUE(dict_val->Get(L"null", &null_val)); |
| 304 ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL)); | 304 ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL)); |
| 305 str_val.clear(); | 305 str_val.clear(); |
| 306 ASSERT_TRUE(dict_val->GetString(L"S", &str_val)); | 306 ASSERT_TRUE(dict_val->GetString(L"S", &str_val)); |
| 307 ASSERT_EQ(L"str", str_val); | 307 ASSERT_EQ(L"str", str_val); |
| 308 | 308 |
| 309 root2.reset(JSONReader::Read( | 309 root2.reset(JSONReader::Read( |
| 310 "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true)); | 310 "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true)); |
| 311 ASSERT_TRUE(root2.get()); |
| 312 EXPECT_TRUE(root->Equals(root2.get())); |
| 313 |
| 314 // Test newline equivalence. |
| 315 root2.reset(JSONReader::Read( |
| 316 "{\n" |
| 317 " \"number\":9.87654321,\n" |
| 318 " \"null\":null,\n" |
| 319 " \"\\x53\":\"str\",\n" |
| 320 "}\n", true)); |
| 321 ASSERT_TRUE(root2.get()); |
| 322 EXPECT_TRUE(root->Equals(root2.get())); |
| 323 |
| 324 root2.reset(JSONReader::Read( |
| 325 "{\r\n" |
| 326 " \"number\":9.87654321,\r\n" |
| 327 " \"null\":null,\r\n" |
| 328 " \"\\x53\":\"str\",\r\n" |
| 329 "}\r\n", true)); |
| 330 ASSERT_TRUE(root2.get()); |
| 311 EXPECT_TRUE(root->Equals(root2.get())); | 331 EXPECT_TRUE(root->Equals(root2.get())); |
| 312 | 332 |
| 313 // Test nesting | 333 // Test nesting |
| 314 root.reset(JSONReader::Read( | 334 root.reset(JSONReader::Read( |
| 315 "{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}", false)); | 335 "{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}", false)); |
| 316 ASSERT_TRUE(root.get()); | 336 ASSERT_TRUE(root.get()); |
| 317 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); | 337 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
| 318 dict_val = static_cast<DictionaryValue*>(root.get()); | 338 dict_val = static_cast<DictionaryValue*>(root.get()); |
| 319 DictionaryValue* inner_dict = NULL; | 339 DictionaryValue* inner_dict = NULL; |
| 320 ASSERT_TRUE(dict_val->GetDictionary(L"inner", &inner_dict)); | 340 ASSERT_TRUE(dict_val->GetDictionary(L"inner", &inner_dict)); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), | 503 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), |
| 484 error_message); | 504 error_message); |
| 485 | 505 |
| 486 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false, | 506 root.reset(JSONReader::ReadAndReturnError("[\"xxx\\q\"]", false, |
| 487 &error_message)); | 507 &error_message)); |
| 488 EXPECT_FALSE(root.get()); | 508 EXPECT_FALSE(root.get()); |
| 489 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), | 509 EXPECT_EQ(JSONReader::FormatErrorMessage(1, 7, JSONReader::kInvalidEscape), |
| 490 error_message); | 510 error_message); |
| 491 | 511 |
| 492 } | 512 } |
| OLD | NEW |