| 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_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 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 root_dict.Set("list", list.Pass()); | 63 root_dict.Set("list", list.Pass()); |
| 64 | 64 |
| 65 // Test the pretty-printer. | 65 // Test the pretty-printer. |
| 66 EXPECT_TRUE(JSONWriter::Write(root_dict, &output_js)); | 66 EXPECT_TRUE(JSONWriter::Write(root_dict, &output_js)); |
| 67 EXPECT_EQ("{\"list\":[{\"inner int\":10},[],true]}", output_js); | 67 EXPECT_EQ("{\"list\":[{\"inner int\":10},[],true]}", output_js); |
| 68 EXPECT_TRUE(JSONWriter::WriteWithOptions( | 68 EXPECT_TRUE(JSONWriter::WriteWithOptions( |
| 69 root_dict, JSONWriter::OPTIONS_PRETTY_PRINT, &output_js)); | 69 root_dict, JSONWriter::OPTIONS_PRETTY_PRINT, &output_js)); |
| 70 | 70 |
| 71 // The pretty-printer uses a different newline style on Windows than on | 71 // The pretty-printer uses a different newline style on Windows than on |
| 72 // other platforms. | 72 // other platforms. |
| 73 #if defined(OS_WIN) | |
| 74 #define JSON_NEWLINE "\r\n" | |
| 75 #else | |
| 76 #define JSON_NEWLINE "\n" | 73 #define JSON_NEWLINE "\n" |
| 77 #endif | |
| 78 EXPECT_EQ("{" JSON_NEWLINE | 74 EXPECT_EQ("{" JSON_NEWLINE |
| 79 " \"list\": [ {" JSON_NEWLINE | 75 " \"list\": [ {" JSON_NEWLINE |
| 80 " \"inner int\": 10" JSON_NEWLINE | 76 " \"inner int\": 10" JSON_NEWLINE |
| 81 " }, [ ], true ]" JSON_NEWLINE | 77 " }, [ ], true ]" JSON_NEWLINE |
| 82 "}" JSON_NEWLINE, | 78 "}" JSON_NEWLINE, |
| 83 output_js); | 79 output_js); |
| 84 #undef JSON_NEWLINE | 80 #undef JSON_NEWLINE |
| 85 } | 81 } |
| 86 | 82 |
| 87 TEST(JSONWriterTest, KeysWithPeriods) { | 83 TEST(JSONWriterTest, KeysWithPeriods) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 141 |
| 146 // Test allowing a double with no fractional part to be written as an integer. | 142 // Test allowing a double with no fractional part to be written as an integer. |
| 147 FundamentalValue double_value(1e10); | 143 FundamentalValue double_value(1e10); |
| 148 EXPECT_TRUE(JSONWriter::WriteWithOptions( | 144 EXPECT_TRUE(JSONWriter::WriteWithOptions( |
| 149 double_value, JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION, | 145 double_value, JSONWriter::OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION, |
| 150 &output_js)); | 146 &output_js)); |
| 151 EXPECT_EQ("10000000000", output_js); | 147 EXPECT_EQ("10000000000", output_js); |
| 152 } | 148 } |
| 153 | 149 |
| 154 } // namespace base | 150 } // namespace base |
| OLD | NEW |