diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-09-23 12:50:52 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2020-10-05 13:49:59 (GMT) |
commit | 3059e6aed7ac3e773dd1f184558b9fd8a4b7b11e (patch) | |
tree | 07d066ec261fd9b45d09adafe0d1371c4276a365 /Tests/CMakeLib | |
parent | 8682d1b7b262258b779cba66a0e6e76f6617d588 (diff) | |
download | CMake-3059e6aed7ac3e773dd1f184558b9fd8a4b7b11e.zip CMake-3059e6aed7ac3e773dd1f184558b9fd8a4b7b11e.tar.gz CMake-3059e6aed7ac3e773dd1f184558b9fd8a4b7b11e.tar.bz2 |
cmJSONHelpers: Add new Bind() function
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r-- | Tests/CMakeLib/testJSONHelpers.cxx | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/Tests/CMakeLib/testJSONHelpers.cxx b/Tests/CMakeLib/testJSONHelpers.cxx index 78eed5b..a45d320 100644 --- a/Tests/CMakeLib/testJSONHelpers.cxx +++ b/Tests/CMakeLib/testJSONHelpers.cxx @@ -37,6 +37,7 @@ enum class ErrorCode InvalidInt, InvalidBool, InvalidString, + InvalidSubObject, InvalidObject, InvalidArray, MissingRequired, @@ -148,15 +149,20 @@ bool testString() bool testObject() { + auto const subhelper = + cmJSONObjectHelper<ObjectStruct, ErrorCode>(ErrorCode::Success, + ErrorCode::InvalidSubObject) + .Bind("subfield"_s, &ObjectStruct::Field2, IntHelper); auto const helper = cmJSONObjectHelper<ObjectStruct, ErrorCode>( ErrorCode::Success, ErrorCode::InvalidObject) .Bind("field1"_s, &ObjectStruct::Field1, StringHelper) - .Bind("field2"_s, &ObjectStruct::Field2, IntHelper) + .Bind("field2"_s, subhelper) .Bind<std::string>("field3"_s, nullptr, StringHelper); Json::Value v(Json::objectValue); v["field1"] = "Hello"; - v["field2"] = 2; + v["field2"] = Json::objectValue; + v["field2"]["subfield"] = 2; v["field3"] = "world!"; v["extra"] = "extra"; @@ -165,29 +171,34 @@ bool testObject() ASSERT_TRUE(s1.Field1 == "Hello"); ASSERT_TRUE(s1.Field2 == 2); - v["field2"] = "wrong"; + v["field2"]["subfield"] = "wrong"; ObjectStruct s2; ASSERT_TRUE(helper(s2, &v) == ErrorCode::InvalidInt); - v.removeMember("field2"); + v["field2"].removeMember("subfield"); ObjectStruct s3; - ASSERT_TRUE(helper(s3, &v) == ErrorCode::InvalidObject); + ASSERT_TRUE(helper(s3, &v) == ErrorCode::InvalidSubObject); - v["field2"] = 2; - v["field3"] = 3; + v.removeMember("field2"); ObjectStruct s4; - ASSERT_TRUE(helper(s4, &v) == ErrorCode::InvalidString); + ASSERT_TRUE(helper(s4, &v) == ErrorCode::InvalidObject); - v.removeMember("field3"); + v["field2"] = Json::objectValue; + v["field2"]["subfield"] = 2; + v["field3"] = 3; ObjectStruct s5; - ASSERT_TRUE(helper(s5, &v) == ErrorCode::InvalidObject); + ASSERT_TRUE(helper(s5, &v) == ErrorCode::InvalidString); - v = "Hello"; + v.removeMember("field3"); ObjectStruct s6; ASSERT_TRUE(helper(s6, &v) == ErrorCode::InvalidObject); + v = "Hello"; ObjectStruct s7; - ASSERT_TRUE(helper(s7, nullptr) == ErrorCode::InvalidObject); + ASSERT_TRUE(helper(s7, &v) == ErrorCode::InvalidObject); + + ObjectStruct s8; + ASSERT_TRUE(helper(s8, nullptr) == ErrorCode::InvalidObject); return true; } |