|
#!perl -T
my $args = [
[[0],[1]],
[\ "a" ,\ "b" ],
];
ok(
str2path( '[0](BACK)' )->[1]->( $args ->[0], $args ->[1]),
"Step back must return 1"
);
is_deeply(
$args ,
[[[0]], [\ "a" ]],
"One step back"
);
$args = [
[[0],[1]],
[\ "a" ,\ "b" ],
];
my $spath = str2path( '[0](back 2)' );
ok(
$spath ->[1]->( $args ->[0], $args ->[1]),
"Step back must return 1"
);
is_deeply(
$args ,
[[], []],
"Two steps back"
);
$args = [
[[0],[1]],
[\ "a" ,\ "b" ],
];
$spath ->[1]->( $args ->[0], $args ->[1]);
is_deeply(
$args ,
[[], []],
"Step back hook must be reusable"
);
$args = [
[[0],[1]],
[\ "a" ,\ "b" ],
];
is(
str2path( '[0](BACK 3)' )->[1]->( $args ->[0], $args ->[1]),
undef ,
"BACK() should return undef when unable to step back"
);
is(
str2path( '[0](BACK "text")' )->[1]->( $args ->[0], $args ->[1]),
undef ,
"BACK() should return undef when not an int passed"
);
is(
str2path( '[0](BACK 0)' )->[1]->( $args ->[0], $args ->[1]),
1,
"BACK() should do nothing when zero passed for step amount"
);
|