use strict; use warnings; use Test::More; use App::RecordStream::Test::OperationHelper; BEGIN { use_ok( 'App::RecordStream::Operation::xform' ) }; my $input = <do_match( 'xform', ['$r->{a} = "a0";'], $input, $output ); $output = <do_match( 'xform', ['$r->{a} = "a0"; [{}]'], $input, $output ); $output = <do_match( 'xform', ['$r->{a} = "a0"; $r = [{}]'], $input, $output ); $output = <do_match( 'xform', ['-e', '$r = [map { {%$r, "a" => $_} } split(/,/, delete($r->{"a"}))]; 1;'], $input, $output ); $output = <do_match( 'xform', ['-E', 'tests/files/executorCode'], $input, $output ); $output = <do_match( 'xform', ['-MList::Util=reduce', '{{reduced}} = reduce { $a * $b } map { (my $tmp = $_) =~ s/\D//g; $tmp } values %$r'], $input, $output ); $output = <do_match( 'xform', ['-B', 1, '{{before}} = $B->[0]->{"b"}'], $input, $output ); $output = <do_match( 'xform', ['-A', 1, '{{after}} = $A->[0]->{"b"}'], $input, $output ); $input = <do_match( 'xform', ['-C', 1, '{{after}} = $A->[0]->{"a"}; {{before}} = $B->[0]->{"a"}'], $input, $output ); $input = <do_match( 'xform', ['--pre', 'push_output({foo=>"bar"})', '{{a}} .= "c"'], $input, $output ); $output = <do_match( 'xform', ['--post', 'push_output({foo=>"bar"})', '{{a}} .= "c"'], $input, $output ); $output = <do_match( 'xform', ['--post', 'push_input({foo=>"bar"})', '{{a}} .= "c"'], $input, $output ); $output = <do_match( 'xform', ['--pre', '$foo = "zipper"', '{{foo}} .= $foo'], $input, $output ); $output = <do_match( 'xform', ['if(!$later){push_output();$later=1}; {{foo}} = "zipper"'], $input, $output ); $output = <do_match( 'xform', ['--post', 'push_input({foo=>"bar"})', '{{a}} = "c"'], '', $output ); $output = <do_match( 'xform', ['--pre', 'push_input({foo=>"bar"})', '{{a}} = "c"'], '', $output ); # Test for GH #70: # $ recs xform '42' <<<'{"foo":13}' # {"foo":13} # $ recs xform '42 #' <<<'{"foo":13}' # 42 $input = '{"foo":13}'; $output = $input; App::RecordStream::Test::OperationHelper->do_match( 'xform', ['42 #'], $input, $output, ); done_testing;