OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_writer.h" | 5 #include "base/json/json_writer.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
11 TEST(JSONWriterTest, Writing) { | 11 TEST(JSONWriterTest, Writing) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #else | 69 #else |
70 #define JSON_NEWLINE "\n" | 70 #define JSON_NEWLINE "\n" |
71 #endif | 71 #endif |
72 ASSERT_EQ("{" JSON_NEWLINE | 72 ASSERT_EQ("{" JSON_NEWLINE |
73 " \"list\": [ {" JSON_NEWLINE | 73 " \"list\": [ {" JSON_NEWLINE |
74 " \"inner int\": 10" JSON_NEWLINE | 74 " \"inner int\": 10" JSON_NEWLINE |
75 " }, [ ], true ]" JSON_NEWLINE | 75 " }, [ ], true ]" JSON_NEWLINE |
76 "}" JSON_NEWLINE, | 76 "}" JSON_NEWLINE, |
77 output_js); | 77 output_js); |
78 #undef JSON_NEWLINE | 78 #undef JSON_NEWLINE |
| 79 |
| 80 // Test keys with periods |
| 81 DictionaryValue period_dict; |
| 82 period_dict.SetWithoutPathExpansion(L"a.b", Value::CreateIntegerValue(3)); |
| 83 period_dict.SetWithoutPathExpansion(L"c", Value::CreateIntegerValue(2)); |
| 84 DictionaryValue* period_dict2 = new DictionaryValue; |
| 85 period_dict2->SetWithoutPathExpansion(L"g.h.i.j", |
| 86 Value::CreateIntegerValue(1)); |
| 87 period_dict.SetWithoutPathExpansion(L"d.e.f", period_dict2); |
| 88 JSONWriter::Write(&period_dict, false, &output_js); |
| 89 ASSERT_EQ("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}", output_js); |
| 90 |
| 91 DictionaryValue period_dict3; |
| 92 period_dict3.Set(L"a.b", Value::CreateIntegerValue(2)); |
| 93 period_dict3.SetWithoutPathExpansion(L"a.b", Value::CreateIntegerValue(1)); |
| 94 JSONWriter::Write(&period_dict3, false, &output_js); |
| 95 ASSERT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js); |
79 } | 96 } |
80 | 97 |
81 } // namespace base | 98 } // namespace base |
OLD | NEW |