Version 0.0.46

1. Refactor private methods names
2. Make methods public
   - split_route_path
   - methods
   - build_route
   - parse_payload
   - setmobj
3. Make methods private 
   - !add
   - !group_index
4. Update tests
parent 0780a9d1
Pipeline #161922622 passed with stage
in 17 minutes and 54 seconds
{
"perl" : "6.d",
"name" : "Router::Right",
"version" : "0.0.45",
"version" : "0.0.46",
"description" : "Framework-agnostic URL routing engine for web applications in Raku",
"depends" : [ "P5quotemeta" ],
"license" : "Artistic-2.0",
......
This diff is collapsed.
......@@ -16,11 +16,11 @@ multi method new(:$parent!, Str :$name!, Str :$path!, :%options!) {
else {
$head = $parent.head;
}
my ( Str $methods, Str $_path ) = $head._split_route_path($path);
my ( Str $methods, Str $_path ) = $head.split_route_path($path);
%options<name> = $name if !%options<name>;
%options<path> = $path if !%options<path>;
%options<methods> = [
$head._methods( (%options<methods> || Str) , $methods)
$head.methods( (%options<methods> || Str) , $methods)
] if $methods || %options<methods>;
my $class = self.bless(
:$parent,
......@@ -43,9 +43,9 @@ method add(
:%payload?,
) returns Router::Right::Submapper {
my ($methods, $_path) = $!head._split_route_path($path);
my ($methods, $_path) = $!head.split_route_path($path);
my @m = [
$!head._methods(
$!head.methods(
(
%!options<methods> ??
%!options<methods>.join(q{,}) !!
......
......@@ -12,74 +12,74 @@ my Bool $raise_except;
subtest {
plan 5;
@a = $r._split_route_path('GET|POST /route');
@a = $r.split_route_path('GET|POST /route');
ok(
( @a[0] eq 'GET|POST' && @a[1] eq '/route' ),
'_split_route_path test no.1',
'split_route_path test no.1',
);
@a = $r._split_route_path('GET /route/subroute/');
@a = $r.split_route_path('GET /route/subroute/');
ok(
( @a[0] eq 'GET' && @a[1] eq '/route/subroute/' ),
'_split_route_path test no.2',
'split_route_path test no.2',
);
@a = $r._split_route_path('GET|PUT|DELETE /route/sub/sub/');
@a = $r.split_route_path('GET|PUT|DELETE /route/sub/sub/');
ok(
( @a[0] eq 'GET|PUT|DELETE' && @a[1] eq '/route/sub/sub/' ),
'_split_route_path test no.3',
'split_route_path test no.3',
);
@a = $r._split_route_path(' POST /a/b/c/d');
@a = $r.split_route_path(' POST /a/b/c/d');
ok(
( @a[0] eq 'POST' && @a[1] eq '/a/b/c/d' ),
'_split_route_path test no.4',
'split_route_path test no.4',
);
@a = $r._split_route_path( "\t\t" ~ ' POST ' ~ "\t" ~ '/a/b/');
@a = $r.split_route_path( "\t\t" ~ ' POST ' ~ "\t" ~ '/a/b/');
ok(
( @a[0] eq 'POST' && @a[1] eq '/a/b/' ),
'_split_route_path test no.5',
'split_route_path test no.5',
);
}, 'check _split_route_path method';
}, 'check split_route_path method';
subtest {
plan 3;
my @a_etalon = ('DELETE', 'GET', 'POST', 'PUT');
@a = $r._methods('GET|POST,pUt', 'GET,post|DelEte');
is-deeply(@a, @a_etalon, 'method _methods test no.1');
@a = $r.methods('GET|POST,pUt', 'GET,post|DelEte');
is-deeply(@a, @a_etalon, 'method methods test no.1');
@a_etalon = ('DELETE', 'GET', 'POST');
@a = $r._methods('', 'GET,post|DelEte');
is-deeply(@a, @a_etalon, 'method _methods test no.2');
@a = $r.methods('', 'GET,post|DelEte');
is-deeply(@a, @a_etalon, 'method methods test no.2');
@a_etalon = ('GET', 'POST', 'PUT');
@a = $r._methods('GET,post|PuT', '');
is-deeply(@a, @a_etalon, 'method _methods test no.3');
}, 'check _methods method';
@a = $r.methods('GET,post|PuT', '');
is-deeply(@a, @a_etalon, 'method methods test no.3');
}, 'check methods method';
subtest {
plan 2;
my @route = $r._build_route( '/entries/{year:\d+}/{month:\d+}' );
my @route = $r.build_route( '/entries/{year:\d+}/{month:\d+}' );
is(
@route[1],
'\/entries\/[$<year>=(\d+)]\/[$<month>=(\d+)]',
'_build_route test no.1',
'build_route test no.1',
);
@route = $r._build_route( '/dl/{file}{.format}' );
@route = $r.build_route( '/dl/{file}{.format}' );
is(
@route[1],
'\/dl\/[$<file>=(<-[/]>+?)][\.$<format>=(<-[.\s/]>+?)]?',
'_build_route test no.2',
'build_route test no.2',
);
}, 'check _build_route method';
}, 'check build_route method';
subtest {
plan 3;
my %h_etalon = controller => 'Controller', action => 'Action';
my %h = $r._parse_payload('Controller#Action');
is-deeply(%h, %h_etalon, 'method _parse_payload test no.1');
my %h = $r.parse_payload('Controller#Action');
is-deeply(%h, %h_etalon, 'method parse_payload test no.1');
%h_etalon = controller => 'Controller';
%h = $r._parse_payload('Controller');
is-deeply(%h, %h_etalon, 'method _parse_payload test no.2');
%h = $r.parse_payload('Controller');
is-deeply(%h, %h_etalon, 'method parse_payload test no.2');
%h_etalon = action => 'Action';
%h = $r._parse_payload('#Action');
is-deeply(%h, %h_etalon, 'method _parse_payload test no.3');
}, 'check _parse_payload method';
%h = $r.parse_payload('#Action');
is-deeply(%h, %h_etalon, 'method parse_payload test no.3');
}, 'check parse_payload method';
subtest {
plan 4;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment