MCPcopy Create free account
hub / github.com/boostorg/json / testLookup

Method testLookup

test/object.cpp:1376–1483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1374 //------------------------------------------------------
1375
1376 void
1377 testLookup()
1378 {
1379 object o0;
1380 object o1({
1381 {"a", 1},
1382 {"b", true},
1383 {"c", "hello"}});
1384 auto const& co0 = o0;
1385 auto const& co1 = o1;
1386
1387 // at(key) &
1388 {
1389 BOOST_TEST(
1390 o1.at("a").is_number());
1391 BOOST_TEST_THROWS_WITH_LOCATION( (o1.at("d")) );
1392 }
1393
1394 // at(key) const&
1395 {
1396 BOOST_TEST(
1397 co1.at("a").is_number());
1398 BOOST_TEST_THROWS_WITH_LOCATION( (co1.at("d")) );
1399 }
1400
1401 // at(key) &&
1402 {
1403 BOOST_TEST(
1404 std::move(o1).at("a").is_number());
1405 BOOST_TEST_THROWS_WITH_LOCATION( (std::move(o1).at("d")) );
1406 value&& rv = std::move(o1).at("a");
1407 (void)rv;
1408 }
1409
1410 // try_at(key) &
1411 {
1412 BOOST_TEST( o1.try_at("a")->is_number() );
1413
1414 system::error_code const ec = o1.try_at("d").error();
1415 BOOST_TEST( ec == error::out_of_range );
1416 BOOST_TEST( ec.has_location() );
1417 }
1418
1419 // try_at(key) const&
1420 {
1421 BOOST_TEST( co1.try_at("a")->is_number() );
1422
1423 system::error_code const ec = o1.try_at("d").error();
1424 BOOST_TEST( ec == error::out_of_range );
1425 BOOST_TEST( ec.has_location() );
1426 }
1427
1428 // operator[&](key)
1429 {
1430 object o({
1431 {"a", 1},
1432 {"b", true},
1433 {"c", "hello"}});

Callers

nothing calls this directly

Calls 7

is_numberMethod · 0.80
is_nullMethod · 0.80
findMethod · 0.80
keyMethod · 0.80
is_int64Method · 0.80
objectClass · 0.50
endMethod · 0.45

Tested by

no test coverage detected