Commit cc91856e authored by Nigel Tao's avatar Nigel Tao Committed by Commit Bot

Upgrade json_schema_compiler from deprecated base::JSONReader API

Bug: 1070409
Change-Id: I77f1865c891b606f96886c106bb0f0f10e9a0241
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212118
Commit-Queue: Nigel Tao <nigeltao@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771546}
parent a3da69e5
...@@ -177,8 +177,8 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -177,8 +177,8 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
// NestedChoices. // NestedChoices.
{ {
// The plain integer choice. // The plain integer choice.
std::unique_ptr<base::Value> value = ReadJson("42"); base::Value value = ReadJson("42");
std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(*value); std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(value);
ASSERT_TRUE(obj); ASSERT_TRUE(obj);
ASSERT_TRUE(obj->as_integer); ASSERT_TRUE(obj->as_integer);
...@@ -186,13 +186,13 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -186,13 +186,13 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
EXPECT_FALSE(obj->as_choice2); EXPECT_FALSE(obj->as_choice2);
EXPECT_EQ(42, *obj->as_integer); EXPECT_EQ(42, *obj->as_integer);
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(value, *obj->ToValue());
} }
{ {
// The string choice within the first choice. // The string choice within the first choice.
std::unique_ptr<base::Value> value = ReadJson("\"foo\""); base::Value value = ReadJson("\"foo\"");
std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(*value); std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(value);
ASSERT_TRUE(obj); ASSERT_TRUE(obj);
EXPECT_FALSE(obj->as_integer); EXPECT_FALSE(obj->as_integer);
...@@ -202,13 +202,13 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -202,13 +202,13 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
EXPECT_FALSE(obj->as_choice1->as_boolean); EXPECT_FALSE(obj->as_choice1->as_boolean);
EXPECT_EQ("foo", *obj->as_choice1->as_string); EXPECT_EQ("foo", *obj->as_choice1->as_string);
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(value, *obj->ToValue());
} }
{ {
// The boolean choice within the first choice. // The boolean choice within the first choice.
std::unique_ptr<base::Value> value = ReadJson("true"); base::Value value = ReadJson("true");
std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(*value); std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(value);
ASSERT_TRUE(obj); ASSERT_TRUE(obj);
EXPECT_FALSE(obj->as_integer); EXPECT_FALSE(obj->as_integer);
...@@ -218,13 +218,13 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -218,13 +218,13 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
ASSERT_TRUE(obj->as_choice1->as_boolean); ASSERT_TRUE(obj->as_choice1->as_boolean);
EXPECT_TRUE(*obj->as_choice1->as_boolean); EXPECT_TRUE(*obj->as_choice1->as_boolean);
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(value, *obj->ToValue());
} }
{ {
// The double choice within the second choice. // The double choice within the second choice.
std::unique_ptr<base::Value> value = ReadJson("42.0"); base::Value value = ReadJson("42.0");
std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(*value); std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(value);
ASSERT_TRUE(obj); ASSERT_TRUE(obj);
EXPECT_FALSE(obj->as_integer); EXPECT_FALSE(obj->as_integer);
...@@ -235,14 +235,14 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -235,14 +235,14 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
EXPECT_FALSE(obj->as_choice2->as_choice_types); EXPECT_FALSE(obj->as_choice2->as_choice_types);
EXPECT_EQ(42.0, *obj->as_choice2->as_double); EXPECT_EQ(42.0, *obj->as_choice2->as_double);
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(value, *obj->ToValue());
} }
{ {
// The ChoiceType choice within the second choice. // The ChoiceType choice within the second choice.
std::unique_ptr<base::Value> value = base::Value value =
ReadJson("{\"integers\": [1, 2], \"strings\": \"foo\"}"); ReadJson("{\"integers\": [1, 2], \"strings\": \"foo\"}");
std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(*value); std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(value);
ASSERT_TRUE(obj); ASSERT_TRUE(obj);
EXPECT_FALSE(obj->as_integer); EXPECT_FALSE(obj->as_integer);
...@@ -262,17 +262,17 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -262,17 +262,17 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
EXPECT_EQ("foo", *choice_type->strings->as_string); EXPECT_EQ("foo", *choice_type->strings->as_string);
} }
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(value, *obj->ToValue());
} }
{ {
// The array of ChoiceTypes within the second choice. // The array of ChoiceTypes within the second choice.
std::unique_ptr<base::Value> value = ReadJson( base::Value value = ReadJson(
"[" "["
" {\"integers\": [1, 2], \"strings\": \"foo\"}," " {\"integers\": [1, 2], \"strings\": \"foo\"},"
" {\"integers\": 3, \"strings\": [\"bar\", \"baz\"]}" " {\"integers\": 3, \"strings\": [\"bar\", \"baz\"]}"
"]"); "]");
std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(*value); std::unique_ptr<NestedChoice> obj = NestedChoice::FromValue(value);
ASSERT_TRUE(obj); ASSERT_TRUE(obj);
EXPECT_FALSE(obj->as_integer); EXPECT_FALSE(obj->as_integer);
...@@ -284,7 +284,7 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) { ...@@ -284,7 +284,7 @@ TEST(JsonSchemaCompilerChoicesTest, NestedChoices) {
// Bleh too much effort to test everything. // Bleh too much effort to test everything.
ASSERT_EQ(2u, obj->as_choice2->as_choice_types->size()); ASSERT_EQ(2u, obj->as_choice2->as_choice_types->size());
EXPECT_EQ(*value, *obj->ToValue()); EXPECT_EQ(value, *obj->ToValue());
} }
} }
......
...@@ -13,15 +13,13 @@ ...@@ -13,15 +13,13 @@
namespace json_schema_compiler { namespace json_schema_compiler {
namespace test_util { namespace test_util {
std::unique_ptr<base::Value> ReadJson(const base::StringPiece& json) { base::Value ReadJson(const base::StringPiece& json) {
int error_code; base::JSONReader::ValueWithError parsed_json =
std::string error_msg; base::JSONReader::ReadAndReturnValueWithError(
std::unique_ptr<base::Value> result( json, base::JSON_ALLOW_TRAILING_COMMAS);
base::JSONReader::ReadAndReturnErrorDeprecated(
json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error_msg));
// CHECK not ASSERT since passing invalid |json| is a test error. // CHECK not ASSERT since passing invalid |json| is a test error.
CHECK(result) << error_msg; CHECK(parsed_json.value) << parsed_json.error_message;
return result; return std::move(*parsed_json.value);
} }
std::unique_ptr<base::ListValue> List(std::unique_ptr<base::Value> a) { std::unique_ptr<base::ListValue> List(std::unique_ptr<base::Value> a) {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace json_schema_compiler { namespace json_schema_compiler {
namespace test_util { namespace test_util {
std::unique_ptr<base::Value> ReadJson(const base::StringPiece& json); base::Value ReadJson(const base::StringPiece& json);
template <typename T> template <typename T>
std::vector<T> Vector(const T& a) { std::vector<T> Vector(const T& a) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment