@@ -3502,6 +3502,53 @@ int main(int argc, const char* argv[]) {
35023502 return runner.runCommandLine (argc, argv);
35033503}
35043504
3505+ struct MemberTemplateAs : JsonTest::TestCase {
3506+ template <typename T, typename F>
3507+ JsonTest::TestResult& EqEval (T v, F f) const {
3508+ const Json::Value j = v;
3509+ return JSONTEST_ASSERT_EQUAL (j.as <T>(), f (j));
3510+ }
3511+ };
3512+
3513+ JSONTEST_FIXTURE_LOCAL (MemberTemplateAs, BehavesSameAsNamedAs) {
3514+ const Json::Value jstr = " hello world" ;
3515+ JSONTEST_ASSERT_STRING_EQUAL (jstr.as <const char *>(), jstr.asCString ());
3516+ JSONTEST_ASSERT_STRING_EQUAL (jstr.as <Json::String>(), jstr.asString ());
3517+ #ifdef JSON_USE_CPPTL
3518+ JSONTEST_ASSERT_STRING_EQUAL (js.as <CppTL::ConstString>(), js.asConstString ());
3519+ #endif
3520+ EqEval (Json::Int (64 ), [](const Json::Value& j) { return j.asInt (); });
3521+ EqEval (Json::UInt (64 ), [](const Json::Value& j) { return j.asUInt (); });
3522+ #if defined(JSON_HAS_INT64)
3523+ EqEval (Json::Int64 (64 ), [](const Json::Value& j) { return j.asInt64 (); });
3524+ EqEval (Json::UInt64 (64 ), [](const Json::Value& j) { return j.asUInt64 (); });
3525+ #endif // if defined(JSON_HAS_INT64)
3526+ EqEval (Json::LargestInt (64 ),
3527+ [](const Json::Value& j) { return j.asLargestInt (); });
3528+ EqEval (Json::LargestUInt (64 ),
3529+ [](const Json::Value& j) { return j.asLargestUInt (); });
3530+
3531+ EqEval (69 .69f , [](const Json::Value& j) { return j.asFloat (); });
3532+ EqEval (69.69 , [](const Json::Value& j) { return j.asDouble (); });
3533+ EqEval (false , [](const Json::Value& j) { return j.asBool (); });
3534+ EqEval (true , [](const Json::Value& j) { return j.asBool (); });
3535+ }
3536+
3537+ class MemberTemplateIs : public JsonTest ::TestCase {};
3538+
3539+ JSONTEST_FIXTURE_LOCAL (MemberTemplateIs, BehavesSameAsNamedIs) {
3540+ const Json::Value values[] = {true , 142 , 40.63 , " hello world" };
3541+ for (const Json::Value& j : values) {
3542+ JSONTEST_ASSERT_EQUAL (j.is <bool >(), j.isBool ());
3543+ JSONTEST_ASSERT_EQUAL (j.is <Json::Int>(), j.isInt ());
3544+ JSONTEST_ASSERT_EQUAL (j.is <Json::Int64>(), j.isInt64 ());
3545+ JSONTEST_ASSERT_EQUAL (j.is <Json::UInt>(), j.isUInt ());
3546+ JSONTEST_ASSERT_EQUAL (j.is <Json::UInt64>(), j.isUInt64 ());
3547+ JSONTEST_ASSERT_EQUAL (j.is <double >(), j.isDouble ());
3548+ JSONTEST_ASSERT_EQUAL (j.is <Json::String>(), j.isString ());
3549+ }
3550+ }
3551+
35053552#if defined(__GNUC__)
35063553#pragma GCC diagnostic pop
35073554#endif
0 commit comments