#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 at = []( int i ) { return i == 3 ? 0 : i + 1; } ); DECLARE( auto q = query( "[ 1, 2, 3 ]" ) ); DECLARE( path p ); TRACE( p.extend( 1 ) ); SAVE(); int i = 0; ASSERT_FOR( ( p, j ), q.map( f ), at( i++ ) == j, "i =", i ); ASSERT( i == 4, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ], ( ++i, x.int_value() == 2 ), "i =", i ); ASSERT( i == 5, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).filter( tt ), ( ++i, x == 2 ), "i =", i ); ASSERT( i == 6, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q.filter( tt ).map( f )[ p ], ( ++i, x == 2 ), "i =", i ); ASSERT( i == 7, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).map( g ), ( ++i, x == 9 ), "i =", i ); ASSERT( i == 8, "i =", i ); CLEAR(); }