Skip to content

Commit

Permalink
TODO test for empty string run mode
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jun 27, 2010
1 parent 5c883b8 commit fff40d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/CGI/Application.pm
Expand Up @@ -24,6 +24,7 @@ has %.callbacks = (
# the CGI object or hash
has %.query is rw;


multi method run() {
my $rm = $.__get_runmode($.mode-param);
$.current-runmode = $rm;
Expand Down Expand Up @@ -67,12 +68,15 @@ multi method call-hook($hook, *@args, *%opts) {
}

multi method __get_runmode($rm-param) {
# warn "In __get_runmode\n";
my $rm = do given $rm-param {
when Callable { .(self) }
when Hash { .<run-mode> }
default { $.query{$_} }
when Callable { .(self) }
when Associative { .<run-mode> }
default { %.query{$_} }
}
# warn "Run mode (before): $rm.perl()";
$rm = $.start-mode unless defined($rm) && $rm.chars;
# warn "Run mode (after): $rm.perl()";
return $rm;
}

Expand Down
11 changes: 10 additions & 1 deletion t/basic.t
Expand Up @@ -14,11 +14,13 @@ BEGIN { @*INC.push('t/lib', 'lib') };
use CGI::Application;


sub response-like($app, Mu $header, Mu $body, $comment, :$todo-header) {
sub response-like($app, Mu $header, Mu $body, $comment,
:$todo-header, :$todo-body) {
my $output = $app.run;
my @hb = $output.split(rx{\r?\n\r?\n});
todo($todo-header) if $todo-header;
ok ?(@hb[0] ~~ $header), "$comment (header)" or diag "Got: @hb[0].perl()";
todo($todo-body) if $todo-body;
ok ?(@hb[1] ~~ $body), "$comment (body)" or diag "Got: @hb[1].perl()";
}

Expand Down Expand Up @@ -168,6 +170,13 @@ if 0 {
rx{'Hello World: zero_mode OK'},
'0 as run mode',
);
response-like(
CallbackRunMode.new(query => {go_to_mode => ''}),
rx{^'Content-Type: text/html'},
rx{'Hello World: default_mode OK'},
:todo-body('empty string run mode fallback'),
'empty string as run mode triggers fallback to start_mode',
);


}
Expand Down

0 comments on commit fff40d0

Please sign in to comment.