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

Method testParseIntoValue

test/parse_into.cpp:103–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101
102 template<class T>
103 void testParseIntoValue( value const& jv )
104 {
105#if defined(__GNUC__) && __GNUC__ < 5
106# pragma GCC diagnostic push
107# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
108#endif
109 T t1 = value_to<T>(jv);
110 (void)t1; // older GCC thinks t1 can be unused
111 std::string json = serialize(jv);
112
113 T t2{};
114 system::error_code jec;
115 parse_into(t2, json, jec);
116 BOOST_TEST( !jec.failed() ) && BOOST_TEST( t1 == t2 );
117
118 T t3{};
119 std::error_code ec;
120 parse_into(t3, json, ec);
121 BOOST_TEST( !ec ) && BOOST_TEST( t1 == t3 );
122
123 T t4{};
124 parse_into(t4, json);
125 BOOST_TEST( t1 == t4 );
126
127 std::istringstream is(json);
128 T t5{};
129 jec = {};
130 parse_into(t5, is, jec);
131 BOOST_TEST( !jec.failed() ) && BOOST_TEST( t1 == t5 );
132
133 is.clear();
134 is.seekg(0);
135 T t6{};
136 ec = {};
137 parse_into(t6, is, ec);
138 BOOST_TEST( !ec ) && BOOST_TEST( t1 == t6 );
139
140 is.str(json);
141 is.clear();
142 T t7{};
143 parse_into(t7, is);
144 BOOST_TEST( t1 == t7 );
145
146 parse_options opt;
147 opt.allow_comments = true;
148 json = "// this is a comment\n" + json;
149
150 T t8{};
151 parser_for<T> p( opt, &t8 );
152 for( auto& c: json )
153 {
154 std::size_t const n = p.write_some( true, &c, 1, jec );
155 BOOST_TEST( !jec.failed() );
156 BOOST_TEST( n == 1 );
157 }
158 p.write_some(false, nullptr, 0, jec);
159 BOOST_TEST( !jec.failed() );
160 BOOST_TEST( t1 == t8 );

Callers

nothing calls this directly

Calls 4

serializeFunction · 0.85
parse_intoFunction · 0.85
clearMethod · 0.45
write_someMethod · 0.45

Tested by

no test coverage detected