#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 std::make_unique< int >( x ); } ); DECLARE( auto tt = []( path, const auto & ) { return true; } ); DECLARE( auto id = []( path, auto i ) { return i; } ); 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 ).map( g ), at( i++ ) == *j, "i =", i ); ASSERT( i == 4, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).map( g ), ( ++i, *x == 2 ), "i =", i ); ASSERT( i == 5, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).filter( tt ).map( g ), ( ++i, *x == 2 ), "i =", i ); ASSERT( i == 6, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q.filter( tt ).map( f )[ p ].map( g ), ( ++i, *x == 2 ), "i =", i ); ASSERT( i == 7, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).map( g ).filter( tt ), ( ++i, *x == 2 ), "i =", i ); ASSERT( i == 8, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q[ p ].map( f ).map( g ).map( id ), ( ++i, *x == 2 ), "i =", i ); ASSERT( i == 9, "i =", i ); CLEAR(); ASSERT_FOR( ( p, x ), q.map( f ).map( g )[ p ], ( ++i, *x == 2 ), "i =", i ); ASSERT( i == 10, "i =", i ); CLEAR(); }