#include "trace.hpp" #include "parser.hpp" int main() { { DECLARE( auto empty = json_parse( "{}" ) ); ASSERT( empty->length() == 0 ); ASSERT( empty->type() == json_type::object ); for ( auto i : { 0, -1, 1 } ) EXCEPT( std::out_of_range, empty->item_at( i ), "i =", i ); for ( auto s : { "", "0" } ) EXCEPT( std::out_of_range, empty->item_at( s ), "s =", s ); CLEAR(); } for ( auto s : { "{", "}", "}{", "{{}", "}}{", "key" } ) EXCEPT( json_error, json_parse( s ), "s =", s ); { DECLARE( auto nested = json_parse( "{empty: {}}" ) ); ASSERT( nested->length() == 1 ); ASSERT( nested->type() == json_type::object ); DECLARE( const auto &empty_0 = nested->item_at( 0 ) ); DECLARE( const auto &empty_1 = nested->item_at( "empty" ) ); ASSERT( empty_0.length() == 0 ); ASSERT( empty_0.type() == json_type::object ); ASSERT( empty_1.length() == 0 ); ASSERT( empty_1.type() == json_type::object ); } }