OLD | NEW |
1 // Copyright (c) 2011 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_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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ASSERT_EQ("[5,2]", output_js); | 112 ASSERT_EQ("[5,2]", output_js); |
113 | 113 |
114 DictionaryValue binary_dict; | 114 DictionaryValue binary_dict; |
115 binary_dict.Set("a", Value::CreateIntegerValue(5)); | 115 binary_dict.Set("a", Value::CreateIntegerValue(5)); |
116 binary_dict.Set("b", BinaryValue::CreateWithCopiedBuffer("asdf", 4)); | 116 binary_dict.Set("b", BinaryValue::CreateWithCopiedBuffer("asdf", 4)); |
117 binary_dict.Set("c", Value::CreateIntegerValue(2)); | 117 binary_dict.Set("c", Value::CreateIntegerValue(2)); |
118 JSONWriter::WriteWithOptions(&binary_dict, false, | 118 JSONWriter::WriteWithOptions(&binary_dict, false, |
119 JSONWriter::OPTIONS_OMIT_BINARY_VALUES, | 119 JSONWriter::OPTIONS_OMIT_BINARY_VALUES, |
120 &output_js); | 120 &output_js); |
121 ASSERT_EQ("{\"a\":5,\"c\":2}", output_js); | 121 ASSERT_EQ("{\"a\":5,\"c\":2}", output_js); |
| 122 |
| 123 // Test allowing a double with no fractional part to be written as an integer. |
| 124 FundamentalValue double_value(1e10); |
| 125 JSONWriter::WriteWithOptions( |
| 126 &double_value, false, |
| 127 JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION, |
| 128 &output_js); |
| 129 ASSERT_EQ("10000000000", output_js); |
122 } | 130 } |
123 | 131 |
124 } // namespace base | 132 } // namespace base |
OLD | NEW |