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

Method testIstream

test/value.cpp:2549–2633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2547 }
2548
2549 void
2550 testIstream()
2551 {
2552 std::istringstream ss(
2553 R"({ "x": 1
2554 , "y": 2
2555 , "z": [77, null, true, "qwerty uiop"]
2556 }_12)");
2557 value jv;
2558
2559 ss >> jv;
2560 BOOST_TEST( !!ss );
2561 BOOST_TEST((
2562 jv == value{
2563 {"x", 1},
2564 {"y", 2},
2565 {"z", {77, nullptr, true, "qwerty uiop"}}} ));
2566
2567 // check we didn't consume any extra characters
2568 std::string s;
2569 std::getline(ss, s);
2570 BOOST_TEST( s == "_12" );
2571
2572 ss.clear();
2573 ss.str("23");
2574 ss >> jv;
2575 BOOST_TEST( jv == 23 );
2576
2577 ss.clear();
2578 ss.str("");
2579 ss >> jv;
2580 BOOST_TEST( jv == 23 );
2581 BOOST_TEST( ss.rdstate() == (std::ios::failbit | std::ios::eofbit) );
2582
2583 ss.clear();
2584 ss.str("nu");
2585 ss >> jv;
2586 BOOST_TEST( jv == 23 );
2587 BOOST_TEST( ss.rdstate() == (std::ios::failbit | std::ios::eofbit) );
2588
2589 ss.clear();
2590 ss.str("[1,2,3,4,]");
2591 ss >> jv;
2592 BOOST_TEST( jv == 23 );
2593 BOOST_TEST( ss.rdstate() == std::ios::failbit );
2594
2595 {
2596 throwing_buffer buf;
2597 std::istream is(&buf);
2598 is >> jv;
2599 BOOST_TEST( jv == 23 );
2600 BOOST_TEST( is.rdstate() & std::ios::badbit );
2601 }
2602 {
2603 throwing_buffer buf;
2604 std::istream is(&buf);
2605 is.exceptions(std::ios::badbit);
2606 BOOST_TEST_THROWS( is >> jv, std::invalid_argument );

Callers

nothing calls this directly

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected