#include "query.hpp" #include "trace.hpp" int main() { DECLARE( auto f = []( path, const json_value &v ) { return v.type() == json_type::integer ? v.int_value() : 0; } ); DECLARE( auto g = []( path, int x ) { return x + 7; } ); DECLARE( auto tt = []( path, const auto & ) { return true; } ); DECLARE( auto q = query( "{ a: 1, b: 2 }" ) ); DECLARE( path p ); TRACE( p.extend( "b" ) ); SAVE(); int i = 0; ASSERT_FOR( ( p, x ), q[ p ], ( ++i, x.int_value() == 2 ), "i =", i ); ASSERT( i == 1, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).filter( tt ), ( ++i, x == 2 ), "i =", i ); ASSERT( i == 2, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q.filter( tt ).map( f )[ p ], ( ++i, x == 2 ), "i =", i ); ASSERT( i == 3, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).map( g ), ( ++i, x == 9 ), "i =", i ); ASSERT( i == 4, "i =", i ); CLEAR(); }