Index: base/test/values_test_util.cc |
diff --git a/base/test/values_test_util.cc b/base/test/values_test_util.cc |
index c5dfd7946adc2333e67fa96dac955e2953126879..32f5214ad523d66796446168bd9fc4b0f6934c6a 100644 |
--- a/base/test/values_test_util.cc |
+++ b/base/test/values_test_util.cc |
@@ -74,5 +74,28 @@ scoped_ptr<Value> ParseJson(base::StringPiece json) { |
return result.Pass(); |
} |
+scoped_ptr<DictionaryValue> ParseJsonDictionaryWithSingleQuotes( |
Paweł Hajdan Jr.
2014/03/03 22:50:47
Why not let the caller do things this code is doin
scheib
2014/03/03 22:56:43
To avoid code duplication and increase test readab
not at google - send to devlin
2014/03/03 22:59:04
FWIW this is a function I've also often very much
Paweł Hajdan Jr.
2014/03/05 03:52:56
Extracting this to a function is fine. Having that
scheib
2014/03/05 04:49:41
Fair point. Here's my justification: It is highly
|
+ base::StringPiece json) { |
+ std::string json_single_quotes_replaced = json.as_string(); |
Jeffrey Yasskin
2014/03/04 01:41:48
Since you're making a copy here anyway, you should
scheib
2014/03/04 15:34:31
Done.
|
+ std::replace(json_single_quotes_replaced.begin(), |
+ json_single_quotes_replaced.end(), |
+ '\'', |
+ '"'); |
+ std::string error_msg; |
+ scoped_ptr<Value> result( |
+ base::JSONReader::ReadAndReturnError(json_single_quotes_replaced, |
+ base::JSON_ALLOW_TRAILING_COMMAS, |
+ NULL, |
+ &error_msg)); |
+ scoped_ptr<base::DictionaryValue> result_dict; |
+ if (result && result->IsType(base::Value::TYPE_DICTIONARY)) { |
+ result_dict.reset(static_cast<DictionaryValue*>(result.release())); |
+ } else { |
+ ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg; |
+ result_dict.reset(new base::DictionaryValue()); |
+ } |
+ return result_dict.Pass(); |
+} |
+ |
} // namespace test |
} // namespace base |