summaryrefslogtreecommitdiffstats
path: root/base/values.cc
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 03:39:35 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 03:39:35 +0000
commite4ef831a8f0bee7e9d484e837fcb1f8c6ea3e3af (patch)
treeec8a31d95e8811a257428fb341440d47e36ca699 /base/values.cc
parentdf7c28c63d70315a0004ad1e5c965c2d808d7034 (diff)
downloadchromium_src-e4ef831a8f0bee7e9d484e837fcb1f8c6ea3e3af.zip
chromium_src-e4ef831a8f0bee7e9d484e837fcb1f8c6ea3e3af.tar.gz
chromium_src-e4ef831a8f0bee7e9d484e837fcb1f8c6ea3e3af.tar.bz2
Add an ostream operator to Value (based on JSONWriter) so that assertions
involving Value::Equals are much easier to understand. For example, ListValue list; DictionaryValue dict; ASSERT_TRUE(Value::Equals(&list, &dict)) << list << "does not equal\n" << dict; will now print Value of: Value::Equals(&list, &dict) Actual: false Expected: true [ ] does not equal { } Review URL: https://chromiumcodereview.appspot.com/10915194 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.cc')
-rw-r--r--base/values.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/base/values.cc b/base/values.cc
index c9b5eef..1063eff 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -5,8 +5,10 @@
#include "base/values.h"
#include <algorithm>
+#include <ostream>
#include "base/float_util.h"
+#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -1057,4 +1059,12 @@ bool ListValue::Equals(const Value* other) const {
ValueSerializer::~ValueSerializer() {
}
+std::ostream& operator<<(std::ostream& out, const Value& value) {
+ std::string json;
+ JSONWriter::WriteWithOptions(&value,
+ JSONWriter::OPTIONS_PRETTY_PRINT,
+ &json);
+ return out << json;
+}
+
} // namespace base