File: 400-bind-path.t

package info (click to toggle)
libweb-machine-perl 0.17-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: perl: 5,481; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 2,549 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Fatal;

BEGIN {
    use_ok('Web::Machine::Util' => 'bind_path');
}

is_deeply( [ bind_path( '/test/:foo/:bar', '/test/1/2' ) ], [ 1, 2 ], '... got the right bindings' );
is_deeply( [ bind_path( '/test/:foo/:bar', '/test/1/0' ) ], [ 1, 0 ], '... got the right bindings (with false part segement)' );
is( bind_path( '/test/:foo/:bar', '/test/1/2/3' ), undef, '... binding failed, nothing returned' );

is_deeply( [ bind_path( '/test/*', '/test/1/2' ) ], [ 1, 2 ], '... got the right bindings' );
is_deeply( [ bind_path( '/test/*', '/test/1' ) ], [ 1 ], '... got the right bindings' );
is_deeply( [ bind_path( '/test/*', '/test/' ) ], [], '... got the right bindings (which is nothing)' );
isnt( bind_path( '/test/*', '/test/' ), undef, '... got the right bindings (which is nothing) (doublecheck)' );
is_deeply( [ bind_path( '/tree/*', '/tree/_,_,_/_,_,_/' ) ], [ '_,_,_', '_,_,_' ], '... got the right bindings' );

is( scalar bind_path( '/:id', '/201' ), 201, '... got the right bindings (context sensitive)' );
is_deeply( [ bind_path( '/:id', '/201' ) ], [ 201 ], '... got the right bindings' );
is_deeply( [ bind_path( '/?:id', '/201' ) ], [ 201 ], '... got the right bindings' );
is_deeply( [ bind_path( '/?:id', '/' ) ], [], '... got the right bindings (which is nothing)' );
isnt( bind_path( '/?:id', '/' ), undef, '... got the right bindings (which is nothing) (doublecheck)' );
is( scalar bind_path( '/?:id', '/' ), 0, '... got the right bindings (which is nothing) (doublecheck)' );
is( bind_path( '/?:id', '/201/100' ), undef, '... binding failed, nothing returned' );
is( scalar bind_path( '/?:id', '/201/100' ), undef, '... binding failed, nothing returned' );

is( scalar bind_path( '/user/:id/:action', '/user/1/edit' ), 2, '... got the right bindings (context sensitive)' );
is_deeply( [ bind_path( '/user/:id/:action', '/user/1/edit' ) ], [ 1, 'edit' ], '... got the right bindings' );
is( bind_path( '/user/:id/:action', '/foo/bar' ), undef, '... binding failed, nothing returned' );
is( bind_path( '/user/:id/:action', '/user/foo/' ), undef, '... binding failed, nothing returned' );
is_deeply( [ bind_path( '/user/:id/?:action', '/user/foo/' ) ], [ 'foo' ], '... binding succeeded with optional param' );
is_deeply( [ bind_path( '/user/:id/?:action', '/user/foo/bar' ) ], [ 'foo', 'bar' ], '... binding succeeded with optional param' );
is( bind_path( '/user/:id/?:action', '/user/foo/bar/baz' ), undef, '... binding failed, nothing returned' );

done_testing;