diff --git a/t/mojo/asset.t b/t/mojo/asset.t index 6c0882e4ac..fcd8992216 100644 --- a/t/mojo/asset.t +++ b/t/mojo/asset.t @@ -9,16 +9,16 @@ use Mojo::File qw(path tempdir); subtest 'File asset' => sub { my $file = Mojo::Asset::File->new; - is $file->size, 0, 'file is empty'; + is $file->size, 0, 'file is empty'; is $file->mtime, (stat $file->handle)[9], 'right mtime'; - is $file->slurp, '', 'file is empty'; + is $file->slurp, '', 'file is empty'; $file->add_chunk('abc'); is $file->contains('abc'), 0, '"abc" at position 0'; is $file->contains('bc'), 1, '"bc" at position 1'; is $file->contains('db'), -1, 'does not contain "db"'; - is $file->size, 3, 'right size'; + is $file->size, 3, 'right size'; is $file->mtime, (stat $file->handle)[9], 'right mtime'; - is $file->to_file, $file, 'same object'; + is $file->to_file, $file, 'same object'; my $path = $file->path; ok -e $path, 'temporary file exists'; @@ -29,12 +29,12 @@ subtest 'File asset' => sub { subtest 'Memory asset' => sub { my $mem = Mojo::Asset::Memory->new; $mem->add_chunk('abc'); - is $mem->contains('abc'), 0, '"abc" at position 0'; - is $mem->contains('bc'), 1, '"bc" at position 1'; - is $mem->contains('db'), -1, 'does not contain "db"'; - is $mem->size, 3, 'right size'; - is $mem->mtime, $^T, 'right mtime'; - is $mem->mtime, Mojo::Asset::Memory->new->mtime, 'same mtime'; + is $mem->contains('abc'), 0, '"abc" at position 0'; + is $mem->contains('bc'), 1, '"bc" at position 1'; + is $mem->contains('db'), -1, 'does not contain "db"'; + is $mem->size, 3, 'right size'; + is $mem->mtime, $^T, 'right mtime'; + is $mem->mtime, Mojo::Asset::Memory->new->mtime, 'same mtime'; my $mtime = $mem->mtime; is $mem->mtime($mtime + 23)->mtime, $mtime + 23, 'right mtime'; }; @@ -53,17 +53,17 @@ subtest 'Asset upgrade from memory to file' => sub { subtest 'Empty file asset' => sub { my $file = Mojo::Asset::File->new; - is $file->size, 0, 'asset is empty'; - is $file->get_chunk(0), '', 'no content'; - is $file->slurp, '', 'no content'; + is $file->size, 0, 'asset is empty'; + is $file->get_chunk(0), '', 'no content'; + is $file->slurp, '', 'no content'; is $file->contains('a'), -1, 'does not contain "a"'; }; subtest 'Empty memory asset' => sub { my $mem = Mojo::Asset::Memory->new; - is $mem->size, 0, 'asset is empty'; + is $mem->size, 0, 'asset is empty'; is $mem->get_chunk(0), '', 'no content'; - is $mem->slurp, '', 'no content'; + is $mem->slurp, '', 'no content'; ok !$mem->is_range, 'no range'; is $mem->contains('a'), -1, 'does not contain "a"'; }; @@ -100,10 +100,10 @@ subtest 'File asset range support (ab[cdefghi]jk)' => sub { is $file->get_chunk(0), 'cdefghi', 'chunk from position 0'; is $file->get_chunk(1), 'defghi', 'chunk from position 1'; is $file->get_chunk(5), 'hi', 'chunk from position 5'; - is $file->get_chunk(0, 2), 'cd', 'chunk from position 0 (2 bytes)'; - is $file->get_chunk(1, 3), 'def', 'chunk from position 1 (3 bytes)'; - is $file->get_chunk(5, 1), 'h', 'chunk from position 5 (1 byte)'; - is $file->get_chunk(5, 3), 'hi', 'chunk from position 5 (2 byte)'; + is $file->get_chunk(0, 2), 'cd', 'chunk from position 0 (2 bytes)'; + is $file->get_chunk(1, 3), 'def', 'chunk from position 1 (3 bytes)'; + is $file->get_chunk(5, 1), 'h', 'chunk from position 5 (1 byte)'; + is $file->get_chunk(5, 3), 'hi', 'chunk from position 5 (2 byte)'; }; subtest 'Memory asset range support (ab[cdefghi]jk)' => sub { @@ -119,10 +119,10 @@ subtest 'Memory asset range support (ab[cdefghi]jk)' => sub { is $mem->get_chunk(0), 'cdefghi', 'chunk from position 0'; is $mem->get_chunk(1), 'defghi', 'chunk from position 1'; is $mem->get_chunk(5), 'hi', 'chunk from position 5'; - is $mem->get_chunk(0, 2), 'cd', 'chunk from position 0 (2 bytes)'; - is $mem->get_chunk(1, 3), 'def', 'chunk from position 1 (3 bytes)'; - is $mem->get_chunk(5, 1), 'h', 'chunk from position 5 (1 byte)'; - is $mem->get_chunk(5, 3), 'hi', 'chunk from position 5 (2 byte)'; + is $mem->get_chunk(0, 2), 'cd', 'chunk from position 0 (2 bytes)'; + is $mem->get_chunk(1, 3), 'def', 'chunk from position 1 (3 bytes)'; + is $mem->get_chunk(5, 1), 'h', 'chunk from position 5 (1 byte)'; + is $mem->get_chunk(5, 3), 'hi', 'chunk from position 5 (2 byte)'; }; subtest 'Huge file asset' => sub { @@ -132,16 +132,16 @@ subtest 'Huge file asset' => sub { $file->add_chunk('b'); $file->add_chunk('c' x 131072); $file->add_chunk('ddd'); - is $file->contains('a'), 0, '"a" at position 0'; - is $file->contains('b'), 131072, '"b" at position 131072'; - is $file->contains('c'), 131073, '"c" at position 131073'; - is $file->contains('abc'), 131071, '"abc" at position 131071'; - is $file->contains('ccdd'), 262143, '"ccdd" at position 262143'; - is $file->contains('dd'), 262145, '"dd" at position 262145'; - is $file->contains('ddd'), 262145, '"ddd" at position 262145'; - is $file->contains('e'), -1, 'does not contain "e"'; - is $file->contains('a' x 131072), 0, '"a" x 131072 at position 0'; - is $file->contains('c' x 131072), 131073, '"c" x 131072 at position 131073'; + is $file->contains('a'), 0, '"a" at position 0'; + is $file->contains('b'), 131072, '"b" at position 131072'; + is $file->contains('c'), 131073, '"c" at position 131073'; + is $file->contains('abc'), 131071, '"abc" at position 131071'; + is $file->contains('ccdd'), 262143, '"ccdd" at position 262143'; + is $file->contains('dd'), 262145, '"dd" at position 262145'; + is $file->contains('ddd'), 262145, '"ddd" at position 262145'; + is $file->contains('e'), -1, 'does not contain "e"'; + is $file->contains('a' x 131072), 0, '"a" x 131072 at position 0'; + is $file->contains('c' x 131072), 131073, '"c" x 131072 at position 131073'; is $file->contains('b' . ('c' x 131072) . "ddd"), 131072, '"b" . ("c" x 131072) . "ddd" at position 131072'; }; @@ -151,14 +151,14 @@ subtest 'Huge file asset with range' => sub { $file->add_chunk('b'); $file->add_chunk('c' x 131072); $file->add_chunk('ddd'); - is $file->contains('a'), 0, '"a" at position 0'; - is $file->contains('b'), 131071, '"b" at position 131071'; - is $file->contains('c'), 131072, '"c" at position 131072'; - is $file->contains('abc'), 131070, '"abc" at position 131070'; - is $file->contains('ccdd'), 262142, '"ccdd" at position 262142'; - is $file->contains('dd'), 262144, '"dd" at position 262144'; - is $file->contains('ddd'), -1, 'does not contain "ddd"'; - is $file->contains('b' . ('c' x 131072) . 'ddd'), -1, 'does not contain "b" . ("c" x 131072) . "ddd"'; + is $file->contains('a'), 0, '"a" at position 0'; + is $file->contains('b'), 131071, '"b" at position 131071'; + is $file->contains('c'), 131072, '"c" at position 131072'; + is $file->contains('abc'), 131070, '"abc" at position 131070'; + is $file->contains('ccdd'), 262142, '"ccdd" at position 262142'; + is $file->contains('dd'), 262144, '"dd" at position 262144'; + is $file->contains('ddd'), -1, 'does not contain "ddd"'; + is $file->contains('b' . ('c' x 131072) . 'ddd'), -1, 'does not contain "b" . ("c" x 131072) . "ddd"'; }; subtest 'Move memory asset to file' => sub { @@ -169,13 +169,13 @@ subtest 'Move memory asset to file' => sub { undef $tmp; ok !-e $path, 'file has been cleaned up'; is $mem->move_to($path)->slurp, 'abc', 'right content'; - ok -e $path, 'file exists'; + ok -e $path, 'file exists'; ok unlink($path), 'unlinked file'; - ok !-e $path, 'file has been cleaned up'; + ok !-e $path, 'file has been cleaned up'; is(Mojo::Asset::Memory->new->move_to($path)->slurp, '', 'no content'); - ok -e $path, 'file exists'; + ok -e $path, 'file exists'; ok unlink($path), 'unlinked file'; - ok !-e $path, 'file has been cleaned up'; + ok !-e $path, 'file has been cleaned up'; }; subtest 'Move file asset to file' => sub { @@ -190,13 +190,13 @@ subtest 'Move file asset to file' => sub { ok !-e $path, 'file has been cleaned up'; is $file->move_to($path)->slurp, 'bcd', 'right content'; undef $file; - ok -e $path, 'file exists'; + ok -e $path, 'file exists'; ok unlink($path), 'unlinked file'; - ok !-e $path, 'file has been cleaned up'; + ok !-e $path, 'file has been cleaned up'; is(Mojo::Asset::File->new->move_to($path)->slurp, '', 'no content'); - ok -e $path, 'file exists'; + ok -e $path, 'file exists'; ok unlink($path), 'unlinked file'; - ok !-e $path, 'file has been cleaned up'; + ok !-e $path, 'file has been cleaned up'; }; subtest 'Upgrade' => sub { @@ -204,7 +204,7 @@ subtest 'Upgrade' => sub { my $upgrade; $asset->on(upgrade => sub { $upgrade++ }); $asset = $asset->add_chunk('lala'); - ok !$upgrade, 'upgrade event has not been emitted'; + ok !$upgrade, 'upgrade event has not been emitted'; ok !$asset->is_file, 'stored in memory'; $asset = $asset->add_chunk('lala'); is $upgrade, 1, 'upgrade event has been emitted once'; @@ -212,7 +212,7 @@ subtest 'Upgrade' => sub { $asset = $asset->add_chunk('lala'); is $upgrade, 1, 'upgrade event was not emitted again'; ok $asset->is_file, 'stored in file'; - is $asset->slurp, 'lalalalalala', 'right content'; + is $asset->slurp, 'lalalalalala', 'right content'; ok $asset->cleanup, 'file will be cleaned up'; $asset = Mojo::Asset::Memory->new(max_memory_size => 5); $asset = $asset->add_chunk('lala'); @@ -232,8 +232,8 @@ subtest 'Change temporary directory during upgrade' => sub { ); my $file = $mem->add_chunk('aaaaaaaaaaa'); ok $file->is_file, 'stored in file'; - is $file->slurp, 'aaaaaaaaaaa', 'right content'; - is path($file->path)->dirname, $tmpdir, 'right directory'; + is $file->slurp, 'aaaaaaaaaaa', 'right content'; + is path($file->path)->dirname, $tmpdir, 'right directory'; }; subtest 'Temporary directory' => sub { @@ -241,8 +241,8 @@ subtest 'Temporary directory' => sub { my $file = Mojo::Asset::File->new; is($file->tmpdir, $tmpdir, 'same directory'); $file->add_chunk('works!'); - is $file->slurp, 'works!', 'right content'; - is path($file->path)->dirname, $tmpdir, 'same directory'; + is $file->slurp, 'works!', 'right content'; + is path($file->path)->dirname, $tmpdir, 'same directory'; }; subtest 'Custom temporary file' => sub { @@ -262,15 +262,15 @@ subtest 'Custom temporary file' => sub { subtest 'Temporary file without cleanup' => sub { my $file = Mojo::Asset::File->new(cleanup => 0)->add_chunk('test'); ok $file->is_file, 'stored in file'; - is $file->slurp, 'test', 'right content'; - is $file->size, 4, 'right size'; + is $file->slurp, 'test', 'right content'; + is $file->size, 4, 'right size'; is $file->mtime, (stat $file->handle)[9], 'right mtime'; - is $file->contains('es'), 1, '"es" at position 1'; + is $file->contains('es'), 1, '"es" at position 1'; my $path = $file->path; undef $file; - ok -e $path, 'file exists'; + ok -e $path, 'file exists'; ok unlink($path), 'unlinked file'; - ok !-e $path, 'file has been cleaned up'; + ok !-e $path, 'file has been cleaned up'; }; subtest 'Incomplete write' => sub { diff --git a/t/mojo/base.t b/t/mojo/base.t index a580b576c3..106c8526d8 100644 --- a/t/mojo/base.t +++ b/t/mojo/base.t @@ -74,7 +74,7 @@ subtest 'Instance method' => sub { subtest 'Default value defined but false' => sub { my $object = Mojo::BaseTestTestTest->new; ok defined($object->yada); - is $object->yada, 0, 'right attribute value'; + is $object->yada, 0, 'right attribute value'; is $object->yada(5)->yada, 5, 'right attribute value'; }; @@ -88,27 +88,27 @@ subtest 'Default value support' => sub { subtest 'Chained attributes and callback default value support' => sub { my $object = Mojo::BaseTest->new; - is $object->bar, 2, 'right attribute value'; + is $object->bar, 2, 'right attribute value'; is $object->bar(6)->bar, 6, 'right chained attribute value'; - is $object->baz, 2, 'right attribute value'; + is $object->baz, 2, 'right attribute value'; is $object->baz(6)->baz, 6, 'right chained attribute value'; }; subtest 'Tap into chain' => sub { my $object = Mojo::BaseTest->new; - is $object->tap(sub { $_->name('foo') })->name, 'foo', 'right attribute value'; + is $object->tap(sub { $_->name('foo') })->name, 'foo', 'right attribute value'; is $object->tap(sub { shift->name('bar')->name })->name, 'bar', 'right attribute value'; - is $object->tap('tests')->tests, 1, 'right attribute value'; - is $object->more_tests, 2, 'right attribute value'; - is $object->tap('more_tests')->tests, 3, 'right attribute value'; - is $object->tap(more_tests => 3)->tests, 6, 'right attribute value'; + is $object->tap('tests')->tests, 1, 'right attribute value'; + is $object->more_tests, 2, 'right attribute value'; + is $object->tap('more_tests')->tests, 3, 'right attribute value'; + is $object->tap(more_tests => 3)->tests, 6, 'right attribute value'; }; subtest 'Inherit -base flag' => sub { my $object = Mojo::BaseTest::Base3->new(test => 1); - is $object->test, 1, 'right attribute value'; - is $object->foo, undef, 'no attribute value'; - is $object->foo(3)->foo, 3, 'right attribute value'; + is $object->test, 1, 'right attribute value'; + is $object->foo, undef, 'no attribute value'; + is $object->foo(3)->foo, 3, 'right attribute value'; }; subtest 'Exceptions' => sub { @@ -138,7 +138,7 @@ subtest 'Weaken' => sub { ok isweak($weak->six($weak)->{six}), 'weakened value'; is $weak->six, $weak, 'circular reference'; $weak = Mojo::BaseTest::Weak3->new(one => 23); - is $weak->one, 23, 'right value'; + is $weak->one, 23, 'right value'; is $weak->one(24)->one, 24, 'right value'; is $weak->four(25)->four, 25, 'right value'; }; diff --git a/t/mojo/bytestream.t b/t/mojo/bytestream.t index 52ffe6372a..c377adc009 100644 --- a/t/mojo/bytestream.t +++ b/t/mojo/bytestream.t @@ -111,16 +111,16 @@ subtest 'Nested bytestreams' => sub { subtest 'split' => sub { my $stream = b('1,2,3,4,5'); - is_deeply $stream->split(',')->to_array, [1, 2, 3, 4, 5], 'right elements'; - is_deeply $stream->split(qr/,/)->to_array, [1, 2, 3, 4, 5], 'right elements'; - is_deeply b('1,2,3,4,5,,,')->split(',')->to_array, [1, 2, 3, 4, 5], 'right elements'; + is_deeply $stream->split(',')->to_array, [1, 2, 3, 4, 5], 'right elements'; + is_deeply $stream->split(qr/,/)->to_array, [1, 2, 3, 4, 5], 'right elements'; + is_deeply b('1,2,3,4,5,,,')->split(',')->to_array, [1, 2, 3, 4, 5], 'right elements'; is_deeply b('1,2,3,4,5,,,')->split(',', -1)->to_array, [1, 2, 3, 4, 5, '', '', ''], 'right elements'; - is_deeply b('54321')->split('')->to_array, [5, 4, 3, 2, 1], 'right elements'; - is_deeply b('')->split('')->to_array, [], 'no elements'; - is_deeply b('')->split(',')->to_array, [], 'no elements'; - is_deeply b('')->split(qr/,/)->to_array, [], 'no elements'; + is_deeply b('54321')->split('')->to_array, [5, 4, 3, 2, 1], 'right elements'; + is_deeply b('')->split('')->to_array, [], 'no elements'; + is_deeply b('')->split(',')->to_array, [], 'no elements'; + is_deeply b('')->split(qr/,/)->to_array, [], 'no elements'; $stream = b('1/2/3'); - is $stream->split('/')->map(sub { $_->quote })->join(', '), '"1", "2", "3"', 'right result'; + is $stream->split('/')->map(sub { $_->quote })->join(', '), '"1", "2", "3"', 'right result'; is $stream->split('/')->map(sub { shift->quote })->join(', '), '"1", "2", "3"', 'right result'; }; @@ -138,7 +138,7 @@ subtest 'clone' => sub { my $stream = b('foo'); my $clone = $stream->clone; isnt $stream->b64_encode->to_string, 'foo', 'original changed'; - is $clone->to_string, 'foo', 'clone did not change'; + is $clone->to_string, 'foo', 'clone did not change'; }; subtest 'say and autojoin' => sub { diff --git a/t/mojo/cache.t b/t/mojo/cache.t index fe78f03fce..dfee911319 100644 --- a/t/mojo/cache.t +++ b/t/mojo/cache.t @@ -27,7 +27,7 @@ subtest 'Basics' => sub { subtest 'Bigger cache' => sub { my $cache = Mojo::Cache->new(max_keys => 3); - is $cache->get('foo'), undef, 'no result'; + is $cache->get('foo'), undef, 'no result'; is $cache->set(foo => 'bar')->get('foo'), 'bar', 'right result'; $cache->set(bar => 'baz'); is $cache->get('foo'), 'bar', 'right result'; @@ -45,7 +45,7 @@ subtest 'Bigger cache' => sub { subtest 'Cache disabled' => sub { my $cache = Mojo::Cache->new(max_keys => 0); - is $cache->get('foo'), undef, 'no result'; + is $cache->get('foo'), undef, 'no result'; is $cache->set(foo => 'bar')->get('foo'), undef, 'no result'; $cache = Mojo::Cache->new(max_keys => -1); diff --git a/t/mojo/cgi.t b/t/mojo/cgi.t index a4296edd83..517106db8a 100644 --- a/t/mojo/cgi.t +++ b/t/mojo/cgi.t @@ -58,11 +58,11 @@ subtest 'Simple' => sub { is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_length, 21, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, 'Your Mojo is working!', 'right content'; + is $res->body, 'Your Mojo is working!', 'right content'; }; subtest 'HEAD request' => sub { @@ -79,11 +79,11 @@ subtest 'HEAD request' => sub { is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_length, 21, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, '', 'no content'; + is $res->body, '', 'no content'; }; subtest 'Non-parsed headers' => sub { @@ -100,11 +100,11 @@ subtest 'Non-parsed headers' => sub { is(Mojolicious::Command::cgi->new(app => app)->run('--nph'), 200, 'right status'); my $res = Mojo::Message::Response->new->parse($msg); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, undef, 'no "Status" value'; is $res->headers->content_length, 21, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, 'Your Mojo is working!', 'right content'; + is $res->body, 'Your Mojo is working!', 'right content'; }; subtest 'Chunked' => sub { @@ -127,9 +127,9 @@ subtest 'Chunked' => sub { like $msg, qr/chunked/, 'is chunked'; my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; - is $res->headers->status, '200 OK', 'right "Status" value'; - is $res->body, '1234567', 'right content'; + is $res->code, 200, 'right status'; + is $res->headers->status, '200 OK', 'right "Status" value'; + is $res->body, '1234567', 'right content'; }; subtest 'Parameters' => sub { @@ -147,12 +147,12 @@ subtest 'Parameters' => sub { is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_type, 'application/json;charset=UTF-8', 'right "Content-Type" value'; is $res->headers->content_length, 27, 'right "Content-Length" value'; - is $res->json->{lalala}, 23, 'right value'; - is $res->json->{bar}, 'baz', 'right value'; + is $res->json->{lalala}, 23, 'right value'; + is $res->json->{bar}, 'baz', 'right value'; }; subtest 'Binding' => sub { @@ -176,11 +176,11 @@ subtest 'Binding' => sub { ); is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_length, 21, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, 'Your Mojo is working!', 'right content'; + is $res->body, 'Your Mojo is working!', 'right content'; is_deeply \@server, ['Mojo::Server::CGI', 'development'], 'hook has been emitted once'; }; @@ -201,11 +201,11 @@ subtest 'Reverse proxy' => sub { is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_length, 15, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, '192.0.2.1:https', 'right content'; + is $res->body, '192.0.2.1:https', 'right content'; }; subtest 'Trusted proxies' => sub { @@ -226,11 +226,11 @@ subtest 'Trusted proxies' => sub { is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_length, 17, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, '10.10.10.10:https', 'right content'; + is $res->body, '10.10.10.10:https', 'right content'; }; subtest 'Trusted proxies (no REMOTE_ADDR)' => sub { @@ -250,11 +250,11 @@ subtest 'Trusted proxies (no REMOTE_ADDR)' => sub { is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status'); my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg"); - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; is $res->headers->status, '200 OK', 'right "Status" value'; is $res->headers->content_length, 5, 'right "Content-Length" value'; is $res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; - is $res->body, 'https', 'right content'; + is $res->body, 'https', 'right content'; }; done_testing(); diff --git a/t/mojo/collection.t b/t/mojo/collection.t index 76d3f81292..95d6eb6697 100644 --- a/t/mojo/collection.t +++ b/t/mojo/collection.t @@ -19,8 +19,8 @@ subtest 'Tap into method chain' => sub { subtest 'compact' => sub { is_deeply c(undef, 0, 1, '', 2, 3)->compact->to_array, [0, 1, 2, 3], 'right result'; - is_deeply c(3, 2, 1)->compact->to_array, [3, 2, 1], 'right result'; - is_deeply c()->compact->to_array, [], 'right result'; + is_deeply c(3, 2, 1)->compact->to_array, [3, 2, 1], 'right result'; + is_deeply c()->compact->to_array, [], 'right result'; }; subtest 'flatten' => sub { @@ -45,41 +45,41 @@ subtest 'first' => sub { my $collection = c(5, 4, [3, 2], 1); is $collection->first, 5, 'right result'; is_deeply $collection->first(sub { ref $_ eq 'ARRAY' }), [3, 2], 'right result'; - is $collection->first(sub { shift() < 5 }), 4, 'right result'; - is $collection->first(qr/[1-4]/), 4, 'right result'; + is $collection->first(sub { shift() < 5 }), 4, 'right result'; + is $collection->first(qr/[1-4]/), 4, 'right result'; is $collection->first(sub { ref $_ eq 'CODE' }), undef, 'no result'; $collection = c(c(1, 2, 3), c(4, 5, 6), c(7, 8, 9)); is_deeply $collection->first(first => sub { $_ == 5 })->to_array, [4, 5, 6], 'right result'; $collection = c(); - is $collection->first, undef, 'no result'; + is $collection->first, undef, 'no result'; is $collection->first(sub {defined}), undef, 'no result'; }; subtest 'last' => sub { - is c(5, 4, 3)->last, 3, 'right result'; + is c(5, 4, 3)->last, 3, 'right result'; is c(5, 4, 3)->reverse->last, 5, 'right result'; is c()->last, undef, 'no result'; }; subtest 'grep' => sub { my $collection = c(1, 2, 3, 4, 5, 6, 7, 8, 9); - is_deeply $collection->grep(qr/[6-9]/)->to_array, [6, 7, 8, 9], 'right elements'; - is_deeply $collection->grep(sub {/[6-9]/})->to_array, [6, 7, 8, 9], 'right elements'; - is_deeply $collection->grep(sub { $_ > 5 })->to_array, [6, 7, 8, 9], 'right elements'; - is_deeply $collection->grep(sub { $_ < 5 })->to_array, [1, 2, 3, 4], 'right elements'; - is_deeply $collection->grep(sub { shift == 5 })->to_array, [5], 'right elements'; - is_deeply $collection->grep(sub { $_ < 1 })->to_array, [], 'no elements'; - is_deeply $collection->grep(sub { $_ > 9 })->to_array, [], 'no elements'; + is_deeply $collection->grep(qr/[6-9]/)->to_array, [6, 7, 8, 9], 'right elements'; + is_deeply $collection->grep(sub {/[6-9]/})->to_array, [6, 7, 8, 9], 'right elements'; + is_deeply $collection->grep(sub { $_ > 5 })->to_array, [6, 7, 8, 9], 'right elements'; + is_deeply $collection->grep(sub { $_ < 5 })->to_array, [1, 2, 3, 4], 'right elements'; + is_deeply $collection->grep(sub { shift == 5 })->to_array, [5], 'right elements'; + is_deeply $collection->grep(sub { $_ < 1 })->to_array, [], 'no elements'; + is_deeply $collection->grep(sub { $_ > 9 })->to_array, [], 'no elements'; $collection = c(c(1, 2, 3), c(4, 5, 6), c(7, 8, 9)); is_deeply $collection->grep(first => sub { $_ >= 5 })->flatten->to_array, [4, 5, 6, 7, 8, 9], 'right result'; }; subtest 'join' => sub { my $collection = c(1, 2, 3); - is $collection->join, '123', 'right result'; - is $collection->join(''), '123', 'right result'; - is $collection->join('---'), '1---2---3', 'right result'; - is $collection->join("\n"), "1\n2\n3", 'right result'; + is $collection->join, '123', 'right result'; + is $collection->join(''), '123', 'right result'; + is $collection->join('---'), '1---2---3', 'right result'; + is $collection->join("\n"), "1\n2\n3", 'right result'; is $collection->join('/')->url_escape, '1%2F2%2F3', 'right result'; }; @@ -91,7 +91,7 @@ subtest 'map' => sub { is_deeply [@$collection], [1, 2, 3], 'right elements'; $collection = c(c(1, 2, 3), c(4, 5, 6), c(7, 8, 9)); is $collection->map('reverse')->map(join => "\n")->join("\n"), "3\n2\n1\n6\n5\n4\n9\n8\n7", 'right result'; - is $collection->map(join => '-')->join("\n"), "1-2-3\n4-5-6\n7-8-9", 'right result'; + is $collection->map(join => '-')->join("\n"), "1-2-3\n4-5-6\n7-8-9", 'right result'; }; subtest 'reverse' => sub { @@ -107,7 +107,7 @@ subtest 'shuffle' => sub { my $collection = c(0 .. 10000); my $random = $collection->shuffle; is $collection->size, $random->size, 'same number of elements'; - isnt "@$collection", "@$random", 'different order'; + isnt "@$collection", "@$random", 'different order'; is_deeply c()->shuffle->to_array, [], 'no elements'; }; @@ -126,26 +126,26 @@ subtest 'size' => sub { subtest 'reduce' => sub { my $collection = c(2, 5, 4, 1); - is $collection->reduce(sub { $a + $b }), 12, 'right result'; - is $collection->reduce(sub { $a + $b }, 5), 17, 'right result'; - is c()->reduce(sub { $a + $b }), undef, 'no result'; + is $collection->reduce(sub { $a + $b }), 12, 'right result'; + is $collection->reduce(sub { $a + $b }, 5), 17, 'right result'; + is c()->reduce(sub { $a + $b }), undef, 'no result'; }; subtest 'sort' => sub { my $collection = c(2, 5, 4, 1); - is_deeply $collection->sort->to_array, [1, 2, 4, 5], 'right order'; - is_deeply $collection->sort(sub { $b cmp $a })->to_array, [5, 4, 2, 1], 'right order'; + is_deeply $collection->sort->to_array, [1, 2, 4, 5], 'right order'; + is_deeply $collection->sort(sub { $b cmp $a })->to_array, [5, 4, 2, 1], 'right order'; is_deeply $collection->sort(sub { $_[1] cmp $_[0] })->to_array, [5, 4, 2, 1], 'right order'; $collection = c(qw(Test perl Mojo)); is_deeply $collection->sort(sub { uc(shift) cmp uc(shift) })->to_array, [qw(Mojo perl Test)], 'right order'; $collection = c(); - is_deeply $collection->sort->to_array, [], 'no elements'; + is_deeply $collection->sort->to_array, [], 'no elements'; is_deeply $collection->sort(sub { $a cmp $b })->to_array, [], 'no elements'; }; subtest 'uniq' => sub { my $collection = c(1, 2, 3, 2, 3, 4, 5, 4); - is_deeply $collection->uniq->to_array, [1, 2, 3, 4, 5], 'right result'; + is_deeply $collection->uniq->to_array, [1, 2, 3, 4, 5], 'right result'; is_deeply $collection->uniq->reverse->uniq->to_array, [5, 4, 3, 2, 1], 'right result'; $collection = c([1, 2, 3], [3, 2, 1], [3, 1, 2]); is_deeply $collection->uniq(sub { $_->[1] }), [[1, 2, 3], [3, 1, 2]], 'right result'; @@ -163,28 +163,28 @@ subtest 'TO_JSON' => sub { subtest 'head' => sub { my $collection = c(1, 2, 5, 4, 3); - is_deeply $collection->head(0)->to_array, [], 'right result'; - is_deeply $collection->head(1)->to_array, [1], 'right result'; - is_deeply $collection->head(2)->to_array, [1, 2], 'right result'; - is_deeply $collection->head(-1)->to_array, [1, 2, 5, 4], 'right result'; - is_deeply $collection->head(-3)->to_array, [1, 2], 'right result'; + is_deeply $collection->head(0)->to_array, [], 'right result'; + is_deeply $collection->head(1)->to_array, [1], 'right result'; + is_deeply $collection->head(2)->to_array, [1, 2], 'right result'; + is_deeply $collection->head(-1)->to_array, [1, 2, 5, 4], 'right result'; + is_deeply $collection->head(-3)->to_array, [1, 2], 'right result'; is_deeply $collection->head(5)->to_array, [1, 2, 5, 4, 3], 'right result'; is_deeply $collection->head(6)->to_array, [1, 2, 5, 4, 3], 'right result'; - is_deeply $collection->head(-5)->to_array, [], 'right result'; - is_deeply $collection->head(-6)->to_array, [], 'right result'; + is_deeply $collection->head(-5)->to_array, [], 'right result'; + is_deeply $collection->head(-6)->to_array, [], 'right result'; }; subtest 'tail' => sub { my $collection = c(1, 2, 5, 4, 3); - is_deeply $collection->tail(0)->to_array, [], 'right result'; - is_deeply $collection->tail(1)->to_array, [3], 'right result'; - is_deeply $collection->tail(2)->to_array, [4, 3], 'right result'; - is_deeply $collection->tail(-1)->to_array, [2, 5, 4, 3], 'right result'; - is_deeply $collection->tail(-3)->to_array, [4, 3], 'right result'; + is_deeply $collection->tail(0)->to_array, [], 'right result'; + is_deeply $collection->tail(1)->to_array, [3], 'right result'; + is_deeply $collection->tail(2)->to_array, [4, 3], 'right result'; + is_deeply $collection->tail(-1)->to_array, [2, 5, 4, 3], 'right result'; + is_deeply $collection->tail(-3)->to_array, [4, 3], 'right result'; is_deeply $collection->tail(5)->to_array, [1, 2, 5, 4, 3], 'right result'; is_deeply $collection->tail(6)->to_array, [1, 2, 5, 4, 3], 'right result'; - is_deeply $collection->tail(-5)->to_array, [], 'right result'; - is_deeply $collection->tail(-6)->to_array, [], 'right result'; + is_deeply $collection->tail(-5)->to_array, [], 'right result'; + is_deeply $collection->tail(-6)->to_array, [], 'right result'; }; done_testing(); diff --git a/t/mojo/content.t b/t/mojo/content.t index f7482c7e20..83c499c878 100644 --- a/t/mojo/content.t +++ b/t/mojo/content.t @@ -8,22 +8,22 @@ use Mojo::Content::Single; subtest 'Single' => sub { my $content = Mojo::Content::Single->new; $content->asset->add_chunk('foo'); - ok !$content->body_contains('a'), 'content does not contain "a"'; + ok !$content->body_contains('a'), 'content does not contain "a"'; ok $content->body_contains('f'), 'content contains "f"'; ok $content->body_contains('o'), 'content contains "o"'; ok $content->body_contains('foo'), 'content contains "foo"'; $content = Mojo::Content::Single->new(asset => Mojo::Asset::Memory->new->add_chunk('bar')); ok !$content->body_contains('foo'), 'content does not contain "foo"'; - ok $content->body_contains('bar'), 'content contains "bar"'; + ok $content->body_contains('bar'), 'content contains "bar"'; $content = Mojo::Content::Single->new({asset => Mojo::Asset::Memory->new->add_chunk('foo')}); ok !$content->body_contains('bar'), 'content does not contain "bar"'; - ok $content->body_contains('foo'), 'content contains "foo"'; + ok $content->body_contains('foo'), 'content contains "foo"'; }; subtest 'Multipart' => sub { my $content = Mojo::Content::MultiPart->new( parts => [Mojo::Content::Single->new({asset => Mojo::Asset::Memory->new->add_chunk('foo')})]); - ok !$content->body_contains('a'), 'content does not contain "a"'; + ok !$content->body_contains('a'), 'content does not contain "a"'; ok $content->body_contains('f'), 'content contains "f"'; ok $content->body_contains('o'), 'content contains "o"'; ok $content->body_contains('foo'), 'content contains "foo"'; @@ -32,23 +32,23 @@ subtest 'Multipart' => sub { push @{$content->parts}, Mojo::Content::Single->new; $content->parts->[1]->asset->add_chunk('.*?foo+'); $content->parts->[1]->headers->header('X-Bender' => 'bar+'); - ok !$content->body_contains('z'), 'content does not contain "z"'; - ok $content->body_contains('f'), 'content contains "f"'; - ok $content->body_contains('o'), 'content contains "o"'; - ok $content->body_contains('foo'), 'content contains "foo"'; - ok $content->body_contains('bar+'), 'content contains "bar+"'; - ok $content->body_contains('.'), 'content contains "."'; - ok $content->body_contains('.*?foo+'), 'content contains ".*?foo+"'; - ok !$content->headers->content_type, 'no "Content-Type" header'; + ok !$content->body_contains('z'), 'content does not contain "z"'; + ok $content->body_contains('f'), 'content contains "f"'; + ok $content->body_contains('o'), 'content contains "o"'; + ok $content->body_contains('foo'), 'content contains "foo"'; + ok $content->body_contains('bar+'), 'content contains "bar+"'; + ok $content->body_contains('.'), 'content contains "."'; + ok $content->body_contains('.*?foo+'), 'content contains ".*?foo+"'; + ok !$content->headers->content_type, 'no "Content-Type" header'; ok my $boundary = $content->build_boundary, 'boundary has been generated'; - is $boundary, $content->boundary, 'same boundary'; + is $boundary, $content->boundary, 'same boundary'; is $content->headers->content_type, "multipart/mixed; boundary=$boundary", 'right "Content-Type" header'; }; subtest 'Dynamic content' => sub { my $content = Mojo::Content::Single->new; $content->write('Hello ')->write('World!'); - ok $content->is_dynamic, 'dynamic content'; + ok $content->is_dynamic, 'dynamic content'; ok !$content->is_chunked, 'no chunked content'; $content->write(''); ok $content->is_dynamic, 'dynamic content'; @@ -69,15 +69,15 @@ subtest 'Multipart boundary detection' => sub { my $content = Mojo::Content::MultiPart->new; is $content->boundary, undef, 'no boundary'; $content->headers->content_type('multipart/form-data; boundary = "azAZ09\'(),.:?-_+/"'); - is $content->boundary, "azAZ09\'(),.:?-_+/", 'right boundary'; + is $content->boundary, "azAZ09\'(),.:?-_+/", 'right boundary'; is $content->boundary, $content->build_boundary, 'same boundary'; $content->headers->content_type('multipart/form-data'); is $content->boundary, undef, 'no boundary'; $content->headers->content_type('multipart/form-data; boundary="foo bar baz"'); - is $content->boundary, 'foo bar baz', 'right boundary'; + is $content->boundary, 'foo bar baz', 'right boundary'; is $content->boundary, $content->build_boundary, 'same boundary'; $content->headers->content_type('MultiPart/Form-Data; BounDaRy="foo 123"'); - is $content->boundary, 'foo 123', 'right boundary'; + is $content->boundary, 'foo 123', 'right boundary'; is $content->boundary, $content->build_boundary, 'same boundary'; }; diff --git a/t/mojo/cookie.t b/t/mojo/cookie.t index 253bd2d821..2a61029d7b 100644 --- a/t/mojo/cookie.t +++ b/t/mojo/cookie.t @@ -34,7 +34,7 @@ subtest 'Parse normal request cookie (RFC 2965)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo=bar; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse request cookies from multiple header values (RFC 2965)' => sub { @@ -43,14 +43,14 @@ subtest 'Parse request cookies from multiple header values (RFC 2965)' => sub { is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'baz', 'right name'; is $cookies->[1]->value, 'yada', 'right value'; - is $cookies->[2], undef, 'no more cookies'; + is $cookies->[2], undef, 'no more cookies'; }; subtest 'Parse request cookie (Netscape)' => sub { my $cookies = Mojo::Cookie::Request->parse('CUSTOMER=WILE_E_COYOTE'); is $cookies->[0]->name, 'CUSTOMER', 'right name'; is $cookies->[0]->value, 'WILE_E_COYOTE', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse multiple request cookies (Netscape)' => sub { @@ -59,7 +59,7 @@ subtest 'Parse multiple request cookies (Netscape)' => sub { is $cookies->[0]->value, 'WILE_E_COYOTE', 'right value'; is $cookies->[1]->name, 'PART_NUMBER', 'right name'; is $cookies->[1]->value, 'ROCKET_LAUNCHER_0001', 'right value'; - is $cookies->[2], undef, 'no more cookies'; + is $cookies->[2], undef, 'no more cookies'; }; subtest 'Parse multiple request cookies from multiple header values (Netscape)' => sub { @@ -68,69 +68,69 @@ subtest 'Parse multiple request cookies from multiple header values (Netscape)' is $cookies->[0]->value, 'WILE_E_COYOTE', 'right value'; is $cookies->[1]->name, 'PART_NUMBER', 'right name'; is $cookies->[1]->value, 'ROCKET_LAUNCHER_0001', 'right value'; - is $cookies->[2], undef, 'no more cookies'; + is $cookies->[2], undef, 'no more cookies'; }; subtest 'Parse request cookie without value (RFC 2965)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo=; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, '', 'no value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Request->parse('$Version=1; foo=""; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, '', 'no value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted request cookie (RFC 2965)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo="b ,a\" r\"\\\\"; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a" r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted request cookie roundtrip (RFC 2965)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo="b ,a\";= r\"\\\\"; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a";= r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Request->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a";= r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted request cookie roundtrip (RFC 2965, alternative)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo="b ,a\" r\"\\\\"; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a" r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Request->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a" r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted request cookie roundtrip (RFC 2965, another alternative)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo="b ;a\" r\"\\\\"; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ;a" r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Request->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ;a" r"\\', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted request cookie roundtrip (RFC 2965, yet another alternative)' => sub { my $cookies = Mojo::Cookie::Request->parse('$Version=1; foo="\"b a\" r\""; $Path="/test"'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, '"b a" r"', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Request->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, '"b a" r"', 'right value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse multiple cookie request (RFC 2965)' => sub { @@ -139,7 +139,7 @@ subtest 'Parse multiple cookie request (RFC 2965)' => sub { is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'baz', 'right name'; is $cookies->[1]->value, 'la la', 'right value'; - is $cookies->[2], undef, 'no more cookies'; + is $cookies->[2], undef, 'no more cookies'; }; subtest 'Response cookie as string' => sub { @@ -187,7 +187,7 @@ subtest 'Parse response cookie (Netscape)' => sub { is $cookies->[0]->name, 'CUSTOMER', 'right name'; is $cookies->[0]->value, 'WILE_E_COYOTE', 'right value'; is $cookies->[0]->expires, 942189160, 'right expires value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse multiple response cookies (Netscape)' => sub { @@ -200,7 +200,7 @@ subtest 'Parse multiple response cookies (Netscape)' => sub { is $cookies->[1]->name, 'SHIPPING', 'right name'; is $cookies->[1]->value, 'FEDEX', 'right value'; is $cookies->[1]->expires, 942189161, 'right expires value'; - is $cookies->[2], undef, 'no more cookies'; + is $cookies->[2], undef, 'no more cookies'; }; subtest 'Parse response cookie (RFC 6265)' => sub { @@ -213,7 +213,7 @@ subtest 'Parse response cookie (RFC 6265)' => sub { is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse response cookie with invalid flag (RFC 6265)' => sub { @@ -226,7 +226,7 @@ subtest 'Parse response cookie with invalid flag (RFC 6265)' => sub { is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, undef, 'no secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted response cookie (RFC 6265)' => sub { @@ -239,7 +239,7 @@ subtest 'Parse quoted response cookie (RFC 6265)' => sub { is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted response cookie (RFC 6265, alternative)' => sub { @@ -252,7 +252,7 @@ subtest 'Parse quoted response cookie (RFC 6265, alternative)' => sub { is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted response cookie roundtrip (RFC 6265)' => sub { @@ -265,7 +265,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265)' => sub { is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a";= r"\\', 'right value'; @@ -274,7 +274,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265)' => sub { is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted response cookie roundtrip (RFC 6265, alternative)' => sub { @@ -287,7 +287,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265, alternative)' => sub is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ,a" r"\\', 'right value'; @@ -296,7 +296,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265, alternative)' => sub is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted response cookie roundtrip (RFC 6265, another alternative)' => sub { @@ -309,7 +309,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265, another alternative)' is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'b ;a" r"\\', 'right value'; @@ -318,7 +318,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265, another alternative)' is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse quoted response cookie roundtrip (RFC 6265, yet another alternative)' => sub { @@ -331,7 +331,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265, yet another alternati is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse($cookies->[0]->to_string); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, '"b a" r"', 'right value'; @@ -340,7 +340,7 @@ subtest 'Parse quoted response cookie roundtrip (RFC 6265, yet another alternati is $cookies->[0]->max_age, 60, 'right max age value'; is $cookies->[0]->expires, 1218092879, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse response cookie without value (RFC 2965)' => sub { @@ -381,7 +381,7 @@ subtest 'Parse response cookie with SameSite value' => sub { is $cookies->[0]->max_age, undef, 'no max age value'; is $cookies->[0]->expires, 942189160, 'right expires value'; is $cookies->[0]->samesite, 'Lax', 'right samesite value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse response cookie with broken Expires and Domain values' => sub { @@ -390,19 +390,19 @@ subtest 'Parse response cookie with broken Expires and Domain values' => sub { is $cookies->[0]->value, 'ba r', 'right value'; is $cookies->[0]->expires, undef, 'no expires value'; is $cookies->[0]->domain, undef, 'no domain value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse('foo="ba r"; Expires=Th; Domain=; Path=/test'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'ba r', 'right value'; is $cookies->[0]->expires, undef, 'no expires value'; is $cookies->[0]->domain, '', 'no domain value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse('foo="ba r"; Expires; Domain; Path=/test'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'ba r', 'right value'; is $cookies->[0]->expires, undef, 'no expires value'; is $cookies->[0]->domain, undef, 'no domain value'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Response cookie with Max-Age 0 and Expires 0' => sub { @@ -425,7 +425,7 @@ subtest 'Parse response cookie with Max-Age 0 and Expires 0 (RFC 6265)' => sub { is $cookies->[0]->max_age, 0, 'right max age value'; is $cookies->[0]->expires, 0, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Parse response cookie with two digit year (RFC 6265)' => sub { @@ -435,14 +435,14 @@ subtest 'Parse response cookie with two digit year (RFC 6265)' => sub { is $cookies->[0]->path, '/', 'right path'; is $cookies->[0]->expires, 1573341160, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; $cookies = Mojo::Cookie::Response->parse('foo=bar; Path=/; Expires=Tuesday, 09-Nov-99 23:12:40 GMT; Secure'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[0]->path, '/', 'right path'; is $cookies->[0]->expires, 942189160, 'right expires value'; is $cookies->[0]->secure, 1, 'right secure flag'; - is $cookies->[1], undef, 'no more cookies'; + is $cookies->[1], undef, 'no more cookies'; }; subtest 'Abstract methods' => sub { diff --git a/t/mojo/cookiejar.t b/t/mojo/cookiejar.t index ff94b9e91b..3755b3e902 100644 --- a/t/mojo/cookiejar.t +++ b/t/mojo/cookiejar.t @@ -26,31 +26,31 @@ subtest 'Session cookie' => sub { is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'just', 'right name'; is $cookies->[1]->value, 'works', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'just', 'right name'; is $cookies->[1]->value, 'works', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'just', 'right name'; is $cookies->[1]->value, 'works', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'just', 'right name'; is $cookies->[1]->value, 'works', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; is $cookies->[1]->name, 'just', 'right name'; is $cookies->[1]->value, 'works', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; $jar->empty; $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); is $cookies->[0], undef, 'no cookies'; @@ -65,23 +65,23 @@ subtest '"localhost"' => sub { my $cookies = $jar->find(Mojo::URL->new('http://localhost/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; $cookies = $jar->find(Mojo::URL->new('http://foo.localhost/foo')); is $cookies->[0]->name, 'bar', 'right name'; is $cookies->[0]->value, 'baz', 'right value'; is $cookies->[1]->name, 'foo', 'right name'; is $cookies->[1]->value, 'bar', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; $cookies = $jar->find(Mojo::URL->new('http://foo.bar.localhost/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; $cookies = $jar->find(Mojo::URL->new('http://bar.foo.localhost/foo')); is $cookies->[0]->name, 'bar', 'right name'; is $cookies->[0]->value, 'baz', 'right value'; is $cookies->[1]->name, 'foo', 'right name'; is $cookies->[1]->value, 'bar', 'right value'; - is $cookies->[2], undef, 'no third cookie'; + is $cookies->[2], undef, 'no third cookie'; }; subtest 'Huge cookie' => sub { @@ -92,11 +92,11 @@ subtest 'Huge cookie' => sub { Mojo::Cookie::Response->new(domain => 'example.com', path => '/foo', name => 'huge', value => 'x' x 1025) ); my $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); - is $cookies->[0]->name, 'small', 'right name'; - is $cookies->[0]->value, 'x', 'right value'; - is $cookies->[1]->name, 'big', 'right name'; + is $cookies->[0]->name, 'small', 'right name'; + is $cookies->[0]->value, 'x', 'right value'; + is $cookies->[1]->name, 'big', 'right name'; is $cookies->[1]->value, 'x' x 1024, 'right value'; - is $cookies->[2], undef, 'no second cookie'; + is $cookies->[2], undef, 'no second cookie'; }; subtest 'Expired cookies' => sub { @@ -111,7 +111,7 @@ subtest 'Expired cookies' => sub { my $cookies = $jar->find(Mojo::URL->new('http://labs.example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; }; subtest 'Replace cookie' => sub { @@ -123,7 +123,7 @@ subtest 'Replace cookie' => sub { my $cookies = $jar->find(Mojo::URL->new('http://example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar2', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; }; subtest 'Switch between secure and normal cookies' => sub { @@ -142,7 +142,7 @@ subtest 'Switch between secure and normal cookies' => sub { $cookies = $jar->find(Mojo::URL->new('https://example.com/foo')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; }; subtest '"(" in path' => sub { @@ -151,11 +151,11 @@ subtest '"(" in path' => sub { my $cookies = $jar->find(Mojo::URL->new('http://example.com/foo(bar')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; $cookies = $jar->find(Mojo::URL->new('http://example.com/foo(bar/baz')); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; }; subtest 'Gather and prepare cookies without domain and path' => sub { @@ -172,12 +172,12 @@ subtest 'Gather and prepare cookies without domain and path' => sub { $tx = Mojo::Transaction::HTTP->new; $tx->req->url->parse('http://mojolicious.org/perldoc'); $jar->prepare($tx); - is $tx->req->cookie('foo')->name, 'foo', 'right name'; - is $tx->req->cookie('foo')->value, 'without', 'right value'; - is $jar->all->[0]->name, 'foo', 'right name'; - is $jar->all->[0]->value, 'without', 'right value'; - is $jar->all->[0]->domain, 'mojolicious.org', 'right domain'; - is $jar->all->[1], undef, 'no second cookie'; + is $tx->req->cookie('foo')->name, 'foo', 'right name'; + is $tx->req->cookie('foo')->value, 'without', 'right value'; + is $jar->all->[0]->name, 'foo', 'right name'; + is $jar->all->[0]->value, 'without', 'right value'; + is $jar->all->[0]->domain, 'mojolicious.org', 'right domain'; + is $jar->all->[1], undef, 'no second cookie'; $tx = Mojo::Transaction::HTTP->new; $tx->req->url->parse('http://www.mojolicious.org/perldoc'); $jar->prepare($tx); @@ -205,14 +205,14 @@ subtest 'Gather and prepare cookies with same name (with and without domain)' => my $cookies = $tx->req->every_cookie('foo'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'with', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; $tx = Mojo::Transaction::HTTP->new; $tx->req->url->parse('http://www.example.com/test'); $jar->prepare($tx); $cookies = $tx->req->every_cookie('foo'); is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'with', 'right value'; - is $cookies->[1], undef, 'no second cookie'; + is $cookies->[1], undef, 'no second cookie'; }; subtest 'Gather and prepare cookies for "localhost" (valid and invalid)' => sub { @@ -229,7 +229,7 @@ subtest 'Gather and prepare cookies for "localhost" (valid and invalid)' => sub $jar->prepare($tx); is $tx->req->cookie('foo')->name, 'foo', 'right name'; is $tx->req->cookie('foo')->value, 'local', 'right value'; - is $tx->req->cookie('bar'), undef, 'no cookie'; + is $tx->req->cookie('bar'), undef, 'no cookie'; }; subtest 'Gather and prepare cookies for unknown public suffix (with IDNA)' => sub { @@ -262,7 +262,7 @@ subtest 'Gather and prepare cookies for public suffix (with IDNA)' => sub { $tx = Mojo::Transaction::HTTP->new; $tx->req->url->parse('http://bücher.com/foo'); $jar->prepare($tx); - is $tx->req->cookie('foo'), undef, 'no cookie'; + is $tx->req->cookie('foo'), undef, 'no cookie'; is $tx->req->cookie('bar')->name, 'bar', 'right name'; is $tx->req->cookie('bar')->value, 'baz', 'right value'; }; @@ -294,7 +294,7 @@ subtest 'Gather and prepare cookies with domain and path' => sub { $tx = Mojo::Transaction::HTTP->new; $tx->req->url->parse('http://bücher.COM/perldoc/Mojolicious/Lite'); $jar->prepare($tx); - is $tx->req->cookie('foo'), undef, 'no cookie'; + is $tx->req->cookie('foo'), undef, 'no cookie'; is $tx->req->cookie('bar')->name, 'bar', 'right name'; is $tx->req->cookie('bar')->value, 'with', 'right value'; is $tx->req->cookie('0')->name, '0', 'right name'; @@ -302,7 +302,7 @@ subtest 'Gather and prepare cookies with domain and path' => sub { $tx = Mojo::Transaction::HTTP->new; $tx->req->url->parse('http://labs.bücher.COM/Perldoc'); $jar->prepare($tx); - is $tx->req->cookie('foo'), undef, 'no cookie'; + is $tx->req->cookie('foo'), undef, 'no cookie'; is $tx->req->cookie('bar')->name, 'bar', 'right name'; is $tx->req->cookie('bar')->value, 'with', 'right value'; }; @@ -335,8 +335,8 @@ subtest 'Gather cookies with invalid expiration' => sub { is $jar->all->[0]->name, 'foo', 'right name'; is $jar->all->[0]->value, 'bar', 'right value'; ok !$jar->all->[0]->expires, 'does not expire'; - is $jar->all->[1]->name, 'bar', 'right name'; - is $jar->all->[1]->value, 'baz', 'right value'; + is $jar->all->[1]->name, 'bar', 'right name'; + is $jar->all->[1]->value, 'baz', 'right value'; ok $jar->all->[1]->expires, 'expires'; }; diff --git a/t/mojo/daemon.t b/t/mojo/daemon.t index b400b2d152..58567febb7 100644 --- a/t/mojo/daemon.t +++ b/t/mojo/daemon.t @@ -77,10 +77,10 @@ subtest 'Config' => sub { subtest 'Loading' => sub { my $daemon = Mojo::Server::Daemon->new; my $path = curfile->sibling('lib', '..', 'lib', 'myapp.pl'); - is ref $daemon->load_app($path), 'Mojolicious::Lite', 'right reference'; - is $daemon->app->config('script'), path($path)->to_abs, 'right script name'; - is ref $daemon->build_app('TestApp'), 'TestApp', 'right reference'; - is ref $daemon->app, 'TestApp', 'right reference'; + is ref $daemon->load_app($path), 'Mojolicious::Lite', 'right reference'; + is $daemon->app->config('script'), path($path)->to_abs, 'right script name'; + is ref $daemon->build_app('TestApp'), 'TestApp', 'right reference'; + is ref $daemon->app, 'TestApp', 'right reference'; }; subtest 'Load broken app' => sub { @@ -181,7 +181,7 @@ subtest 'Keep-alive request' => sub { subtest 'Non-keep-alive request' => sub { my $tx = $ua->get('/close/' => {Connection => 'close'}); ok !$tx->keep_alive, 'will not be kept alive'; - ok $tx->kept_alive, 'was kept alive'; + ok $tx->kept_alive, 'was kept alive'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'Whatever!', 'right content'; }; @@ -223,10 +223,10 @@ subtest 'Concurrent requests' => sub { })->wait; ok $tx->is_finished, 'transaction is finished'; is $tx->res->body, 'Whatever!', 'right content'; - ok !$tx->error, 'no error'; + ok !$tx->error, 'no error'; ok $tx2->is_finished, 'transaction is finished'; is $tx2->res->body, 'Whatever!', 'right content'; - ok !$tx2->error, 'no error'; + ok !$tx2->error, 'no error'; ok $tx3->is_finished, 'transaction is finished'; is $tx3->res->body, 'Whatever!', 'right content'; ok !$tx3->error, 'no error'; @@ -238,24 +238,24 @@ subtest 'Form with chunked response' => sub { my $result = ''; for my $key (sort keys %params) { $result .= $params{$key} } my $tx = $ua->post('/chunked' => form => \%params); - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $result, 'right content'; }; subtest 'Upload' => sub { my $result = ''; my $tx = $ua->post('/upload' => form => {file => {content => $result}}); - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $result, 'right content'; - ok $tx->local_address, 'has local address'; - ok $tx->local_port > 0, 'has local port'; + ok $tx->local_address, 'has local address'; + ok $tx->local_port > 0, 'has local port'; ok $tx->original_remote_address, 'has original remote address'; ok $tx->remote_address, 'has remote address'; - ok $tx->remote_port > 0, 'has remote port'; - ok $local_address, 'has local address'; - ok $local_port > 0, 'has local port'; - ok $remote_address, 'has remote address'; - ok $remote_port > 0, 'has remote port'; + ok $tx->remote_port > 0, 'has remote port'; + ok $local_address, 'has local address'; + ok $local_port > 0, 'has local port'; + ok $remote_address, 'has remote address'; + ok $remote_port > 0, 'has remote port'; }; subtest 'Timeout' => sub { @@ -295,9 +295,9 @@ subtest 'Pipelined' => sub { subtest 'Throttling' => sub { my $daemon = Mojo::Server::Daemon->new(app => $app, listen => ['http://127.0.0.1'], max_clients => 23, silent => 1); - is scalar @{$daemon->acceptors}, 0, 'no active acceptors'; - is scalar @{$daemon->start->start->acceptors}, 1, 'one active acceptor'; - is $daemon->ioloop->max_connections, 23, 'right value'; + is scalar @{$daemon->acceptors}, 0, 'no active acceptors'; + is scalar @{$daemon->start->start->acceptors}, 1, 'one active acceptor'; + is $daemon->ioloop->max_connections, 23, 'right value'; my $id = $daemon->acceptors->[0]; ok !!Mojo::IOLoop->acceptor($id), 'acceptor has been added'; is scalar @{$daemon->stop->acceptors}, 0, 'no active acceptors'; @@ -331,15 +331,15 @@ subtest 'Single-accept and connection limit' => sub { ); $loop->client({port => $acceptor->port} => sub { }) for 1 .. 2; $loop->start; - ok $accepting[0], 'accepting connections'; + ok $accepting[0], 'accepting connections'; ok !$accepting[1], 'connection limit reached'; }; subtest 'Request limit' => sub { my $daemon = Mojo::Server::Daemon->new(app => $app, listen => ['http://127.0.0.1'], silent => 1)->start; my $port = $daemon->ports->[0]; - is $daemon->max_requests, 100, 'right value'; - is $daemon->max_requests(2)->max_requests, 2, 'right value'; + is $daemon->max_requests, 100, 'right value'; + is $daemon->max_requests(2)->max_requests, 2, 'right value'; my $tx = $ua->get("http://127.0.0.1:$port/keep_alive/1"); ok $tx->keep_alive, 'will be kept alive'; is $tx->res->code, 200, 'right status'; @@ -357,7 +357,7 @@ subtest 'File descriptor' => sub { my $port = $listen->sockport; is $daemon->ports->[0], $port, 'same port'; my $tx = $ua->get("http://127.0.0.1:$port/port"); - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $port, 'right content'; }; diff --git a/t/mojo/date.t b/t/mojo/date.t index c3a166cd6c..88b04cfcbc 100644 --- a/t/mojo/date.t +++ b/t/mojo/date.t @@ -70,8 +70,8 @@ subtest "Current time roundtrips" => sub { subtest "Zero time checks" => sub { my $date = Mojo::Date->new(0); - is $date->epoch, 0, 'right epoch value'; - is "$date", 'Thu, 01 Jan 1970 00:00:00 GMT', 'right format'; + is $date->epoch, 0, 'right epoch value'; + is "$date", 'Thu, 01 Jan 1970 00:00:00 GMT', 'right format'; is(Mojo::Date->new('Thu, 01 Jan 1970 00:00:00 GMT')->epoch, 0, 'right epoch value'); }; diff --git a/t/mojo/dom.t b/t/mojo/dom.t index f7cd80560c..e3f3077d1a 100644 --- a/t/mojo/dom.t +++ b/t/mojo/dom.t @@ -22,9 +22,9 @@ subtest 'Simple (basics)' => sub { @div = (); $dom->find('div[id]')->each(sub { push @div, $_->text }); is_deeply \@div, [qw(A B)], 'found all div elements with id'; - is $dom->at('#a')->attr('foo'), 0, 'right attribute'; - is $dom->at('#a')->attr->{foo}, 0, 'right attribute'; - is "$dom", '
A
B
', 'right result'; + is $dom->at('#a')->attr('foo'), 0, 'right attribute'; + is $dom->at('#a')->attr->{foo}, 0, 'right attribute'; + is "$dom", '
A
B
', 'right result'; }; subtest 'Tap into method chain' => sub { @@ -41,36 +41,36 @@ subtest 'Simple nesting with healing (tree structure)' => sub { my $dom = Mojo::DOM->new(<justworks EOF - is $dom->tree->[0], 'root', 'right type'; - is $dom->tree->[1][0], 'tag', 'right type'; - is $dom->tree->[1][1], 'foo', 'right tag'; + is $dom->tree->[0], 'root', 'right type'; + is $dom->tree->[1][0], 'tag', 'right type'; + is $dom->tree->[1][1], 'foo', 'right tag'; is_deeply $dom->tree->[1][2], {}, 'empty attributes'; - is $dom->tree->[1][3], $dom->tree, 'right parent'; - is $dom->tree->[1][4][0], 'tag', 'right type'; - is $dom->tree->[1][4][1], 'bar', 'right tag'; + is $dom->tree->[1][3], $dom->tree, 'right parent'; + is $dom->tree->[1][4][0], 'tag', 'right type'; + is $dom->tree->[1][4][1], 'bar', 'right tag'; is_deeply $dom->tree->[1][4][2], {a => 'btree->[1][4][3], $dom->tree->[1], 'right parent'; - is $dom->tree->[1][4][4][0], 'text', 'right type'; - is $dom->tree->[1][4][4][1], 'ju', 'right text'; + is $dom->tree->[1][4][3], $dom->tree->[1], 'right parent'; + is $dom->tree->[1][4][4][0], 'text', 'right type'; + is $dom->tree->[1][4][4][1], 'ju', 'right text'; is $dom->tree->[1][4][4][2], $dom->tree->[1][4], 'right parent'; - is $dom->tree->[1][4][5][0], 'tag', 'right type'; - is $dom->tree->[1][4][5][1], 'baz', 'right tag'; + is $dom->tree->[1][4][5][0], 'tag', 'right type'; + is $dom->tree->[1][4][5][1], 'baz', 'right tag'; is_deeply $dom->tree->[1][4][5][2], {a23 => undef}, 'right attributes'; - is $dom->tree->[1][4][5][3], $dom->tree->[1][4], 'right parent'; - is $dom->tree->[1][4][5][4][0], 'text', 'right type'; - is $dom->tree->[1][4][5][4][1], 's', 'right text'; + is $dom->tree->[1][4][5][3], $dom->tree->[1][4], 'right parent'; + is $dom->tree->[1][4][5][4][0], 'text', 'right type'; + is $dom->tree->[1][4][5][4][1], 's', 'right text'; is $dom->tree->[1][4][5][4][2], $dom->tree->[1][4][5], 'right parent'; - is $dom->tree->[1][4][5][5][0], 'tag', 'right type'; - is $dom->tree->[1][4][5][5][1], 'bazz', 'right tag'; + is $dom->tree->[1][4][5][5][0], 'tag', 'right type'; + is $dom->tree->[1][4][5][5][1], 'bazz', 'right tag'; is_deeply $dom->tree->[1][4][5][5][2], {}, 'empty attributes'; is $dom->tree->[1][4][5][5][3], $dom->tree->[1][4][5], 'right parent'; - is $dom->tree->[1][4][5][6][0], 'text', 'right type'; - is $dom->tree->[1][4][5][6][1], 't', 'right text'; + is $dom->tree->[1][4][5][6][0], 'text', 'right type'; + is $dom->tree->[1][4][5][6][1], 't', 'right text'; is $dom->tree->[1][4][5][6][2], $dom->tree->[1][4][5], 'right parent'; - is $dom->tree->[1][5][0], 'text', 'right type'; - is $dom->tree->[1][5][1], 'works', 'right text'; - is $dom->tree->[1][5][2], $dom->tree->[1], 'right parent'; - is "$dom", <tree->[1][5][0], 'text', 'right type'; + is $dom->tree->[1][5][1], 'works', 'right text'; + is $dom->tree->[1][5][2], $dom->tree->[1], 'right parent'; + is "$dom", <justworks EOF }; @@ -82,13 +82,13 @@ subtest 'Select based on parent' => sub {
test2
EOF - is $dom->find('body > div')->[0]->text, 'test1', 'right text'; - is $dom->find('body > div')->[1]->text, '', 'no content'; - is $dom->find('body > div')->[2], undef, 'no result'; - is $dom->find('body > div')->size, 2, 'right number of elements'; + is $dom->find('body > div')->[0]->text, 'test1', 'right text'; + is $dom->find('body > div')->[1]->text, '', 'no content'; + is $dom->find('body > div')->[2], undef, 'no result'; + is $dom->find('body > div')->size, 2, 'right number of elements'; is $dom->find('body > div > div')->[0]->text, 'test2', 'right text'; - is $dom->find('body > div > div')->[1], undef, 'no result'; - is $dom->find('body > div > div')->size, 1, 'right number of elements'; + is $dom->find('body > div > div')->[1], undef, 'no result'; + is $dom->find('body > div > div')->size, 1, 'right number of elements'; }; subtest 'A bit of everything (basic navigation)' => sub { @@ -109,12 +109,12 @@ subtest 'A bit of everything (basic navigation)' => sub { EOF ok !$dom->xml, 'XML mode not detected'; - is $dom->tag, undef, 'no tag'; - is $dom->attr('foo'), undef, 'no attribute'; - is $dom->attr(foo => 'bar')->attr('foo'), undef, 'no attribute'; - is $dom->tree->[1][0], 'doctype', 'right type'; - is $dom->tree->[1][1], ' foo', 'right doctype'; - is "$dom", <tag, undef, 'no tag'; + is $dom->attr('foo'), undef, 'no attribute'; + is $dom->attr(foo => 'bar')->attr('foo'), undef, 'no attribute'; + is $dom->tree->[1][0], 'doctype', 'right type'; + is $dom->tree->[1][1], ' foo', 'right doctype'; + is "$dom", < test @@ -134,127 +134,127 @@ EOF is $simple->parent->all_text, "\n test\n easy\n \n \n works well\n yada yada\n" . " \n \n < very broken\n \n more text\n", 'right text'; - is $simple->tag, 'simple', 'right tag'; - is $simple->attr('class'), 'working', 'right class attribute'; - is $simple->text, 'easy', 'right text'; - is $simple->parent->tag, 'foo', 'right parent tag'; - is $simple->parent->attr->{bar}, 'baparent->children->[1]->tag, 'test', 'right sibling'; - is $simple->to_string, 'easy', 'stringified right'; + is $simple->tag, 'simple', 'right tag'; + is $simple->attr('class'), 'working', 'right class attribute'; + is $simple->text, 'easy', 'right text'; + is $simple->parent->tag, 'foo', 'right parent tag'; + is $simple->parent->attr->{bar}, 'baparent->children->[1]->tag, 'test', 'right sibling'; + is $simple->to_string, 'easy', 'stringified right'; $simple->parent->attr(bar => 'baz')->attr({this => 'works', too => 'yea'}); - is $simple->parent->attr('bar'), 'baz', 'right parent attribute'; - is $simple->parent->attr('this'), 'works', 'right parent attribute'; - is $simple->parent->attr('too'), 'yea', 'right parent attribute'; - is $dom->at('test#test')->tag, 'test', 'right tag'; - is $dom->at('[class$="ing"]')->tag, 'simple', 'right tag'; - is $dom->at('[class="working"]')->tag, 'simple', 'right tag'; - is $dom->at('[class$=ing]')->tag, 'simple', 'right tag'; - is $dom->at('[class=working][class]')->tag, 'simple', 'right tag'; - is $dom->at('foo > simple')->next->tag, 'test', 'right tag'; - is $dom->at('foo > simple')->next->next->tag, 'a', 'right tag'; - is $dom->at('foo > test')->previous->tag, 'simple', 'right tag'; - is $dom->next, undef, 'no siblings'; - is $dom->previous, undef, 'no siblings'; - is $dom->at('foo > a')->next, undef, 'no next sibling'; - is $dom->at('foo > simple')->previous, undef, 'no previous sibling'; + is $simple->parent->attr('bar'), 'baz', 'right parent attribute'; + is $simple->parent->attr('this'), 'works', 'right parent attribute'; + is $simple->parent->attr('too'), 'yea', 'right parent attribute'; + is $dom->at('test#test')->tag, 'test', 'right tag'; + is $dom->at('[class$="ing"]')->tag, 'simple', 'right tag'; + is $dom->at('[class="working"]')->tag, 'simple', 'right tag'; + is $dom->at('[class$=ing]')->tag, 'simple', 'right tag'; + is $dom->at('[class=working][class]')->tag, 'simple', 'right tag'; + is $dom->at('foo > simple')->next->tag, 'test', 'right tag'; + is $dom->at('foo > simple')->next->next->tag, 'a', 'right tag'; + is $dom->at('foo > test')->previous->tag, 'simple', 'right tag'; + is $dom->next, undef, 'no siblings'; + is $dom->previous, undef, 'no siblings'; + is $dom->at('foo > a')->next, undef, 'no next sibling'; + is $dom->at('foo > simple')->previous, undef, 'no previous sibling'; is_deeply [$dom->at('simple')->ancestors->map('tag')->each], ['foo'], 'right results'; ok !$dom->at('simple')->ancestors->first->xml, 'XML mode not active'; }; subtest 'Nodes' => sub { my $dom = Mojo::DOM->new('

test

'); - is $dom->at('p')->preceding_nodes->first->content, ' before', 'right content'; - is $dom->at('p')->preceding_nodes->size, 1, 'right number of nodes'; - is $dom->at('p')->child_nodes->last->preceding_nodes->first->content, 'test', 'right content'; - is $dom->at('p')->child_nodes->last->preceding_nodes->last->content, '123', 'right content'; - is $dom->at('p')->child_nodes->last->preceding_nodes->size, 2, 'right number of nodes'; - is $dom->preceding_nodes->size, 0, 'no preceding nodes'; - is $dom->at('p')->following_nodes->first->content, 'after', 'right content'; - is $dom->at('p')->following_nodes->size, 1, 'right number of nodes'; - is $dom->child_nodes->first->following_nodes->first->tag, 'p', 'right tag'; - is $dom->child_nodes->first->following_nodes->last->content, 'after', 'right content'; - is $dom->child_nodes->first->following_nodes->size, 2, 'right number of nodes'; - is $dom->following_nodes->size, 0, 'no following nodes'; - is $dom->at('p')->previous_node->content, ' before', 'right content'; - is $dom->at('p')->previous_node->previous_node, undef, 'no more siblings'; - is $dom->at('p')->next_node->content, 'after', 'right content'; - is $dom->at('p')->next_node->next_node, undef, 'no more siblings'; - is $dom->at('p')->child_nodes->last->previous_node->previous_node->content, 'test', 'right content'; - is $dom->at('p')->child_nodes->first->next_node->next_node->content, ' 456 ', 'right content'; - is $dom->descendant_nodes->[0]->type, 'doctype', 'right type'; - is $dom->descendant_nodes->[0]->content, ' before', 'right content'; - is $dom->descendant_nodes->[0], '', 'right content'; - is $dom->descendant_nodes->[1]->tag, 'p', 'right tag'; - is $dom->descendant_nodes->[2]->type, 'text', 'right type'; - is $dom->descendant_nodes->[2]->content, 'test', 'right content'; - is $dom->descendant_nodes->[5]->type, 'pi', 'right type'; - is $dom->descendant_nodes->[5]->content, 'after', 'right content'; - is $dom->at('p')->descendant_nodes->[0]->type, 'text', 'right type'; - is $dom->at('p')->descendant_nodes->[0]->content, 'test', 'right type'; - is $dom->at('p')->descendant_nodes->last->type, 'comment', 'right type'; - is $dom->at('p')->descendant_nodes->last->content, ' 456 ', 'right type'; - is $dom->child_nodes->[1]->child_nodes->first->parent->tag, 'p', 'right tag'; - is $dom->child_nodes->[1]->child_nodes->first->content, 'test', 'right content'; - is $dom->child_nodes->[1]->child_nodes->first, 'test', 'right content'; - is $dom->at('p')->child_nodes->first->type, 'text', 'right type'; - is $dom->at('p')->child_nodes->first->remove->tag, 'p', 'right tag'; - is $dom->at('p')->child_nodes->first->type, 'cdata', 'right type'; - is $dom->at('p')->child_nodes->first->content, '123', 'right content'; - is $dom->at('p')->child_nodes->[1]->type, 'comment', 'right type'; - is $dom->at('p')->child_nodes->[1]->content, ' 456 ', 'right content'; - is $dom->[0]->type, 'doctype', 'right type'; - is $dom->[0]->content, ' before', 'right content'; - is $dom->child_nodes->[2]->type, 'pi', 'right type'; - is $dom->child_nodes->[2]->content, 'after', 'right content'; - is $dom->child_nodes->first->content(' again')->content, ' again', 'right content'; - is $dom->child_nodes->grep(sub { $_->type eq 'pi' })->map('remove')->first->type, 'root', 'right type'; - is "$dom", '

', 'right result'; + is $dom->at('p')->preceding_nodes->first->content, ' before', 'right content'; + is $dom->at('p')->preceding_nodes->size, 1, 'right number of nodes'; + is $dom->at('p')->child_nodes->last->preceding_nodes->first->content, 'test', 'right content'; + is $dom->at('p')->child_nodes->last->preceding_nodes->last->content, '123', 'right content'; + is $dom->at('p')->child_nodes->last->preceding_nodes->size, 2, 'right number of nodes'; + is $dom->preceding_nodes->size, 0, 'no preceding nodes'; + is $dom->at('p')->following_nodes->first->content, 'after', 'right content'; + is $dom->at('p')->following_nodes->size, 1, 'right number of nodes'; + is $dom->child_nodes->first->following_nodes->first->tag, 'p', 'right tag'; + is $dom->child_nodes->first->following_nodes->last->content, 'after', 'right content'; + is $dom->child_nodes->first->following_nodes->size, 2, 'right number of nodes'; + is $dom->following_nodes->size, 0, 'no following nodes'; + is $dom->at('p')->previous_node->content, ' before', 'right content'; + is $dom->at('p')->previous_node->previous_node, undef, 'no more siblings'; + is $dom->at('p')->next_node->content, 'after', 'right content'; + is $dom->at('p')->next_node->next_node, undef, 'no more siblings'; + is $dom->at('p')->child_nodes->last->previous_node->previous_node->content, 'test', 'right content'; + is $dom->at('p')->child_nodes->first->next_node->next_node->content, ' 456 ', 'right content'; + is $dom->descendant_nodes->[0]->type, 'doctype', 'right type'; + is $dom->descendant_nodes->[0]->content, ' before', 'right content'; + is $dom->descendant_nodes->[0], '', 'right content'; + is $dom->descendant_nodes->[1]->tag, 'p', 'right tag'; + is $dom->descendant_nodes->[2]->type, 'text', 'right type'; + is $dom->descendant_nodes->[2]->content, 'test', 'right content'; + is $dom->descendant_nodes->[5]->type, 'pi', 'right type'; + is $dom->descendant_nodes->[5]->content, 'after', 'right content'; + is $dom->at('p')->descendant_nodes->[0]->type, 'text', 'right type'; + is $dom->at('p')->descendant_nodes->[0]->content, 'test', 'right type'; + is $dom->at('p')->descendant_nodes->last->type, 'comment', 'right type'; + is $dom->at('p')->descendant_nodes->last->content, ' 456 ', 'right type'; + is $dom->child_nodes->[1]->child_nodes->first->parent->tag, 'p', 'right tag'; + is $dom->child_nodes->[1]->child_nodes->first->content, 'test', 'right content'; + is $dom->child_nodes->[1]->child_nodes->first, 'test', 'right content'; + is $dom->at('p')->child_nodes->first->type, 'text', 'right type'; + is $dom->at('p')->child_nodes->first->remove->tag, 'p', 'right tag'; + is $dom->at('p')->child_nodes->first->type, 'cdata', 'right type'; + is $dom->at('p')->child_nodes->first->content, '123', 'right content'; + is $dom->at('p')->child_nodes->[1]->type, 'comment', 'right type'; + is $dom->at('p')->child_nodes->[1]->content, ' 456 ', 'right content'; + is $dom->[0]->type, 'doctype', 'right type'; + is $dom->[0]->content, ' before', 'right content'; + is $dom->child_nodes->[2]->type, 'pi', 'right type'; + is $dom->child_nodes->[2]->content, 'after', 'right content'; + is $dom->child_nodes->first->content(' again')->content, ' again', 'right content'; + is $dom->child_nodes->grep(sub { $_->type eq 'pi' })->map('remove')->first->type, 'root', 'right type'; + is "$dom", '

', 'right result'; }; subtest 'Modify nodes' => sub { my $dom = Mojo::DOM->new(''); - is $dom->at('script')->type, 'tag', 'right type'; - is $dom->at('script')->[0]->type, 'raw', 'right type'; - is $dom->at('script')->[0]->content, 'lala', 'right content'; - is "$dom", '', 'right result'; - is $dom->at('script')->child_nodes->first->replace('ac1d')->tag, 'script', 'right tag'; - is "$dom", '', 'right result'; - is $dom->at('b')->child_nodes->first->append('e')->content, 'c', 'right content'; - is $dom->at('b')->child_nodes->first->prepend('f')->type, 'text', 'right type'; - is "$dom", '', 'right result'; - is $dom->at('script')->child_nodes->first->following->first->tag, 'b', 'right tag'; - is $dom->at('script')->child_nodes->first->next->content, 'fce', 'right content'; - is $dom->at('script')->child_nodes->first->previous, undef, 'no siblings'; - is $dom->at('script')->child_nodes->[2]->previous->content, 'fce', 'right content'; - is $dom->at('b')->child_nodes->[1]->next, undef, 'no siblings'; + is $dom->at('script')->type, 'tag', 'right type'; + is $dom->at('script')->[0]->type, 'raw', 'right type'; + is $dom->at('script')->[0]->content, 'lala', 'right content'; + is "$dom", '', 'right result'; + is $dom->at('script')->child_nodes->first->replace('ac1d')->tag, 'script', 'right tag'; + is "$dom", '', 'right result'; + is $dom->at('b')->child_nodes->first->append('e')->content, 'c', 'right content'; + is $dom->at('b')->child_nodes->first->prepend('f')->type, 'text', 'right type'; + is "$dom", '', 'right result'; + is $dom->at('script')->child_nodes->first->following->first->tag, 'b', 'right tag'; + is $dom->at('script')->child_nodes->first->next->content, 'fce', 'right content'; + is $dom->at('script')->child_nodes->first->previous, undef, 'no siblings'; + is $dom->at('script')->child_nodes->[2]->previous->content, 'fce', 'right content'; + is $dom->at('b')->child_nodes->[1]->next, undef, 'no siblings'; is $dom->at('script')->child_nodes->first->wrap(':)')->root, '', 'right result'; is $dom->at('i')->child_nodes->first->wrap_content('')->root, '', 'no changes'; is $dom->at('i')->child_nodes->first->wrap('')->root, '', 'right result'; - is $dom->at('b')->child_nodes->first->ancestors->map('tag')->join(','), 'b,i,script', 'right result'; - is $dom->at('b')->child_nodes->first->append_content('g')->content, ':)g', 'right content'; - is $dom->at('b')->child_nodes->first->prepend_content('h')->content, 'h:)g', 'right content'; - is "$dom", '', 'right result'; + is $dom->at('b')->child_nodes->first->ancestors->map('tag')->join(','), 'b,i,script', 'right result'; + is $dom->at('b')->child_nodes->first->append_content('g')->content, ':)g', 'right content'; + is $dom->at('b')->child_nodes->first->prepend_content('h')->content, 'h:)g', 'right content'; + is "$dom", '', 'right result'; is $dom->at('script > b:last-of-type')->append('')->following_nodes->first->content, 'y', 'right content'; is $dom->at('i')->prepend('z')->preceding_nodes->first->content, 'z', 'right content'; - is $dom->at('i')->following->last->text, 'd', 'right text'; - is $dom->at('i')->following->size, 2, 'right number of following elements'; - is $dom->at('i')->following('b:last-of-type')->first->text, 'd', 'right text'; - is $dom->at('i')->following('b:last-of-type')->size, 1, 'right number of following elements'; - is $dom->following->size, 0, 'no following elements'; - is $dom->at('script > b:last-of-type')->preceding->first->tag, 'i', 'right tag'; - is $dom->at('script > b:last-of-type')->preceding->size, 2, 'right number of preceding elements'; - is $dom->at('script > b:last-of-type')->preceding('b')->first->tag, 'b', 'right tag'; - is $dom->at('script > b:last-of-type')->preceding('b')->size, 1, 'right number of preceding elements'; - is $dom->preceding->size, 0, 'no preceding elements'; + is $dom->at('i')->following->last->text, 'd', 'right text'; + is $dom->at('i')->following->size, 2, 'right number of following elements'; + is $dom->at('i')->following('b:last-of-type')->first->text, 'd', 'right text'; + is $dom->at('i')->following('b:last-of-type')->size, 1, 'right number of following elements'; + is $dom->following->size, 0, 'no following elements'; + is $dom->at('script > b:last-of-type')->preceding->first->tag, 'i', 'right tag'; + is $dom->at('script > b:last-of-type')->preceding->size, 2, 'right number of preceding elements'; + is $dom->at('script > b:last-of-type')->preceding('b')->first->tag, 'b', 'right tag'; + is $dom->at('script > b:last-of-type')->preceding('b')->size, 1, 'right number of preceding elements'; + is $dom->preceding->size, 0, 'no preceding elements'; is "$dom", '', 'right result'; }; subtest 'XML nodes' => sub { my $dom = Mojo::DOM->new->xml(1)->parse('test'); - ok $dom->at('b')->child_nodes->first->xml, 'XML mode active'; + ok $dom->at('b')->child_nodes->first->xml, 'XML mode active'; ok $dom->at('b')->child_nodes->first->replace('
')->child_nodes->first->xml, 'XML mode active'; is "$dom", '
', 'right result'; }; @@ -265,8 +265,8 @@ subtest 'Treating nodes as elements' => sub { is $dom->child_nodes->first->descendant_nodes->size, 0, 'no nodes'; is $dom->child_nodes->first->children->size, 0, 'no children'; is $dom->child_nodes->first->strip->parent, 'foobarbaz', 'no changes'; - is $dom->child_nodes->first->at('b'), undef, 'no result'; - is $dom->child_nodes->first->find('*')->size, 0, 'no results'; + is $dom->child_nodes->first->at('b'), undef, 'no result'; + is $dom->child_nodes->first->find('*')->size, 0, 'no results'; ok !$dom->child_nodes->first->matches('*'), 'no match'; is_deeply $dom->child_nodes->first->attr, {}, 'no attributes'; is $dom->child_nodes->first->namespace, undef, 'no namespace'; @@ -306,18 +306,18 @@ subtest 'Deep nesting (parent combinator)' => sub { EOF my $p = $dom->find('body > #container > div p[id]'); is $p->[0]->attr('id'), 'foo', 'right id attribute'; - is $p->[1], undef, 'no second result'; - is $p->size, 1, 'right number of elements'; + is $p->[1], undef, 'no second result'; + is $p->size, 1, 'right number of elements'; my @p; my @div; $dom->find('div')->each(sub { push @div, $_->attr('id') }); $dom->find('p')->each(sub { push @p, $_->attr('id') }); is_deeply \@p, [qw(foo bar)], 'found all p elements'; my $ids = [qw(container header logo buttons buttons content)]; - is_deeply \@div, $ids, 'found all div elements'; + is_deeply \@div, $ids, 'found all div elements'; is_deeply [$dom->at('p')->ancestors->map('tag')->each], [qw(div div div body html)], 'right results'; - is_deeply [$dom->at('html')->ancestors->each], [], 'no results'; - is_deeply [$dom->ancestors->each], [], 'no results'; + is_deeply [$dom->at('html')->ancestors->each], [], 'no results'; + is_deeply [$dom->ancestors->each], [], 'no results'; }; subtest 'Script tag' => sub { @@ -332,14 +332,14 @@ subtest 'HTML5 (unquoted values)' => sub { is $dom->at('#test')->text, 'works', 'right text'; is $dom->at('div')->text, 'works', 'right text'; is $dom->at('[foo=bar][foo="bar"]')->text, 'works', 'right text'; - is $dom->at('[foo="ba"]'), undef, 'no result'; - is $dom->at('[foo=bar]')->text, 'works', 'right text'; - is $dom->at('[foo=ba]'), undef, 'no result'; - is $dom->at('.tset')->text, 'works', 'right text'; - is $dom->at('[bar=/baz/]')->text, 'works', 'right text'; - is $dom->at('[baz=//]')->text, 'works', 'right text'; - is $dom->at('[value]')->text, 'works', 'right text'; - is $dom->at('[value=baz]'), undef, 'no result'; + is $dom->at('[foo="ba"]'), undef, 'no result'; + is $dom->at('[foo=bar]')->text, 'works', 'right text'; + is $dom->at('[foo=ba]'), undef, 'no result'; + is $dom->at('.tset')->text, 'works', 'right text'; + is $dom->at('[bar=/baz/]')->text, 'works', 'right text'; + is $dom->at('[baz=//]')->text, 'works', 'right text'; + is $dom->at('[value]')->text, 'works', 'right text'; + is $dom->at('[value=baz]'), undef, 'no result'; }; subtest 'HTML1 (single quotes, uppercase tags and whitespace in attributes)' => sub { @@ -347,23 +347,23 @@ subtest 'HTML1 (single quotes, uppercase tags and whitespace in attributes)' => is $dom->at('#test')->text, 'works', 'right text'; is $dom->at('div')->text, 'works', 'right text'; is $dom->at('[foo="bar"]')->text, 'works', 'right text'; - is $dom->at('[foo="ba"]'), undef, 'no result'; - is $dom->at('[foo=bar]')->text, 'works', 'right text'; - is $dom->at('[foo=ba]'), undef, 'no result'; - is $dom->at('.tset')->text, 'works', 'right text'; + is $dom->at('[foo="ba"]'), undef, 'no result'; + is $dom->at('[foo=bar]')->text, 'works', 'right text'; + is $dom->at('[foo=ba]'), undef, 'no result'; + is $dom->at('.tset')->text, 'works', 'right text'; }; subtest 'Already decoded Unicode snowman and quotes in selector' => sub { my $dom = Mojo::DOM->new('
'); - is $dom->at('[id="snow\'m\"an"]')->text, '☃', 'right text'; - is $dom->at('[id="snow\'m\22 an"]')->text, '☃', 'right text'; - is $dom->at('[id="snow\'m\000022an"]')->text, '☃', 'right text'; - is $dom->at('[id="snow\'m\22an"]'), undef, 'no result'; - is $dom->at('[id="snow\'m\21 an"]'), undef, 'no result'; - is $dom->at('[id="snow\'m\000021an"]'), undef, 'no result'; - is $dom->at('[id="snow\'m\000021 an"]'), undef, 'no result'; - is $dom->at("[id='snow\\'m\"an']")->text, '☃', 'right text'; - is $dom->at("[id='snow\\27m\"an']")->text, '☃', 'right text'; + is $dom->at('[id="snow\'m\"an"]')->text, '☃', 'right text'; + is $dom->at('[id="snow\'m\22 an"]')->text, '☃', 'right text'; + is $dom->at('[id="snow\'m\000022an"]')->text, '☃', 'right text'; + is $dom->at('[id="snow\'m\22an"]'), undef, 'no result'; + is $dom->at('[id="snow\'m\21 an"]'), undef, 'no result'; + is $dom->at('[id="snow\'m\000021an"]'), undef, 'no result'; + is $dom->at('[id="snow\'m\000021 an"]'), undef, 'no result'; + is $dom->at("[id='snow\\'m\"an']")->text, '☃', 'right text'; + is $dom->at("[id='snow\\27m\"an']")->text, '☃', 'right text'; }; subtest 'Unicode and escaped selectors' => sub { @@ -430,12 +430,12 @@ subtest 'Unicode and escaped selectors' => sub { is $dom->at('div[class~=x]')->text, 'Heart', 'right text'; is $dom->at('html div[class~=x]')->text, 'Heart', 'right text'; is $dom->at('html > div[class~=x]')->text, 'Heart', 'right text'; - is $dom->at('html'), $html, 'right result'; - is $dom->at('#☃x')->parent, $html, 'right result'; - is $dom->at('#☃x')->root, $html, 'right result'; - is $dom->children('html')->first, $html, 'right result'; - is $dom->to_string, $html, 'right result'; - is $dom->content, $html, 'right result'; + is $dom->at('html'), $html, 'right result'; + is $dom->at('#☃x')->parent, $html, 'right result'; + is $dom->at('#☃x')->root, $html, 'right result'; + is $dom->children('html')->first, $html, 'right result'; + is $dom->to_string, $html, 'right result'; + is $dom->content, $html, 'right result'; }; subtest 'Looks remotely like HTML' => sub { @@ -448,7 +448,7 @@ subtest 'Looks remotely like HTML' => sub { subtest 'Replace elements' => sub { my $dom = Mojo::DOM->new('
foo

lalala

bar
'); is $dom->at('p')->replace('bar'), '
foobarbar
', 'right result'; - is "$dom", '
foobarbar
', 'right result'; + is "$dom", '
foobarbar
', 'right result'; $dom->at('foo')->replace(Mojo::DOM->new('text')); is "$dom", '
footextbar
', 'right result'; $dom = Mojo::DOM->new('
foo
bar
'); @@ -456,13 +456,13 @@ subtest 'Replace elements' => sub { is "$dom", '

test

test

', 'right result'; $dom = Mojo::DOM->new('
foo

lalala

bar
'); is $dom->replace('♥'), '♥', 'right result'; - is "$dom", '♥', 'right result'; + is "$dom", '♥', 'right result'; $dom->replace('
foo

lalala

bar
'); - is "$dom", '
foo

lalala

bar
', 'right result'; - is $dom->at('p')->replace(''), '
foobar
', 'right result'; - is "$dom", '
foobar
', 'right result'; - is $dom->replace(''), '', 'no result'; - is "$dom", '', 'no result'; + is "$dom", '
foo

lalala

bar
', 'right result'; + is $dom->at('p')->replace(''), '
foobar
', 'right result'; + is "$dom", '
foobar
', 'right result'; + is $dom->replace(''), '', 'no result'; + is "$dom", '', 'no result'; $dom->replace('
foo

lalala

bar
'); is "$dom", '
foo

lalala

bar
', 'right result'; $dom->find('p')->map(replace => ''); @@ -472,18 +472,18 @@ subtest 'Replace elements' => sub { is "$dom", '
', 'right result'; $dom = Mojo::DOM->new('
'); $dom->at('div')->content("\x{2603}"); - is $dom->to_string, '
', 'right result'; - is $dom->at('div')->replace('

')->root, '

', 'right result'; - is $dom->to_string, '

', 'right result'; - is $dom->replace('whatever')->root, 'whatever', 'right result'; - is $dom->to_string, 'whatever', 'right result'; + is $dom->to_string, '
', 'right result'; + is $dom->at('div')->replace('

')->root, '

', 'right result'; + is $dom->to_string, '

', 'right result'; + is $dom->replace('whatever')->root, 'whatever', 'right result'; + is $dom->to_string, 'whatever', 'right result'; $dom->at('b')->prepend('

foo

')->append('

bar

'); - is "$dom", '

foo

whatever

bar

', 'right result'; - is $dom->find('p')->map('remove')->first->root->at('b')->text, 'whatever', 'right result'; - is "$dom", 'whatever', 'right result'; - is $dom->at('b')->strip, 'whatever', 'right result'; - is $dom->strip, 'whatever', 'right result'; - is $dom->remove, '', 'right result'; + is "$dom", '

foo

whatever

bar

', 'right result'; + is $dom->find('p')->map('remove')->first->root->at('b')->text, 'whatever', 'right result'; + is "$dom", 'whatever', 'right result'; + is $dom->at('b')->strip, 'whatever', 'right result'; + is $dom->strip, 'whatever', 'right result'; + is $dom->remove, '', 'right result'; $dom->replace('A
B

CDEFG

H
I'); is $dom->find(':not(div):not(i):not(u)')->map('strip')->first->root, 'A
BCDEFG
H
I', 'right result'; @@ -496,8 +496,8 @@ subtest 'Replace elements' => sub { subtest 'Replace element content' => sub { my $dom = Mojo::DOM->new('
foo

lalala

bar
'); - is $dom->at('p')->content('bar'), '

bar

', 'right result'; - is "$dom", '
foo

bar

bar
', 'right result'; + is $dom->at('p')->content('bar'), '

bar

', 'right result'; + is "$dom", '
foo

bar

bar
', 'right result'; $dom->at('p')->content(Mojo::DOM->new('text')); is "$dom", '
foo

text

bar
', 'right result'; $dom = Mojo::DOM->new('
foo
bar
'); @@ -510,14 +510,14 @@ subtest 'Replace element content' => sub { is "$dom", '

', 'right result'; $dom = Mojo::DOM->new('
foo

lalala

bar
'); $dom->content('♥'); - is "$dom", '♥', 'right result'; + is "$dom", '♥', 'right result'; is $dom->content('
foo

lalala

bar
'), '
foo

lalala

bar
', 'right result'; - is "$dom", '
foo

lalala

bar
', 'right result'; - is $dom->content(''), '', 'no result'; - is "$dom", '', 'no result'; + is "$dom", '
foo

lalala

bar
', 'right result'; + is $dom->content(''), '', 'no result'; + is "$dom", '', 'no result'; $dom->content('
foo

lalala

bar
'); - is "$dom", '
foo

lalala

bar
', 'right result'; - is $dom->at('p')->content(''), '

', 'right result'; + is "$dom", '
foo

lalala

bar
', 'right result'; + is $dom->at('p')->content(''), '

', 'right result'; }; subtest 'Mixed search and tree walk' => sub { @@ -575,15 +575,15 @@ EOF like $dom->at('#works')->text, qr/\[awesome\]\]/, 'right text'; like $dom->at('[id="works"]')->text, qr/\[awesome\]\]/, 'right text'; is $dom->find('description')->[1]->text, "\n

trololololo>\n ", 'right text'; - is $dom->at('pubDate')->text, 'Mon, 12 Jul 2010 20:42:00', 'right text'; - like $dom->at('[id*="ork"]')->text, qr/\[awesome\]\]/, 'right text'; - like $dom->at('[id*="orks"]')->text, qr/\[awesome\]\]/, 'right text'; - like $dom->at('[id*="work"]')->text, qr/\[awesome\]\]/, 'right text'; - like $dom->at('[id*="or"]')->text, qr/\[awesome\]\]/, 'right text'; - ok $dom->at('rss')->xml, 'XML mode active'; - ok $dom->at('extension')->parent->xml, 'XML mode active'; - ok $dom->at('extension')->root->xml, 'XML mode active'; - ok $dom->children('rss')->first->xml, 'XML mode active'; + is $dom->at('pubDate')->text, 'Mon, 12 Jul 2010 20:42:00', 'right text'; + like $dom->at('[id*="ork"]')->text, qr/\[awesome\]\]/, 'right text'; + like $dom->at('[id*="orks"]')->text, qr/\[awesome\]\]/, 'right text'; + like $dom->at('[id*="work"]')->text, qr/\[awesome\]\]/, 'right text'; + like $dom->at('[id*="or"]')->text, qr/\[awesome\]\]/, 'right text'; + ok $dom->at('rss')->xml, 'XML mode active'; + ok $dom->at('extension')->parent->xml, 'XML mode active'; + ok $dom->at('extension')->root->xml, 'XML mode active'; + ok $dom->children('rss')->first->xml, 'XML mode active'; ok $dom->at('title')->ancestors->first->xml, 'XML mode active'; }; @@ -604,29 +604,29 @@ subtest 'Namespace' => sub { EOF ok $dom->xml, 'XML mode detected'; - is $dom->namespace, undef, 'no namespace'; - is $dom->at('book comment')->namespace, 'uri:default-ns', 'right namespace'; - is $dom->at('book comment')->text, 'rocks!', 'right text'; - is $dom->at('book nons section')->namespace, '', 'no namespace'; - is $dom->at('book nons section')->text, 'Nothing', 'right text'; - is $dom->at('book meta number')->namespace, 'uri:isbn-ns', 'right namespace'; - is $dom->at('book meta number')->text, '978-0596000271', 'right text'; - is $dom->children('bk\:book')->first->{xmlns}, 'uri:default-ns', 'right attribute'; - is $dom->children('book')->first->{xmlns}, 'uri:default-ns', 'right attribute'; - is $dom->children('k\:book')->first, undef, 'no result'; - is $dom->children('ook')->first, undef, 'no result'; - is $dom->at('k\:book'), undef, 'no result'; - is $dom->at('ook'), undef, 'no result'; - is $dom->at('[xmlns\:bk]')->{'xmlns:bk'}, 'uri:book-ns', 'right attribute'; - is $dom->at('[bk]')->{'xmlns:bk'}, 'uri:book-ns', 'right attribute'; - is $dom->at('[bk]')->attr('xmlns:bk'), 'uri:book-ns', 'right attribute'; - is $dom->at('[bk]')->attr('s:bk'), undef, 'no attribute'; - is $dom->at('[bk]')->attr('bk'), undef, 'no attribute'; - is $dom->at('[bk]')->attr('k'), undef, 'no attribute'; - is $dom->at('[s\:bk]'), undef, 'no result'; - is $dom->at('[k]'), undef, 'no result'; - is $dom->at('number')->ancestors('meta')->first->{xmlns}, 'uri:meta-ns', 'right attribute'; - ok $dom->at('nons')->matches('book > nons'), 'element did match'; + is $dom->namespace, undef, 'no namespace'; + is $dom->at('book comment')->namespace, 'uri:default-ns', 'right namespace'; + is $dom->at('book comment')->text, 'rocks!', 'right text'; + is $dom->at('book nons section')->namespace, '', 'no namespace'; + is $dom->at('book nons section')->text, 'Nothing', 'right text'; + is $dom->at('book meta number')->namespace, 'uri:isbn-ns', 'right namespace'; + is $dom->at('book meta number')->text, '978-0596000271', 'right text'; + is $dom->children('bk\:book')->first->{xmlns}, 'uri:default-ns', 'right attribute'; + is $dom->children('book')->first->{xmlns}, 'uri:default-ns', 'right attribute'; + is $dom->children('k\:book')->first, undef, 'no result'; + is $dom->children('ook')->first, undef, 'no result'; + is $dom->at('k\:book'), undef, 'no result'; + is $dom->at('ook'), undef, 'no result'; + is $dom->at('[xmlns\:bk]')->{'xmlns:bk'}, 'uri:book-ns', 'right attribute'; + is $dom->at('[bk]')->{'xmlns:bk'}, 'uri:book-ns', 'right attribute'; + is $dom->at('[bk]')->attr('xmlns:bk'), 'uri:book-ns', 'right attribute'; + is $dom->at('[bk]')->attr('s:bk'), undef, 'no attribute'; + is $dom->at('[bk]')->attr('bk'), undef, 'no attribute'; + is $dom->at('[bk]')->attr('k'), undef, 'no attribute'; + is $dom->at('[s\:bk]'), undef, 'no result'; + is $dom->at('[k]'), undef, 'no result'; + is $dom->at('number')->ancestors('meta')->first->{xmlns}, 'uri:meta-ns', 'right attribute'; + ok $dom->at('nons')->matches('book > nons'), 'element did match'; ok !$dom->at('title')->matches('book > nons > section'), 'element did not match'; }; @@ -645,8 +645,8 @@ EOF is $dom->at('foo bar ya\.da')->text, "Second\n ", 'right text'; is $dom->at('ya\.da')->namespace, 'uri:second', 'right namespace'; is $dom->at('foo')->namespace, undef, 'no namespace'; - is $dom->at('[xml\.s]'), undef, 'no result'; - is $dom->at('b\.z'), undef, 'no result'; + is $dom->at('[xml\.s]'), undef, 'no result'; + is $dom->at('b\.z'), undef, 'no result'; }; subtest 'Yadis' => sub { @@ -668,11 +668,11 @@ EOF is $dom->at('XRD')->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; my $s = $dom->find('XRDS XRD Service'); is $s->[0]->at('Type')->text, 'http://o.r.g/sso/2.0', 'right text'; - is $s->[0]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; + is $s->[0]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; is $s->[1]->at('Type')->text, 'http://o.r.g/sso/1.0', 'right text'; - is $s->[1]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; - is $s->[2], undef, 'no result'; - is $s->size, 2, 'right number of elements'; + is $s->[1]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; + is $s->[2], undef, 'no result'; + is $s->size, 2, 'right number of elements'; }; subtest 'Yadis (roundtrip with namespace)' => sub { @@ -702,29 +702,29 @@ EOF is $dom->at('XRDS')->namespace, 'xri://$xrds', 'right namespace'; is $dom->at('XRD')->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; my $s = $dom->find('XRDS XRD Service'); - is $s->[0]->at('Type')->text, 'http://o.r.g/sso/3.0', 'right text'; - is $s->[0]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; - is $s->[1]->at('Type')->text, 'http://o.r.g/sso/4.0', 'right text'; - is $s->[1]->namespace, 'xri://$xrds', 'right namespace'; - is $s->[2]->at('Type')->text, 'http://o.r.g/sso/2.0', 'right text'; - is $s->[2]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; - is $s->[3]->at('Type')->text, 'http://o.r.g/sso/1.0', 'right text'; - is $s->[3]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; - is $s->[4], undef, 'no result'; - is $s->size, 4, 'right number of elements'; - is $dom->at('[Test="23"]')->text, 'http://o.r.g/sso/1.0', 'right text'; - is $dom->at('[test="23"]')->text, 'http://o.r.g/sso/2.0', 'right text'; - is $dom->find('xrds\:Service > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; - is $dom->find('xrds\:Service > Type')->[1], undef, 'no result'; - is $dom->find('xrds\3AService > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; - is $dom->find('xrds\3AService > Type')->[1], undef, 'no result'; - is $dom->find('xrds\3A Service > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; - is $dom->find('xrds\3A Service > Type')->[1], undef, 'no result'; - is $dom->find('xrds\00003AService > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; - is $dom->find('xrds\00003AService > Type')->[1], undef, 'no result'; + is $s->[0]->at('Type')->text, 'http://o.r.g/sso/3.0', 'right text'; + is $s->[0]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; + is $s->[1]->at('Type')->text, 'http://o.r.g/sso/4.0', 'right text'; + is $s->[1]->namespace, 'xri://$xrds', 'right namespace'; + is $s->[2]->at('Type')->text, 'http://o.r.g/sso/2.0', 'right text'; + is $s->[2]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; + is $s->[3]->at('Type')->text, 'http://o.r.g/sso/1.0', 'right text'; + is $s->[3]->namespace, 'xri://$xrd*($v*2.0)', 'right namespace'; + is $s->[4], undef, 'no result'; + is $s->size, 4, 'right number of elements'; + is $dom->at('[Test="23"]')->text, 'http://o.r.g/sso/1.0', 'right text'; + is $dom->at('[test="23"]')->text, 'http://o.r.g/sso/2.0', 'right text'; + is $dom->find('xrds\:Service > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; + is $dom->find('xrds\:Service > Type')->[1], undef, 'no result'; + is $dom->find('xrds\3AService > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; + is $dom->find('xrds\3AService > Type')->[1], undef, 'no result'; + is $dom->find('xrds\3A Service > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; + is $dom->find('xrds\3A Service > Type')->[1], undef, 'no result'; + is $dom->find('xrds\00003AService > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; + is $dom->find('xrds\00003AService > Type')->[1], undef, 'no result'; is $dom->find('xrds\00003A Service > Type')->[0]->text, 'http://o.r.g/sso/4.0', 'right text'; - is $dom->find('xrds\00003A Service > Type')->[1], undef, 'no result'; - is "$dom", $yadis, 'successful roundtrip'; + is $dom->find('xrds\00003A Service > Type')->[1], undef, 'no result'; + is "$dom", $yadis, 'successful roundtrip'; }; subtest 'Result and iterator order' => sub { @@ -744,29 +744,29 @@ subtest 'Attributes on multiple lines' => sub { subtest 'Markup characters in attribute values' => sub { my $dom = Mojo::DOM->new(qq{

Test
}); - is $dom->at('div[id=""]')->attr->{test}, '=', 'right attribute'; - is $dom->at('[id=""]')->text, 'Test', 'right text'; - is $dom->at('[id="><"]')->attr->{id}, '><', 'right attribute'; + is $dom->at('div[id=""]')->attr->{test}, '=', 'right attribute'; + is $dom->at('[id=""]')->text, 'Test', 'right text'; + is $dom->at('[id="><"]')->attr->{id}, '><', 'right attribute'; }; subtest 'Empty attributes' => sub { my $dom = Mojo::DOM->new(qq{
}); - is $dom->at('div')->attr->{test}, '', 'empty attribute value'; - is $dom->at('div')->attr->{test2}, '', 'empty attribute value'; - is $dom->at('[test]')->tag, 'div', 'right tag'; - is $dom->at('[test2]')->tag, 'div', 'right tag'; - is $dom->at('[test3]'), undef, 'no result'; - is $dom->at('[test=""]')->tag, 'div', 'right tag'; - is $dom->at('[test2=""]')->tag, 'div', 'right tag'; - is $dom->at('[test3=""]'), undef, 'no result'; + is $dom->at('div')->attr->{test}, '', 'empty attribute value'; + is $dom->at('div')->attr->{test2}, '', 'empty attribute value'; + is $dom->at('[test]')->tag, 'div', 'right tag'; + is $dom->at('[test2]')->tag, 'div', 'right tag'; + is $dom->at('[test3]'), undef, 'no result'; + is $dom->at('[test=""]')->tag, 'div', 'right tag'; + is $dom->at('[test2=""]')->tag, 'div', 'right tag'; + is $dom->at('[test3=""]'), undef, 'no result'; }; subtest 'Multi-line attribute' => sub { my $dom = Mojo::DOM->new(qq{
}); is $dom->at('div')->attr->{class}, "line1\nline2", 'multi-line attribute value'; - is $dom->at('.line1')->tag, 'div', 'right tag'; - is $dom->at('.line2')->tag, 'div', 'right tag'; - is $dom->at('.line3'), undef, 'no result'; + is $dom->at('.line1')->tag, 'div', 'right tag'; + is $dom->at('.line2')->tag, 'div', 'right tag'; + is $dom->at('.line3'), undef, 'no result'; }; subtest 'Entities in attributes' => sub { @@ -808,14 +808,14 @@ subtest 'Defined but false text' => sub { subtest 'Empty tags' => sub { my $dom = Mojo::DOM->new('



'); - is "$dom", '



', 'right result'; - is $dom->at('br')->content, '', 'empty result'; + is "$dom", '



', 'right result'; + is $dom->at('br')->content, '', 'empty result'; }; subtest 'Inner XML' => sub { my $dom = Mojo::DOM->new('
xxxxxxx'); - is $dom->at('a')->content, 'xxxxxxx', 'right result'; - is $dom->content, 'xxxxxxx', 'right result'; + is $dom->at('a')->content, 'xxxxxxx', 'right result'; + is $dom->content, 'xxxxxxx', 'right result'; }; subtest 'Multiple selectors' => sub { @@ -857,9 +857,9 @@ EOF @div = (); $dom->find('div[foo^="b"][foo$="r"]')->each(sub { push @div, shift->text }); is_deeply \@div, [qw(A B C)], 'found all div elements with the right atributes'; - is $dom->at('[foo="bar"]')->previous, undef, 'no previous sibling'; - is $dom->at('[foo="bar"]')->next->text, 'B', 'right text'; - is $dom->at('[foo="bar"]')->next->previous->text, 'A', 'right text'; + is $dom->at('[foo="bar"]')->previous, undef, 'no previous sibling'; + is $dom->at('[foo="bar"]')->next->text, 'B', 'right text'; + is $dom->at('[foo="bar"]')->next->previous->text, 'A', 'right text'; is $dom->at('[foo="bar"]')->next->next->next->next, undef, 'no next sibling'; }; @@ -884,35 +884,35 @@ subtest 'Pseudo-classes' => sub {

EOF - is $dom->find(':root')->[0]->tag, 'form', 'right tag'; - is $dom->find('*:root')->[0]->tag, 'form', 'right tag'; - is $dom->find('form:root')->[0]->tag, 'form', 'right tag'; - is $dom->find(':root')->[1], undef, 'no result'; - is $dom->find(':checked')->[0]->attr->{name}, 'groovy', 'right name'; - is $dom->find('option:checked')->[0]->attr->{value}, 'e', 'right value'; - is $dom->find(':checked')->[1]->text, 'E', 'right text'; - is $dom->find('*:checked')->[1]->text, 'E', 'right text'; - is $dom->find(':checked')->[2]->text, 'H', 'right name'; - is $dom->find(':checked')->[3]->attr->{name}, 'I', 'right name'; - is $dom->find(':checked')->[4], undef, 'no result'; - is $dom->find('option[selected]')->[0]->attr->{value}, 'e', 'right value'; - is $dom->find('option[selected]')->[1]->text, 'H', 'right text'; - is $dom->find('option[selected]')->[2], undef, 'no result'; - is $dom->find(':checked[value="e"]')->[0]->text, 'E', 'right text'; - is $dom->find('*:checked[value="e"]')->[0]->text, 'E', 'right text'; - is $dom->find('option:checked[value="e"]')->[0]->text, 'E', 'right text'; - is $dom->at('optgroup option:checked[value="e"]')->text, 'E', 'right text'; - is $dom->at('select option:checked[value="e"]')->text, 'E', 'right text'; - is $dom->at('select :checked[value="e"]')->text, 'E', 'right text'; - is $dom->at('optgroup > :checked[value="e"]')->text, 'E', 'right text'; - is $dom->at('select *:checked[value="e"]')->text, 'E', 'right text'; - is $dom->at('optgroup > *:checked[value="e"]')->text, 'E', 'right text'; - is $dom->find(':checked[value="e"]')->[1], undef, 'no result'; - is $dom->find(':empty')->[0]->attr->{name}, 'user', 'right name'; - is $dom->find('input:empty')->[0]->attr->{name}, 'user', 'right name'; - is $dom->at(':empty[type^="ch"]')->attr->{name}, 'groovy', 'right name'; - is $dom->at('p')->attr->{id}, 'content', 'right attribute'; - is $dom->at('p:empty')->attr->{id}, 'no_content', 'right attribute'; + is $dom->find(':root')->[0]->tag, 'form', 'right tag'; + is $dom->find('*:root')->[0]->tag, 'form', 'right tag'; + is $dom->find('form:root')->[0]->tag, 'form', 'right tag'; + is $dom->find(':root')->[1], undef, 'no result'; + is $dom->find(':checked')->[0]->attr->{name}, 'groovy', 'right name'; + is $dom->find('option:checked')->[0]->attr->{value}, 'e', 'right value'; + is $dom->find(':checked')->[1]->text, 'E', 'right text'; + is $dom->find('*:checked')->[1]->text, 'E', 'right text'; + is $dom->find(':checked')->[2]->text, 'H', 'right name'; + is $dom->find(':checked')->[3]->attr->{name}, 'I', 'right name'; + is $dom->find(':checked')->[4], undef, 'no result'; + is $dom->find('option[selected]')->[0]->attr->{value}, 'e', 'right value'; + is $dom->find('option[selected]')->[1]->text, 'H', 'right text'; + is $dom->find('option[selected]')->[2], undef, 'no result'; + is $dom->find(':checked[value="e"]')->[0]->text, 'E', 'right text'; + is $dom->find('*:checked[value="e"]')->[0]->text, 'E', 'right text'; + is $dom->find('option:checked[value="e"]')->[0]->text, 'E', 'right text'; + is $dom->at('optgroup option:checked[value="e"]')->text, 'E', 'right text'; + is $dom->at('select option:checked[value="e"]')->text, 'E', 'right text'; + is $dom->at('select :checked[value="e"]')->text, 'E', 'right text'; + is $dom->at('optgroup > :checked[value="e"]')->text, 'E', 'right text'; + is $dom->at('select *:checked[value="e"]')->text, 'E', 'right text'; + is $dom->at('optgroup > *:checked[value="e"]')->text, 'E', 'right text'; + is $dom->find(':checked[value="e"]')->[1], undef, 'no result'; + is $dom->find(':empty')->[0]->attr->{name}, 'user', 'right name'; + is $dom->find('input:empty')->[0]->attr->{name}, 'user', 'right name'; + is $dom->at(':empty[type^="ch"]')->attr->{name}, 'groovy', 'right name'; + is $dom->at('p')->attr->{id}, 'content', 'right attribute'; + is $dom->at('p:empty')->attr->{id}, 'no_content', 'right attribute'; }; subtest 'More pseudo-classes' => sub { @@ -937,14 +937,14 @@ EOF @li = (); $dom->find('li:nth-last-child(odd)')->each(sub { push @li, shift->text }); is_deeply \@li, [qw(B D F H)], 'found all odd li elements'; - is $dom->find(':nth-child(odd)')->[0]->tag, 'ul', 'right tag'; - is $dom->find(':nth-child(odd)')->[1]->text, 'A', 'right text'; - is $dom->find(':nth-child(1)')->[0]->tag, 'ul', 'right tag'; - is $dom->find(':nth-child(1)')->[1]->text, 'A', 'right text'; - is $dom->find(':nth-last-child(odd)')->[0]->tag, 'ul', 'right tag'; - is $dom->find(':nth-last-child(odd)')->last->text, 'H', 'right text'; - is $dom->find(':nth-last-child(1)')->[0]->tag, 'ul', 'right tag'; - is $dom->find(':nth-last-child(1)')->[1]->text, 'H', 'right text'; + is $dom->find(':nth-child(odd)')->[0]->tag, 'ul', 'right tag'; + is $dom->find(':nth-child(odd)')->[1]->text, 'A', 'right text'; + is $dom->find(':nth-child(1)')->[0]->tag, 'ul', 'right tag'; + is $dom->find(':nth-child(1)')->[1]->text, 'A', 'right text'; + is $dom->find(':nth-last-child(odd)')->[0]->tag, 'ul', 'right tag'; + is $dom->find(':nth-last-child(odd)')->last->text, 'H', 'right text'; + is $dom->find(':nth-last-child(1)')->[0]->tag, 'ul', 'right tag'; + is $dom->find(':nth-last-child(1)')->[1]->text, 'H', 'right text'; @li = (); $dom->find('li:nth-child(2n+1)')->each(sub { push @li, shift->text }); is_deeply \@li, [qw(A C E G)], 'found all odd li elements'; @@ -1208,15 +1208,15 @@ EOF is $dom->find(':any-link')->map(sub { $_->tag })->join(','), 'a,link,area', 'right tags'; is $dom->find(':link')->map(sub { $_->tag })->join(','), 'a,link,area', 'right tags'; is $dom->find(':visited')->map(sub { $_->tag })->join(','), 'a,link,area', 'right tags'; - is $dom->at('a:link')->text, 'B', 'right result'; - is $dom->at('a:any-link')->text, 'B', 'right result'; - is $dom->at('a:visited')->text, 'B', 'right result'; - is $dom->at('link:any-link')->{rel}, 'D', 'right result'; - is $dom->at('link:link')->{rel}, 'D', 'right result'; - is $dom->at('link:visited')->{rel}, 'D', 'right result'; - is $dom->at('area:link')->{alt}, 'F', 'right result'; - is $dom->at('area:any-link')->{alt}, 'F', 'right result'; - is $dom->at('area:visited')->{alt}, 'F', 'right result'; + is $dom->at('a:link')->text, 'B', 'right result'; + is $dom->at('a:any-link')->text, 'B', 'right result'; + is $dom->at('a:visited')->text, 'B', 'right result'; + is $dom->at('link:any-link')->{rel}, 'D', 'right result'; + is $dom->at('link:link')->{rel}, 'D', 'right result'; + is $dom->at('link:visited')->{rel}, 'D', 'right result'; + is $dom->at('area:link')->{alt}, 'F', 'right result'; + is $dom->at('area:any-link')->{alt}, 'F', 'right result'; + is $dom->at('area:visited')->{alt}, 'F', 'right result'; }; subtest 'Sibling combinator' => sub { @@ -1231,44 +1231,44 @@ subtest 'Sibling combinator' => sub {

FH

G
EOF - is $dom->at('li ~ p')->text, 'B', 'right text'; - is $dom->at('li + p')->text, 'B', 'right text'; - is $dom->at('h1 ~ p ~ p')->text, 'F', 'right text'; - is $dom->at('h1 + p ~ p')->text, 'F', 'right text'; - is $dom->at('h1 ~ p + p')->text, 'F', 'right text'; - is $dom->at('h1 + p + p')->text, 'F', 'right text'; - is $dom->at('h1 + p+p')->text, 'F', 'right text'; - is $dom->at('ul > li ~ li')->text, 'C', 'right text'; - is $dom->at('ul li ~ li')->text, 'C', 'right text'; - is $dom->at('ul>li~li')->text, 'C', 'right text'; - is $dom->at('ul li li'), undef, 'no result'; - is $dom->at('ul ~ li ~ li'), undef, 'no result'; - is $dom->at('ul + li ~ li'), undef, 'no result'; - is $dom->at('ul > li + li'), undef, 'no result'; - is $dom->at('h1 ~ div')->text, 'G', 'right text'; - is $dom->at('h1 + div'), undef, 'no result'; - is $dom->at('p + div')->text, 'G', 'right text'; - is $dom->at('ul + h1 + p + p + div')->text, 'G', 'right text'; - is $dom->at('ul + h1 ~ p + div')->text, 'G', 'right text'; - is $dom->at('h1 ~ #♥')->text, 'E', 'right text'; - is $dom->at('h1 + #♥')->text, 'E', 'right text'; - is $dom->at('#♥~#☃')->text, 'F', 'right text'; - is $dom->at('#♥+#☃')->text, 'F', 'right text'; - is $dom->at('#♥+#☃>b')->text, 'H', 'right text'; - is $dom->at('#♥ > #☃'), undef, 'no result'; - is $dom->at('#♥ #☃'), undef, 'no result'; - is $dom->at('#♥ + #☃ + :nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ ~ #☃ + :nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ + #☃ ~ :nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ ~ #☃ ~ :nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ + :nth-last-child(2)')->text, 'F', 'right text'; - is $dom->at('#♥ ~ :nth-last-child(2)')->text, 'F', 'right text'; - is $dom->at('#♥ + #☃ + *:nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ ~ #☃ + *:nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ + #☃ ~ *:nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ ~ #☃ ~ *:nth-last-child(1)')->text, 'G', 'right text'; - is $dom->at('#♥ + *:nth-last-child(2)')->text, 'F', 'right text'; - is $dom->at('#♥ ~ *:nth-last-child(2)')->text, 'F', 'right text'; + is $dom->at('li ~ p')->text, 'B', 'right text'; + is $dom->at('li + p')->text, 'B', 'right text'; + is $dom->at('h1 ~ p ~ p')->text, 'F', 'right text'; + is $dom->at('h1 + p ~ p')->text, 'F', 'right text'; + is $dom->at('h1 ~ p + p')->text, 'F', 'right text'; + is $dom->at('h1 + p + p')->text, 'F', 'right text'; + is $dom->at('h1 + p+p')->text, 'F', 'right text'; + is $dom->at('ul > li ~ li')->text, 'C', 'right text'; + is $dom->at('ul li ~ li')->text, 'C', 'right text'; + is $dom->at('ul>li~li')->text, 'C', 'right text'; + is $dom->at('ul li li'), undef, 'no result'; + is $dom->at('ul ~ li ~ li'), undef, 'no result'; + is $dom->at('ul + li ~ li'), undef, 'no result'; + is $dom->at('ul > li + li'), undef, 'no result'; + is $dom->at('h1 ~ div')->text, 'G', 'right text'; + is $dom->at('h1 + div'), undef, 'no result'; + is $dom->at('p + div')->text, 'G', 'right text'; + is $dom->at('ul + h1 + p + p + div')->text, 'G', 'right text'; + is $dom->at('ul + h1 ~ p + div')->text, 'G', 'right text'; + is $dom->at('h1 ~ #♥')->text, 'E', 'right text'; + is $dom->at('h1 + #♥')->text, 'E', 'right text'; + is $dom->at('#♥~#☃')->text, 'F', 'right text'; + is $dom->at('#♥+#☃')->text, 'F', 'right text'; + is $dom->at('#♥+#☃>b')->text, 'H', 'right text'; + is $dom->at('#♥ > #☃'), undef, 'no result'; + is $dom->at('#♥ #☃'), undef, 'no result'; + is $dom->at('#♥ + #☃ + :nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ ~ #☃ + :nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ + #☃ ~ :nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ ~ #☃ ~ :nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ + :nth-last-child(2)')->text, 'F', 'right text'; + is $dom->at('#♥ ~ :nth-last-child(2)')->text, 'F', 'right text'; + is $dom->at('#♥ + #☃ + *:nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ ~ #☃ + *:nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ + #☃ ~ *:nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ ~ #☃ ~ *:nth-last-child(1)')->text, 'G', 'right text'; + is $dom->at('#♥ + *:nth-last-child(2)')->text, 'F', 'right text'; + is $dom->at('#♥ ~ *:nth-last-child(2)')->text, 'F', 'right text'; }; subtest 'Scoped selectors' => sub { @@ -1286,38 +1286,38 @@ subtest 'Scoped selectors' => sub {

Five

EOF - is $dom->at('div p')->at(':scope')->text, 'One', 'right text'; - is $dom->at('div')->at(':scope p')->text, 'One', 'right text'; - is $dom->at('div')->at(':scope > p')->text, 'One', 'right text'; - is $dom->at('div')->at('> p')->text, 'One', 'right text'; - is $dom->at('div p')->at('+ p')->text, 'Two', 'right text'; - is $dom->at('div p')->at('~ p')->text, 'Two', 'right text'; - is $dom->at('div p')->at('~ p a')->text, 'Link', 'right text'; - is $dom->at('div')->at(':scope a')->text, 'Link', 'right text'; - is $dom->at('div')->at(':scope > a'), undef, 'no result'; - is $dom->at('div')->at(':scope > p > a')->text, 'Link', 'right text'; - is $dom->find('div')->last->at(':scope p')->text, 'Three', 'right text'; - is $dom->find('div')->last->at(':scope > p')->text, 'Three', 'right text'; - is $dom->find('div')->last->at('> p')->text, 'Three', 'right text'; - is $dom->at('div p')->at(':scope + p')->text, 'Two', 'right text'; - is $dom->at('div')->at(':scope > p:nth-child(2), p a')->text, 'Two', 'right text'; - is $dom->at('div')->at('p, :scope > p:nth-child(2)')->text, 'One', 'right text'; - is $dom->at('div')->at('p:not(:scope > *)')->text, 'Zero', 'right text'; - is $dom->at('div p:nth-child(2)')->at('*:is(:scope)')->text, 'Two', 'right text'; - is $dom->at('div')->at('div p, ~ p')->text, 'Five', 'right text'; - is $dom->at('> p')->text, 'Zero', 'right text'; - is $dom->at(':scope'), undef, 'no result'; - is $dom->at(':scope p')->text, 'Zero', 'right text'; - is $dom->at(':scope div p')->text, 'One', 'right text'; - is $dom->at(':scope p a')->text, 'Link', 'right text'; - is $dom->at('> p')->at('p ~ :scope'), undef, 'no result'; - is $dom->at('> p:last-child')->at('p ~ :scope')->text, 'Five', 'righ text'; - is $dom->at('p:has(+ i)')->text, 'Four', 'right text'; - is $dom->at('p:has(:scope ~ i)')->text, 'Three', 'right text'; - is $dom->at('div:has(i) p')->text, 'Three', 'right text'; - is $dom->at('div:has(> i) p')->text, 'Three', 'right text'; - is $dom->find('div:not(:has(i)) > p')->last->all_text, 'Link', 'right text'; - is $dom->find('div:has(:not(p)) > p')->last->all_text, 'Four', 'right text'; + is $dom->at('div p')->at(':scope')->text, 'One', 'right text'; + is $dom->at('div')->at(':scope p')->text, 'One', 'right text'; + is $dom->at('div')->at(':scope > p')->text, 'One', 'right text'; + is $dom->at('div')->at('> p')->text, 'One', 'right text'; + is $dom->at('div p')->at('+ p')->text, 'Two', 'right text'; + is $dom->at('div p')->at('~ p')->text, 'Two', 'right text'; + is $dom->at('div p')->at('~ p a')->text, 'Link', 'right text'; + is $dom->at('div')->at(':scope a')->text, 'Link', 'right text'; + is $dom->at('div')->at(':scope > a'), undef, 'no result'; + is $dom->at('div')->at(':scope > p > a')->text, 'Link', 'right text'; + is $dom->find('div')->last->at(':scope p')->text, 'Three', 'right text'; + is $dom->find('div')->last->at(':scope > p')->text, 'Three', 'right text'; + is $dom->find('div')->last->at('> p')->text, 'Three', 'right text'; + is $dom->at('div p')->at(':scope + p')->text, 'Two', 'right text'; + is $dom->at('div')->at(':scope > p:nth-child(2), p a')->text, 'Two', 'right text'; + is $dom->at('div')->at('p, :scope > p:nth-child(2)')->text, 'One', 'right text'; + is $dom->at('div')->at('p:not(:scope > *)')->text, 'Zero', 'right text'; + is $dom->at('div p:nth-child(2)')->at('*:is(:scope)')->text, 'Two', 'right text'; + is $dom->at('div')->at('div p, ~ p')->text, 'Five', 'right text'; + is $dom->at('> p')->text, 'Zero', 'right text'; + is $dom->at(':scope'), undef, 'no result'; + is $dom->at(':scope p')->text, 'Zero', 'right text'; + is $dom->at(':scope div p')->text, 'One', 'right text'; + is $dom->at(':scope p a')->text, 'Link', 'right text'; + is $dom->at('> p')->at('p ~ :scope'), undef, 'no result'; + is $dom->at('> p:last-child')->at('p ~ :scope')->text, 'Five', 'righ text'; + is $dom->at('p:has(+ i)')->text, 'Four', 'right text'; + is $dom->at('p:has(:scope ~ i)')->text, 'Three', 'right text'; + is $dom->at('div:has(i) p')->text, 'Three', 'right text'; + is $dom->at('div:has(> i) p')->text, 'Three', 'right text'; + is $dom->find('div:not(:has(i)) > p')->last->all_text, 'Link', 'right text'; + is $dom->find('div:has(:not(p)) > p')->last->all_text, 'Four', 'right text'; }; subtest 'Text matching' => sub { @@ -1329,10 +1329,10 @@ subtest 'Text matching' => sub {

Five SixSevenEight

EOF - is $dom->at(':text(ero)')->text, 'Zero', 'right text'; - is $dom->at(':text(Zero)')->text, 'Zero', 'right text'; - is $dom->at('p:text(Zero)')->text, 'Zero', 'right text'; - is $dom->at('div:text(Zero)'), undef, 'no result'; + is $dom->at(':text(ero)')->text, 'Zero', 'right text'; + is $dom->at(':text(Zero)')->text, 'Zero', 'right text'; + is $dom->at('p:text(Zero)')->text, 'Zero', 'right text'; + is $dom->at('div:text(Zero)'), undef, 'no result'; is $dom->at('p:text(w)')->text, 'One', 'right text'; is $dom->at(':text()')->text, 'One', 'right text'; is $dom->at(':text(Sev)')->text, 'Seven', 'right text'; @@ -1342,12 +1342,12 @@ EOF is $dom->at(':text(eight)')->all_text, 'Five SixSevenEight', 'right text'; is $dom->at(':text(/Ei.ht/)')->all_text, 'Five SixSevenEight', 'right text'; is $dom->at(':text(/(?i:ei.ht)/)')->all_text, 'Five SixSevenEight', 'right text'; - is $dom->at(':text(v) :text(x)'), undef, 'no result'; - is $dom->at('div:text(x)'), undef, 'no result'; - is $dom->at(':text(three)'), undef, 'no result'; - is $dom->at(':text(/three/)'), undef, 'no result'; - is $dom->at(':text(/zero/)'), undef, 'no result'; - is $dom->at(':text(/zero/)'), undef, 'no result'; + is $dom->at(':text(v) :text(x)'), undef, 'no result'; + is $dom->at('div:text(x)'), undef, 'no result'; + is $dom->at(':text(three)'), undef, 'no result'; + is $dom->at(':text(/three/)'), undef, 'no result'; + is $dom->at(':text(/zero/)'), undef, 'no result'; + is $dom->at(':text(/zero/)'), undef, 'no result'; }; subtest 'Adding nodes' => sub { @@ -1377,10 +1377,10 @@ EOF
D
EOF - is $dom->at('div')->text, 'A-1', 'right text'; - is $dom->at('iv'), undef, 'no result'; + is $dom->at('div')->text, 'A-1', 'right text'; + is $dom->at('iv'), undef, 'no result'; is $dom->prepend('l')->prepend('alal')->prepend('a')->type, 'root', 'right type'; - is "$dom", < 24
A-1
25
  • A
  • A1

    23

    B

    @@ -1389,7 +1389,7 @@ EOF
    D
    EOF is $dom->append('lalala')->type, 'root', 'right type'; - is "$dom", < 24
    A-1
    25
  • A
  • A1

    23

    B

    @@ -1408,7 +1408,7 @@ EOF EOF $dom->at('li')->prepend_content('A3

    A2

    ')->prepend_content('A4'); is $dom->at('li')->text, 'A4A3A', 'right text'; - is "$dom", < 24
    A-1
    works25
  • A4A3

    A2

    A
  • A1

    23

    B

    @@ -1418,7 +1418,7 @@ EOF EOF $dom->find('li')->[1]->append_content('

    C2

    C3')->append_content(' C4')->append_content('C5'); is $dom->find('li')->[1]->text, 'CC3 C4C5', 'right text'; - is "$dom", < 24
    A-1
    works25
  • A4A3

    A2

    A
  • A1

    23

    B

    @@ -1475,16 +1475,16 @@ subtest 'Optional "p" tag' => sub {

    H

    EOF - is $dom->find('div > p')->[0]->text, 'A', 'right text'; - is $dom->find('div > p')->[1]->text, "B\n ", 'right text'; - is $dom->find('div > p')->[2]->text, 'C', 'right text'; - is $dom->find('div > p')->[3]->text, 'D', 'right text'; - is $dom->find('div > p')->[4]->text, "E\n ", 'right text'; - is $dom->find('div > p')->[5]->text, "FG\n ", 'right text'; - is $dom->find('div > p')->[6]->text, "H\n", 'right text'; - is $dom->find('div > p > p')->[0], undef, 'no results'; + is $dom->find('div > p')->[0]->text, 'A', 'right text'; + is $dom->find('div > p')->[1]->text, "B\n ", 'right text'; + is $dom->find('div > p')->[2]->text, 'C', 'right text'; + is $dom->find('div > p')->[3]->text, 'D', 'right text'; + is $dom->find('div > p')->[4]->text, "E\n ", 'right text'; + is $dom->find('div > p')->[5]->text, "FG\n ", 'right text'; + is $dom->find('div > p')->[6]->text, "H\n", 'right text'; + is $dom->find('div > p > p')->[0], undef, 'no results'; is $dom->at('div > p > img')->attr->{src}, 'foo.png', 'right attribute'; - is $dom->at('div > div')->text, 'X', 'right text'; + is $dom->at('div > div')->text, 'X', 'right text'; }; subtest 'Optional "dt" and "dd" tags' => sub { @@ -1582,10 +1582,10 @@ subtest 'Optional "thead", "tbody", "tfoot", "tr", "th" and "td" tags' => sub { B EOF - is $dom->at('table > thead > tr > th')->text, 'A', 'right text'; + is $dom->at('table > thead > tr > th')->text, 'A', 'right text'; is $dom->find('table > thead > tr > th')->[1]->text, "D\n ", 'right text'; - is $dom->at('table > tbody > tr > td')->text, "B\n", 'right text'; - is $dom->at('table > tfoot > tr > td')->text, "C\n ", 'right text'; + is $dom->at('table > tbody > tr > td')->text, "B\n", 'right text'; + is $dom->at('table > tfoot > tr > td')->text, "C\n ", 'right text'; }; subtest 'Optional "colgroup", "thead", "tbody", "tr", "th" and "td" tags' => sub { @@ -1611,14 +1611,14 @@ subtest 'Optional "colgroup", "thead", "tbody", "tr", "th" and "td" tags' => sub E EOF - is $dom->find('table > col')->[0]->attr->{id}, 'morefail', 'right attribute'; - is $dom->find('table > col')->[1]->attr->{id}, 'fail', 'right attribute'; - is $dom->find('table > colgroup > col')->[0]->attr->{id}, 'foo', 'right attribute'; - is $dom->find('table > colgroup > col')->[1]->attr->{class}, 'foo', 'right attribute'; - is $dom->find('table > colgroup > col')->[2]->attr->{id}, 'bar', 'right attribute'; - is $dom->at('table > thead > tr > th')->text, 'A', 'right text'; - is $dom->find('table > thead > tr > th')->[1]->text, "D\n ", 'right text'; - is $dom->at('table > tbody > tr > td')->text, "B\n ", 'right text'; + is $dom->find('table > col')->[0]->attr->{id}, 'morefail', 'right attribute'; + is $dom->find('table > col')->[1]->attr->{id}, 'fail', 'right attribute'; + is $dom->find('table > colgroup > col')->[0]->attr->{id}, 'foo', 'right attribute'; + is $dom->find('table > colgroup > col')->[1]->attr->{class}, 'foo', 'right attribute'; + is $dom->find('table > colgroup > col')->[2]->attr->{id}, 'bar', 'right attribute'; + is $dom->at('table > thead > tr > th')->text, 'A', 'right text'; + is $dom->find('table > thead > tr > th')->[1]->text, "D\n ", 'right text'; + is $dom->at('table > tbody > tr > td')->text, "B\n ", 'right text'; is $dom->find('table > tbody > tr > td')->map('text')->join("\n"), "B\n \nE\n", 'right text'; }; @@ -1639,7 +1639,7 @@ EOF is $dom->find('table > colgroup > col')->[0]->attr->{id}, 'foo', 'right attribute'; is $dom->find('table > colgroup > col')->[1]->attr->{class}, 'foo', 'right attribute'; is $dom->find('table > colgroup > col')->[2]->attr->{id}, 'bar', 'right attribute'; - is $dom->at('table > tbody > tr > td')->text, "B\n", 'right text'; + is $dom->at('table > tbody > tr > td')->text, "B\n", 'right text'; }; subtest 'Optional "tr" and "td" tags' => sub { @@ -1735,7 +1735,7 @@ EOF is $dom->find('body > ul > li > p')->[0]->text, "\n\n ", 'no text'; is $dom->find('body > ul > li')->[1]->text, "\n Test\n \n 321\n ", 'right text'; is $dom->find('body > ul > li > p')->[1]->text, "\n ", 'no text'; - is $dom->find('body > ul > li')->[1]->all_text, "\n Test\n \n 321\n \n ", + is $dom->find('body > ul > li')->[1]->all_text, "\n Test\n \n 321\n \n ", 'right text'; is $dom->find('body > ul > li > p')->[1]->all_text, "\n ", 'no text'; is $dom->find('body > ul > li')->[2]->text, "\n Test\n 3\n 2\n 1\n ", 'right text'; @@ -1775,8 +1775,8 @@ subtest 'Real world JavaScript and CSS' => sub { < sCriPt two="23" >if (b > c) { alert('&') }< / scRiPt > Foo! EOF - is $dom->find('html > body')->[0]->text, 'Foo!', 'right text'; - is $dom->find('html > head > style')->[0]->text, "#style { foo: style(''); }", 'right text'; + is $dom->find('html > body')->[0]->text, 'Foo!', 'right text'; + is $dom->find('html > head > style')->[0]->text, "#style { foo: style(''); }", 'right text'; is $dom->find('html > head > script')->[0]->text, "\n if (a < b) {\n alert('<123>');\n }\n ", 'right text'; is $dom->find('html > head > script')->[1]->text, "if (b > c) { alert('&') }", 'right text'; @@ -1795,12 +1795,12 @@ subtest 'More real world JavaScript' => sub { Bar EOF - is $dom->at('title')->text, 'Foo', 'right text'; + is $dom->at('title')->text, 'Foo', 'right text'; is $dom->find('html > head > script')->[0]->attr('src'), '/js/one.js', 'right attribute'; is $dom->find('html > head > script')->[1]->attr('src'), '/js/two.js', 'right attribute'; is $dom->find('html > head > script')->[2]->attr('src'), '/js/three.js', 'right attribute'; - is $dom->find('html > head > script')->[2]->text, '', 'no text'; - is $dom->at('html > body')->text, 'Bar', 'right text'; + is $dom->find('html > head > script')->[2]->text, '', 'no text'; + is $dom->at('html > body')->text, 'Bar', 'right text'; }; subtest 'Even more real world JavaScript' => sub { @@ -1816,12 +1816,12 @@ subtest 'Even more real world JavaScript' => sub { Bar EOF - is $dom->at('title')->text, 'Foo', 'right text'; + is $dom->at('title')->text, 'Foo', 'right text'; is $dom->find('html > head > script')->[0]->attr('src'), '/js/one.js', 'right attribute'; is $dom->find('html > head > script')->[1]->attr('src'), '/js/two.js', 'right attribute'; is $dom->find('html > head > script')->[2]->attr('src'), '/js/three.js', 'right attribute'; - is $dom->find('html > head > script')->[2]->text, "\n ", 'no text'; - is $dom->at('html > body')->text, 'Bar', 'right text'; + is $dom->find('html > head > script')->[2]->text, "\n ", 'no text'; + is $dom->at('html > body')->text, 'Bar', 'right text'; }; subtest 'Inline DTD' => sub { @@ -1875,8 +1875,8 @@ EOF %myentities; ] ', 'right doctype'; - is $dom->at('foo')->attr->{'xml:lang'}, 'de', 'right attribute'; - is $dom->at('foo')->text, "Check!\n", 'right text'; + is $dom->at('foo')->attr->{'xml:lang'}, 'de', 'right attribute'; + is $dom->at('foo')->text, "Check!\n", 'right text'; $dom = Mojo::DOM->new(< @@ -1930,7 +1930,7 @@ subtest 'Different broken "font" block' => sub { EOF - is $dom->at('html > head > title')->text, 'Test', 'right text'; + is $dom->at('html > head > title')->text, 'Test', 'right text'; is $dom->find('html > body > font > table > tr > td')->[0]->text, 'test1', 'right text'; is $dom->find('html > body > font > table > tr > td')->[1]->text, "test2\n ", 'right text'; }; @@ -1984,17 +1984,17 @@ subtest 'And another broken "font" block' => sub { EOF - is $dom->at('html > head > title')->text, 'Test', 'right text'; + is $dom->at('html > head > title')->text, 'Test', 'right text'; is $dom->find('html body table tr > td > font')->[0]->text, 'test1', 'right text'; is $dom->find('html body table tr > td')->[1]->text, 'x1', 'right text'; is $dom->find('html body table tr > td')->[2]->text, 'test2', 'right text'; is $dom->find('html body table tr > td')->[3]->text, 'x2', 'right text'; - is $dom->find('html body table tr > td')->[5], undef, 'no result'; - is $dom->find('html body table tr > td')->size, 5, 'right number of elements'; + is $dom->find('html body table tr > td')->[5], undef, 'no result'; + is $dom->find('html body table tr > td')->size, 5, 'right number of elements'; is $dom->find('html body table tr > td > font')->[1]->text, 'test3', 'right text'; - is $dom->find('html body table tr > td > font')->[2], undef, 'no result'; - is $dom->find('html body table tr > td > font')->size, 2, 'right number of elements'; - is $dom, <find('html body table tr > td > font')->[2], undef, 'no result'; + is $dom->find('html body table tr > td > font')->size, 2, 'right number of elements'; + is $dom, < Test @@ -2028,11 +2028,11 @@ subtest 'A collection of wonderful screwups' => sub { EOF - is $dom->at('#screw-up > b')->text, '>la<>la<<>>la<', 'right text'; - is $dom->at('#screw-up .ewww > a > img')->attr('src'), '/test.png', 'right attribute'; - is $dom->find('#screw-up .ewww > a > img')->[1]->attr('src'), '/test2.png', 'right attribute'; - is $dom->find('#screw-up .ewww > a > img')->[2], undef, 'no result'; - is $dom->find('#screw-up .ewww > a > img')->size, 2, 'right number of elements'; + is $dom->at('#screw-up > b')->text, '>la<>la<<>>la<', 'right text'; + is $dom->at('#screw-up .ewww > a > img')->attr('src'), '/test.png', 'right attribute'; + is $dom->find('#screw-up .ewww > a > img')->[1]->attr('src'), '/test2.png', 'right attribute'; + is $dom->find('#screw-up .ewww > a > img')->[2], undef, 'no result'; + is $dom->find('#screw-up .ewww > a > img')->size, 2, 'right number of elements'; }; subtest 'Broken "br" tag' => sub { @@ -2051,7 +2051,7 @@ EOF is $element->tag, 'Element', 'right tag'; ok $element->xml, 'XML mode active'; $element = $dom->at('XMLTest')->children->[0]; - is $element->tag, 'Element', 'right child'; + is $element->tag, 'Element', 'right child'; is $element->parent->tag, 'XMLTest', 'right parent'; ok $element->root->xml, 'XML mode active'; $dom->replace(''); @@ -2083,8 +2083,8 @@ subtest 'Ensure XML semantics' => sub { EOF is $dom->find('table > td > tr > thead')->[0]->text, 'foo', 'right text'; is $dom->find('script > table > td > tr > thead')->[1]->text, 'bar', 'right text'; - is $dom->find('table > td > tr > thead')->[2], undef, 'no result'; - is $dom->find('table > td > tr > thead')->size, 2, 'right number of elements'; + is $dom->find('table > td > tr > thead')->[2], undef, 'no result'; + is $dom->find('table > td > tr > thead')->size, 2, 'right number of elements'; }; subtest 'Ensure XML semantics again' => sub { @@ -2100,8 +2100,8 @@ subtest 'Ensure XML semantics again' => sub { EOF is $dom->find('table > td > tr > thead')->[0]->text, 'foo', 'right text'; is $dom->find('table > td > tr > thead')->[1]->text, 'bar', 'right text'; - is $dom->find('table > td > tr > thead')->[2], undef, 'no result'; - is $dom->find('table > td > tr > thead')->size, 2, 'right number of elements'; + is $dom->find('table > td > tr > thead')->[2], undef, 'no result'; + is $dom->find('table > td > tr > thead')->size, 2, 'right number of elements'; }; subtest 'Nested tables' => sub { @@ -2150,8 +2150,8 @@ EOF $_->find('c a')->each(sub { push @results, $_->text }); }); is_deeply \@results, [qw(baz yada)], 'right results'; - is $dom->at('b')->at('a')->text, 'bar', 'right text'; - is $dom->at('c > b > a')->text, 'bar', 'right text'; + is $dom->at('b')->at('a')->text, 'bar', 'right text'; + is $dom->at('c > b > a')->text, 'bar', 'right text'; is $dom->at('b')->at('c > b > a'), undef, 'no result'; }; @@ -2169,16 +2169,16 @@ EOF is $dom->at('a')->{id}, 'one', 'right attribute'; is_deeply [sort keys %{$dom->at('a')}], ['id'], 'right attributes'; is $dom->at('a')->at('B')->text, "\n foo\n \n \n ", 'right text'; - is $dom->at('B')->{class}, 'two', 'right attribute'; + is $dom->at('B')->{class}, 'two', 'right attribute'; is_deeply [sort keys %{$dom->at('a B')}], [qw(class test)], 'right attributes'; - is $dom->find('a B c')->[0]->text, 'bar', 'right text'; - is $dom->find('a B c')->[0]{id}, 'three', 'right attribute'; + is $dom->find('a B c')->[0]->text, 'bar', 'right text'; + is $dom->find('a B c')->[0]{id}, 'three', 'right attribute'; is_deeply [sort keys %{$dom->find('a B c')->[0]}], ['id'], 'right attributes'; - is $dom->find('a B c')->[1]->text, 'baz', 'right text'; - is $dom->find('a B c')->[1]{ID}, 'four', 'right attribute'; + is $dom->find('a B c')->[1]->text, 'baz', 'right text'; + is $dom->find('a B c')->[1]{ID}, 'four', 'right attribute'; is_deeply [sort keys %{$dom->find('a B c')->[1]}], ['ID'], 'right attributes'; - is $dom->find('a B c')->[2], undef, 'no result'; - is $dom->find('a B c')->size, 2, 'right number of elements'; + is $dom->find('a B c')->[2], undef, 'no result'; + is $dom->find('a B c')->size, 2, 'right number of elements'; my @results; $dom->find('a B c')->each(sub { push @results, $_->text }); is_deeply \@results, [qw(bar baz)], 'right results'; @@ -2201,16 +2201,16 @@ EOF is $dom->at('a')->{id}, 'one', 'right attribute'; is_deeply [sort keys %{$dom->at('a')}], ['id'], 'right attributes'; is $dom->at('a')->at('b')->text, "\n foo\n \n \n ", 'right text'; - is $dom->at('b')->{class}, 'two', 'right attribute'; + is $dom->at('b')->{class}, 'two', 'right attribute'; is_deeply [sort keys %{$dom->at('a b')}], [qw(class test)], 'right attributes'; - is $dom->find('a b c')->[0]->text, 'bar', 'right text'; - is $dom->find('a b c')->[0]{id}, 'three', 'right attribute'; + is $dom->find('a b c')->[0]->text, 'bar', 'right text'; + is $dom->find('a b c')->[0]{id}, 'three', 'right attribute'; is_deeply [sort keys %{$dom->find('a b c')->[0]}], ['id'], 'right attributes'; - is $dom->find('a b c')->[1]->text, 'baz', 'right text'; - is $dom->find('a b c')->[1]{id}, 'four', 'right attribute'; + is $dom->find('a b c')->[1]->text, 'baz', 'right text'; + is $dom->find('a b c')->[1]{id}, 'four', 'right attribute'; is_deeply [sort keys %{$dom->find('a b c')->[1]}], ['id'], 'right attributes'; - is $dom->find('a b c')->[2], undef, 'no result'; - is $dom->find('a b c')->size, 2, 'right number of elements'; + is $dom->find('a b c')->[2], undef, 'no result'; + is $dom->find('a b c')->size, 2, 'right number of elements'; my @results; $dom->find('a b c')->each(sub { push @results, $_->text }); is_deeply \@results, [qw(bar baz)], 'right results'; @@ -2222,40 +2222,40 @@ EOF subtest 'Append and prepend content' => sub { my $dom = Mojo::DOM->new('Test'); $dom->at('b')->append_content(''); - is $dom->children->[0]->tag, 'a', 'right tag'; - is $dom->all_text, 'Test', 'right text'; - is $dom->at('c')->parent->tag, 'b', 'right tag'; - is $dom->at('d')->parent->tag, 'b', 'right tag'; + is $dom->children->[0]->tag, 'a', 'right tag'; + is $dom->all_text, 'Test', 'right text'; + is $dom->at('c')->parent->tag, 'b', 'right tag'; + is $dom->at('d')->parent->tag, 'b', 'right tag'; $dom->at('b')->prepend_content('Mojo'); - is $dom->at('e')->parent->tag, 'b', 'right tag'; - is $dom->all_text, 'MojoTest', 'right text'; + is $dom->at('e')->parent->tag, 'b', 'right tag'; + is $dom->all_text, 'MojoTest', 'right text'; }; subtest 'Wrap elements' => sub { my $dom = Mojo::DOM->new('Test'); - is "$dom", 'Test', 'right result'; - is $dom->wrap('')->type, 'root', 'right type'; - is "$dom", 'Test', 'no changes'; - is $dom->at('a')->wrap('')->type, 'tag', 'right type'; - is "$dom", 'Test', 'right result'; - is $dom->at('b')->strip->at('a')->wrap('A')->tag, 'a', 'right tag'; - is "$dom", 'Test', 'right result'; - is $dom->at('a')->wrap('')->tag, 'a', 'right tag'; - is "$dom", 'Test', 'right result'; - is $dom->at('a')->wrap('CDEF')->parent->tag, 'd', 'right tag'; - is "$dom", 'CDTestEF', 'right result'; + is "$dom", 'Test', 'right result'; + is $dom->wrap('')->type, 'root', 'right type'; + is "$dom", 'Test', 'no changes'; + is $dom->at('a')->wrap('')->type, 'tag', 'right type'; + is "$dom", 'Test', 'right result'; + is $dom->at('b')->strip->at('a')->wrap('A')->tag, 'a', 'right tag'; + is "$dom", 'Test', 'right result'; + is $dom->at('a')->wrap('')->tag, 'a', 'right tag'; + is "$dom", 'Test', 'right result'; + is $dom->at('a')->wrap('CDEF')->parent->tag, 'd', 'right tag'; + is "$dom", 'CDTestEF', 'right result'; }; subtest 'Wrap content' => sub { my $dom = Mojo::DOM->new('Test'); - is $dom->at('a')->wrap_content('A')->tag, 'a', 'right tag'; - is "$dom", 'Test', 'right result'; - is $dom->wrap_content('')->type, 'root', 'right type'; - is "$dom", 'Test', 'right result'; + is $dom->at('a')->wrap_content('A')->tag, 'a', 'right tag'; + is "$dom", 'Test', 'right result'; + is $dom->wrap_content('')->type, 'root', 'right type'; + is "$dom", 'Test', 'right result'; is $dom->at('b')->strip->at('a')->tag('e:a')->wrap_content('1')->tag, 'e:a', 'right tag'; - is "$dom", '1Test', 'right result'; - is $dom->at('a')->wrap_content('CDEF')->parent->type, 'root', 'right type'; - is "$dom", 'CD1TestEF', 'right result'; + is "$dom", '1Test', 'right result'; + is $dom->at('a')->wrap_content('CDEF')->parent->type, 'root', 'right type'; + is "$dom", 'CD1TestEF', 'right result'; }; subtest 'Broken "div" in "td"' => sub { @@ -2267,11 +2267,11 @@ subtest 'Broken "div" in "td"' => sub { EOF - is $dom->find('table tr td')->[0]->at('div')->{id}, 'A', 'right attribute'; - is $dom->find('table tr td')->[1]->at('div')->{id}, 'B', 'right attribute'; - is $dom->find('table tr td')->[2], undef, 'no result'; - is $dom->find('table tr td')->size, 2, 'right number of elements'; - is "$dom", <find('table tr td')->[0]->at('div')->{id}, 'A', 'right attribute'; + is $dom->find('table tr td')->[1]->at('div')->{id}, 'B', 'right attribute'; + is $dom->find('table tr td')->[2], undef, 'no result'; + is $dom->find('table tr td')->size, 2, 'right number of elements'; + is "$dom", <
    @@ -2323,24 +2323,24 @@ EOF is $dom->at('input')->val, 'A', 'right value'; is $dom->at('input:checked')->val, 'B', 'right value'; is $dom->at('input:checked[type=radio]')->val, 'C', 'right value'; - is_deeply $dom->at('select')->val, ['I', 'J'], 'right values'; - is $dom->at('select option')->val, 'F', 'right value'; - is $dom->at('select optgroup option:not([selected])')->val, 'H', 'right value'; - is $dom->find('select')->[1]->at('option')->val, 'N', 'right value'; - is $dom->find('select')->[1]->val, undef, 'no value'; - is $dom->find('select')->[2]->val, undef, 'no value'; - is $dom->find('select')->[2]->at('option')->val, 'Q', 'right value'; - is $dom->at('select[disabled]')->val, 'Y', 'right value'; - is $dom->find('select')->last->val, 'D', 'right value'; - is $dom->find('select')->last->at('option')->val, 'R', 'right value'; - is $dom->at('textarea')->val, 'M', 'right value'; - is $dom->at('button')->val, 'O', 'right value'; - is $dom->at('form')->find('input')->last->val, 'P', 'right value'; - is $dom->at('input[name=q]')->val, 'on', 'right value'; - is $dom->at('input[name=r]')->val, 'on', 'right value'; - is $dom->at('input[name=s]')->val, undef, 'no value'; - is $dom->at('input[name=t]')->val, '', 'right value'; - is $dom->at('input[name=u]')->val, undef, 'no value'; + is_deeply $dom->at('select')->val, ['I', 'J'], 'right values'; + is $dom->at('select option')->val, 'F', 'right value'; + is $dom->at('select optgroup option:not([selected])')->val, 'H', 'right value'; + is $dom->find('select')->[1]->at('option')->val, 'N', 'right value'; + is $dom->find('select')->[1]->val, undef, 'no value'; + is $dom->find('select')->[2]->val, undef, 'no value'; + is $dom->find('select')->[2]->at('option')->val, 'Q', 'right value'; + is $dom->at('select[disabled]')->val, 'Y', 'right value'; + is $dom->find('select')->last->val, 'D', 'right value'; + is $dom->find('select')->last->at('option')->val, 'R', 'right value'; + is $dom->at('textarea')->val, 'M', 'right value'; + is $dom->at('button')->val, 'O', 'right value'; + is $dom->at('form')->find('input')->last->val, 'P', 'right value'; + is $dom->at('input[name=q]')->val, 'on', 'right value'; + is $dom->at('input[name=r]')->val, 'on', 'right value'; + is $dom->at('input[name=s]')->val, undef, 'no value'; + is $dom->at('input[name=t]')->val, '', 'right value'; + is $dom->at('input[name=u]')->val, undef, 'no value'; }; subtest 'PoCo example with whitespace-sensitive text' => sub { @@ -2367,18 +2367,18 @@ Springfield, VT 12345 USA EOF - is $dom->find('entry')->[0]->at('displayName')->text, 'Homer Simpson', 'right text'; - is $dom->find('entry')->[0]->at('id')->text, '1286823', 'right text'; - is $dom->find('entry')->[0]->at('addresses')->children('type')->[0]->text, 'home', 'right text'; + is $dom->find('entry')->[0]->at('displayName')->text, 'Homer Simpson', 'right text'; + is $dom->find('entry')->[0]->at('id')->text, '1286823', 'right text'; + is $dom->find('entry')->[0]->at('addresses')->children('type')->[0]->text, 'home', 'right text'; is $dom->find('entry')->[0]->at('addresses formatted')->text, "742 Evergreen Terrace\nSpringfield, VT 12345 USA", 'right text'; - is $dom->find('entry')->[1]->at('displayName')->text, 'Marge Simpson', 'right text'; - is $dom->find('entry')->[1]->at('id')->text, '1286822', 'right text'; - is $dom->find('entry')->[1]->at('addresses')->children('type')->[0]->text, 'home', 'right text'; + is $dom->find('entry')->[1]->at('displayName')->text, 'Marge Simpson', 'right text'; + is $dom->find('entry')->[1]->at('id')->text, '1286822', 'right text'; + is $dom->find('entry')->[1]->at('addresses')->children('type')->[0]->text, 'home', 'right text'; is $dom->find('entry')->[1]->at('addresses formatted')->text, "742 Evergreen Terrace\nSpringfield, VT 12345 USA", 'right text'; - is $dom->find('entry')->[2], undef, 'no result'; - is $dom->find('entry')->size, 2, 'right number of elements'; + is $dom->find('entry')->[2], undef, 'no result'; + is $dom->find('entry')->size, 2, 'right number of elements'; }; subtest 'Find attribute with hyphen in name and value' => sub { @@ -2387,14 +2387,14 @@ subtest 'Find attribute with hyphen in name and value' => sub { EOF - is $dom->find('[http-equiv]')->[0]{content}, 'text/html', 'right attribute'; - is $dom->find('[http-equiv]')->[1], undef, 'no result'; - is $dom->find('[http-equiv="content-type"]')->[0]{content}, 'text/html', 'right attribute'; - is $dom->find('[http-equiv="content-type"]')->[1], undef, 'no result'; - is $dom->find('[http-equiv^="content-"]')->[0]{content}, 'text/html', 'right attribute'; - is $dom->find('[http-equiv^="content-"]')->[1], undef, 'no result'; + is $dom->find('[http-equiv]')->[0]{content}, 'text/html', 'right attribute'; + is $dom->find('[http-equiv]')->[1], undef, 'no result'; + is $dom->find('[http-equiv="content-type"]')->[0]{content}, 'text/html', 'right attribute'; + is $dom->find('[http-equiv="content-type"]')->[1], undef, 'no result'; + is $dom->find('[http-equiv^="content-"]')->[0]{content}, 'text/html', 'right attribute'; + is $dom->find('[http-equiv^="content-"]')->[1], undef, 'no result'; is $dom->find('head > [http-equiv$="-type"]')->[0]{content}, 'text/html', 'right attribute'; - is $dom->find('head > [http-equiv$="-type"]')->[1], undef, 'no result'; + is $dom->find('head > [http-equiv$="-type"]')->[1], undef, 'no result'; }; subtest 'Find "0" attribute value' => sub { @@ -2402,34 +2402,34 @@ subtest 'Find "0" attribute value' => sub { Zero O&gTn>e EOF - is $dom->find('a[accesskey]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey]')->[1]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey]')->[2], undef, 'no result'; - is $dom->find('a[accesskey=0]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey=0]')->[1], undef, 'no result'; - is $dom->find('a[accesskey^=0]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey^=0]')->[1], undef, 'no result'; - is $dom->find('a[accesskey$=0]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey$=0]')->[1], undef, 'no result'; - is $dom->find('a[accesskey~=0]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey~=0]')->[1], undef, 'no result'; - is $dom->find('a[accesskey*=0]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey*=0]')->[1], undef, 'no result'; - is $dom->find('a[accesskey|=0]')->[0]->text, 'Zero', 'right text'; - is $dom->find('a[accesskey|=0]')->[1], undef, 'no result'; - is $dom->find('a[accesskey=1]')->[0]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey=1]')->[1], undef, 'no result'; + is $dom->find('a[accesskey]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey]')->[1]->text, 'O&gTn>e', 'right text'; + is $dom->find('a[accesskey]')->[2], undef, 'no result'; + is $dom->find('a[accesskey=0]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey=0]')->[1], undef, 'no result'; + is $dom->find('a[accesskey^=0]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey^=0]')->[1], undef, 'no result'; + is $dom->find('a[accesskey$=0]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey$=0]')->[1], undef, 'no result'; + is $dom->find('a[accesskey~=0]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey~=0]')->[1], undef, 'no result'; + is $dom->find('a[accesskey*=0]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey*=0]')->[1], undef, 'no result'; + is $dom->find('a[accesskey|=0]')->[0]->text, 'Zero', 'right text'; + is $dom->find('a[accesskey|=0]')->[1], undef, 'no result'; + is $dom->find('a[accesskey=1]')->[0]->text, 'O&gTn>e', 'right text'; + is $dom->find('a[accesskey=1]')->[1], undef, 'no result'; is $dom->find('a[accesskey^=1]')->[0]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey^=1]')->[1], undef, 'no result'; + is $dom->find('a[accesskey^=1]')->[1], undef, 'no result'; is $dom->find('a[accesskey$=1]')->[0]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey$=1]')->[1], undef, 'no result'; + is $dom->find('a[accesskey$=1]')->[1], undef, 'no result'; is $dom->find('a[accesskey~=1]')->[0]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey~=1]')->[1], undef, 'no result'; + is $dom->find('a[accesskey~=1]')->[1], undef, 'no result'; is $dom->find('a[accesskey*=1]')->[0]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey*=1]')->[1], undef, 'no result'; + is $dom->find('a[accesskey*=1]')->[1], undef, 'no result'; is $dom->find('a[accesskey|=1]')->[0]->text, 'O&gTn>e', 'right text'; - is $dom->find('a[accesskey|=1]')->[1], undef, 'no result'; - is $dom->at('a[accesskey*="."]'), undef, 'no result'; + is $dom->find('a[accesskey|=1]')->[1], undef, 'no result'; + is $dom->at('a[accesskey*="."]'), undef, 'no result'; }; subtest 'Empty attribute value' => sub { @@ -2439,17 +2439,17 @@ subtest 'Empty attribute value' => sub {
    after EOF - is $dom->tree->[0], 'root', 'right type'; - is $dom->tree->[1][0], 'tag', 'right type'; - is $dom->tree->[1][1], 'foo', 'right tag'; + is $dom->tree->[0], 'root', 'right type'; + is $dom->tree->[1][0], 'tag', 'right type'; + is $dom->tree->[1][1], 'foo', 'right tag'; is_deeply $dom->tree->[1][2], {bar => ''}, 'right attributes'; is $dom->tree->[1][4][0], 'text', 'right type'; is $dom->tree->[1][4][1], "\n test\n", 'right text'; - is $dom->tree->[3][0], 'tag', 'right type'; - is $dom->tree->[3][1], 'bar', 'right tag'; - is $dom->tree->[3][4][0], 'text', 'right type'; - is $dom->tree->[3][4][1], 'after', 'right text'; - is "$dom", <tree->[3][0], 'tag', 'right type'; + is $dom->tree->[3][1], 'bar', 'right tag'; + is $dom->tree->[3][4][0], 'text', 'right type'; + is $dom->tree->[3][4][1], 'after', 'right text'; + is "$dom", < test @@ -2464,17 +2464,17 @@ subtest 'Case-insensitive attribute values' => sub {

    C

    D

    EOF - is $dom->find('.foo')->map('text')->join(','), 'A,B', 'right result'; - is $dom->find('.FOO')->map('text')->join(','), 'C', 'right result'; - is $dom->find('[class=foo]')->map('text')->join(','), 'A', 'right result'; - is $dom->find('[class=foo s]')->map('text')->join(','), 'A', 'right result'; - is $dom->find('[class=foo S]')->map('text')->join(','), 'A', 'right result'; - is $dom->find('[class=foo i]')->map('text')->join(','), 'A,C', 'right result'; - is $dom->find('[class="foo" i]')->map('text')->join(','), 'A,C', 'right result'; - is $dom->find('[class="foo" I]')->map('text')->join(','), 'A,C', 'right result'; - is $dom->find('[class="foo bar"]')->size, 0, 'no results'; - is $dom->find('[class="foo bar s"]')->size, 0, 'no results'; - is $dom->find('[class="foo bar S"]')->size, 0, 'no results'; + is $dom->find('.foo')->map('text')->join(','), 'A,B', 'right result'; + is $dom->find('.FOO')->map('text')->join(','), 'C', 'right result'; + is $dom->find('[class=foo]')->map('text')->join(','), 'A', 'right result'; + is $dom->find('[class=foo s]')->map('text')->join(','), 'A', 'right result'; + is $dom->find('[class=foo S]')->map('text')->join(','), 'A', 'right result'; + is $dom->find('[class=foo i]')->map('text')->join(','), 'A,C', 'right result'; + is $dom->find('[class="foo" i]')->map('text')->join(','), 'A,C', 'right result'; + is $dom->find('[class="foo" I]')->map('text')->join(','), 'A,C', 'right result'; + is $dom->find('[class="foo bar"]')->size, 0, 'no results'; + is $dom->find('[class="foo bar s"]')->size, 0, 'no results'; + is $dom->find('[class="foo bar S"]')->size, 0, 'no results'; is $dom->find('[class="foo bar" i]')->map('text')->join(','), 'B', 'right result'; is $dom->find('[class~=foo]')->map('text')->join(','), 'A,B', 'right result'; is $dom->find('[class~=foo s]')->map('text')->join(','), 'A,B', 'right result'; @@ -2523,29 +2523,29 @@ subtest 'Nested lists' => sub { EOF - is $dom->find('div > ul > li')->[0]->text, "\n A\n \n ", 'right text'; - is $dom->find('div > ul > li')->[1], undef, 'no result'; - is $dom->find('div > ul li')->[0]->text, "\n A\n \n ", 'right text'; - is $dom->find('div > ul li')->[1]->text, 'B', 'right text'; - is $dom->find('div > ul li')->[2], undef, 'no result'; - is $dom->find('div > ul ul')->[0]->text, "\n \n C\n ", 'right text'; - is $dom->find('div > ul ul')->[1], undef, 'no result'; + is $dom->find('div > ul > li')->[0]->text, "\n A\n \n ", 'right text'; + is $dom->find('div > ul > li')->[1], undef, 'no result'; + is $dom->find('div > ul li')->[0]->text, "\n A\n \n ", 'right text'; + is $dom->find('div > ul li')->[1]->text, 'B', 'right text'; + is $dom->find('div > ul li')->[2], undef, 'no result'; + is $dom->find('div > ul ul')->[0]->text, "\n \n C\n ", 'right text'; + is $dom->find('div > ul ul')->[1], undef, 'no result'; }; subtest 'Unusual order' => sub { my $dom = Mojo::DOM->new('Ok!'); - is $dom->at('a:not([href$=foo])[href^=h]')->text, 'Ok!', 'right text'; - is $dom->at('a:not([href$=example.com])[href^=h]'), undef, 'no result'; - is $dom->at('a[href^=h]#foo.bar')->text, 'Ok!', 'right text'; - is $dom->at('a[href^=h]#foo.baz'), undef, 'no result'; - is $dom->at('a[href^=h]#foo:not(b)')->text, 'Ok!', 'right text'; - is $dom->at('a[href^=h]#foo:not(a)'), undef, 'no result'; + is $dom->at('a:not([href$=foo])[href^=h]')->text, 'Ok!', 'right text'; + is $dom->at('a:not([href$=example.com])[href^=h]'), undef, 'no result'; + is $dom->at('a[href^=h]#foo.bar')->text, 'Ok!', 'right text'; + is $dom->at('a[href^=h]#foo.baz'), undef, 'no result'; + is $dom->at('a[href^=h]#foo:not(b)')->text, 'Ok!', 'right text'; + is $dom->at('a[href^=h]#foo:not(a)'), undef, 'no result'; is $dom->at('[href^=h].bar:not(b)[href$=m]#foo')->text, 'Ok!', 'right text'; - is $dom->at('[href^=h].bar:not(b)[href$=m]#bar'), undef, 'no result'; - is $dom->at(':not(b)#foo#foo')->text, 'Ok!', 'right text'; - is $dom->at(':not(b)#foo#bar'), undef, 'no result'; - is $dom->at(':not([href^=h]#foo#bar)')->text, 'Ok!', 'right text'; - is $dom->at(':not([href^=h]#foo#foo)'), undef, 'no result'; + is $dom->at('[href^=h].bar:not(b)[href$=m]#bar'), undef, 'no result'; + is $dom->at(':not(b)#foo#foo')->text, 'Ok!', 'right text'; + is $dom->at(':not(b)#foo#bar'), undef, 'no result'; + is $dom->at(':not([href^=h]#foo#bar)')->text, 'Ok!', 'right text'; + is $dom->at(':not([href^=h]#foo#foo)'), undef, 'no result'; }; subtest 'Slash between attributes' => sub { @@ -2564,10 +2564,10 @@ subtest 'Dot and hash in class and id attributes' => sub { subtest 'Extra whitespace' => sub { my $dom = Mojo::DOM->new('< span>a< /span>bc'); - is $dom->at('span')->text, 'a', 'right text'; - is $dom->at('span + b')->text, 'b', 'right text'; - is $dom->at('b + span')->text, 'c', 'right text'; - is "$dom", 'abc', 'right result'; + is $dom->at('span')->text, 'a', 'right text'; + is $dom->at('span + b')->text, 'b', 'right text'; + is $dom->at('b + span')->text, 'c', 'right text'; + is "$dom", 'abc', 'right result'; }; subtest 'Selectors with leading and trailing whitespace' => sub { @@ -2580,7 +2580,7 @@ subtest '"0"' => sub { my $dom = Mojo::DOM->new('0'); is "$dom", '0', 'right result'; $dom->append_content('☃'); - is "$dom", '0☃', 'right result'; + is "$dom", '0☃', 'right result'; is $dom->parse(''), '', 'successful roundtrip'; is $dom->parse(''), '', 'successful roundtrip'; is $dom->parse(''), '', 'successful roundtrip'; @@ -2589,11 +2589,11 @@ subtest '"0"' => sub { subtest 'Not self-closing' => sub { my $dom = Mojo::DOM->new('
    < div >
    test
    123'); - is $dom->at('div > div > pre')->text, 'test', 'right text'; - is "$dom", '
    test
    123
    ', 'right result'; + is $dom->at('div > div > pre')->text, 'test', 'right text'; + is "$dom", '
    test
    123
    ', 'right result'; $dom = Mojo::DOM->new('

    '); - is $dom->find('p > svg > circle')->size, 2, 'two circles'; - is "$dom", '

    ', 'right result'; + is $dom->find('p > svg > circle')->size, 2, 'two circles'; + is "$dom", '

    ', 'right result'; }; subtest 'Auto-close tag' => sub { @@ -2617,20 +2617,20 @@ subtest 'Auto-close scope' => sub { subtest '"image"' => sub { my $dom = Mojo::DOM->new('test'); - is $dom->at('img')->{src}, 'foo.png', 'right attribute'; - is "$dom", 'test', 'right result'; + is $dom->at('img')->{src}, 'foo.png', 'right attribute'; + is "$dom", 'test', 'right result'; }; subtest '"title"' => sub { my $dom = Mojo::DOM->new(' <p>test<'); - is $dom->at('title')->text, '

    test<', 'right text'; - is "$dom", ' <p>test<', 'right result'; + is $dom->at('title')->text, '

    test<', 'right text'; + is "$dom", ' <p>test<', 'right result'; }; subtest '"textarea"' => sub { my $dom = Mojo::DOM->new(''); - is $dom->at('textarea#a')->text, '

    test<', 'right text'; - is "$dom", '', 'right result'; + is $dom->at('textarea#a')->text, '

    test<', 'right text'; + is "$dom", '', 'right result'; }; subtest 'Comments' => sub { @@ -2655,7 +2655,7 @@ subtest 'Huge number of nested tags' => sub { my $huge = ('' x 100) . 'works' . ('' x 100); my $dom = Mojo::DOM->new($huge); is $dom->all_text, 'works', 'right text'; - is "$dom", $huge, 'right result'; + is "$dom", $huge, 'right result'; }; subtest 'Namespace' => sub { @@ -2666,9 +2666,9 @@ subtest 'Namespace' => sub { EOF my %ns = (cool => 'coolns'); - is_deeply $dom->find('cool|this', %ns)->map('text'), ['bar'], 'right result'; - is_deeply $dom->find('cool|*', %ns)->map('text'), ['bar'], 'right result'; - is_deeply $dom->find('|this', %ns)->map('text'), ['foo'], 'right result'; + is_deeply $dom->find('cool|this', %ns)->map('text'), ['bar'], 'right result'; + is_deeply $dom->find('cool|*', %ns)->map('text'), ['bar'], 'right result'; + is_deeply $dom->find('|this', %ns)->map('text'), ['foo'], 'right result'; is_deeply $dom->find('*|this', %ns)->map('text'), ['foo', 'bar'], 'right result'; ok !$dom->at('foo|*'), 'no result'; }; @@ -2752,7 +2752,7 @@ subtest 'No more content' => sub { EOF is $dom->find('body > select > option')->[0]->text, "A\n ", 'right text'; is $dom->find('body > select > option')->[1]->text, "B\n ", 'right text'; - is $dom->at('body > textarea')->text, 'C', 'right text'; + is $dom->at('body > textarea')->text, 'C', 'right text'; $dom = Mojo::DOM->new(< @@ -2766,7 +2766,7 @@ EOF EOF is $dom->find('body > select > optgroup > option')->[0]->text, "A\n ", 'right text'; is $dom->find('body > select > optgroup > option')->[1]->text, "B\n ", 'right text'; - is $dom->at('body > textarea')->text, 'C', 'right text'; + is $dom->at('body > textarea')->text, 'C', 'right text'; $dom = Mojo::DOM->new(< @@ -2779,7 +2779,7 @@ EOF EOF is $dom->find('body > ul > li')->[0]->text, "A\n ", 'right text'; is $dom->find('body > ul > li')->[1]->text, "B\n ", 'right text'; - is $dom->at('body > textarea')->text, 'C', 'right text'; + is $dom->at('body > textarea')->text, 'C', 'right text'; $dom = Mojo::DOM->new(< @@ -2792,7 +2792,7 @@ EOF EOF is $dom->find('body > dl > dd')->[0]->text, "A\n ", 'right text'; is $dom->find('body > dl > dd')->[1]->text, "B\n ", 'right text'; - is $dom->at('body > textarea')->text, 'C', 'right text'; + is $dom->at('body > textarea')->text, 'C', 'right text'; $dom = Mojo::DOM->new(< @@ -2923,7 +2923,7 @@ subtest 'Generate tags' => sub { my $dom = Mojo::DOM->new('

    Test
    '); my $br = $dom->new_tag('br'); $dom->at('div')->append_content($br)->append_content($br); - is $dom, '
    Test

    ', 'right result'; + is $dom, '
    Test

    ', 'right result'; is tag_to_html('div', id => 'foo', 'bar'), '
    bar
    ', 'right result'; }; @@ -2941,19 +2941,19 @@ subtest 'Generate selector' => sub { EOF - is $dom->selector, undef, 'not a tag'; - is $dom->at('#a')->child_nodes->first->selector, undef, 'not a tag'; - is $dom->at('#a')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(1)', 'right selector'; - is $dom->at($dom->at('#a')->selector)->text, 'A', 'right text'; - is $dom->at('#b')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(2)', 'right selector'; - is $dom->at($dom->at('#b')->selector)->text, 'B', 'right text'; - is $dom->at('#c')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(3)', 'right selector'; - is $dom->at($dom->at('#c')->selector)->text, 'C', 'right text'; - is $dom->at('#d')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(4)', 'right selector'; - is $dom->at($dom->at('#d')->selector)->text, 'D', 'right text'; + is $dom->selector, undef, 'not a tag'; + is $dom->at('#a')->child_nodes->first->selector, undef, 'not a tag'; + is $dom->at('#a')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(1)', 'right selector'; + is $dom->at($dom->at('#a')->selector)->text, 'A', 'right text'; + is $dom->at('#b')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(2)', 'right selector'; + is $dom->at($dom->at('#b')->selector)->text, 'B', 'right text'; + is $dom->at('#c')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(3)', 'right selector'; + is $dom->at($dom->at('#c')->selector)->text, 'C', 'right text'; + is $dom->at('#d')->selector, 'html:nth-child(1) > body:nth-child(2) > p:nth-child(4)', 'right selector'; + is $dom->at($dom->at('#d')->selector)->text, 'D', 'right text'; is $dom->at('title')->selector, 'html:nth-child(1) > head:nth-child(1) > title:nth-child(1)', 'right selector'; - is $dom->at($dom->at('title')->selector)->text, 'Test', 'right text'; - is $dom->at('html')->selector, 'html:nth-child(1)', 'right selector'; + is $dom->at($dom->at('title')->selector)->text, 'Test', 'right text'; + is $dom->at('html')->selector, 'html:nth-child(1)', 'right selector'; }; subtest 'Reusing partial DOM trees' => sub { @@ -2997,8 +2997,8 @@ EOF subtest 'Root pseudo-class' => sub { my $dom = Mojo::DOM->new('
    x
    '); - is $dom->find('body > :first-child > :first-child')->first->text, 'x', 'right text'; - is $dom->at(':scope:first-child'), undef, 'no result'; + is $dom->find('body > :first-child > :first-child')->first->text, 'x', 'right text'; + is $dom->at(':scope:first-child'), undef, 'no result'; }; subtest 'Unknown CSS selector' => sub { diff --git a/t/mojo/dynamic_methods.t b/t/mojo/dynamic_methods.t index 891c1461df..5af74c80c7 100644 --- a/t/mojo/dynamic_methods.t +++ b/t/mojo/dynamic_methods.t @@ -31,7 +31,7 @@ my ($called_foo, $dyn_methods); Mojo::DynamicMethods::register 'Mojo::TestDynamic', $t1->hashref, 'foo', sub { $called_foo++; $dyn_methods = $_[1] }; is $foo, \&Mojo::TestDynamic::_Dynamic::foo, 'foo not reinstalled'; ok !Mojo::TestDynamic->can('foo'), 'dynamic method is hidden'; -ok eval { $t1->foo; 1 }, 'foo called ok'; +ok eval { $t1->foo; 1 }, 'foo called ok'; cmp_ok $called_foo, '==', 1, 'called dynamic method'; ok !eval { $t2->foo; 1 }, 'error calling foo on wrong object'; diff --git a/t/mojo/eventemitter.t b/t/mojo/eventemitter.t index f875fbcd2a..2b9fb4eb74 100644 --- a/t/mojo/eventemitter.t +++ b/t/mojo/eventemitter.t @@ -43,11 +43,11 @@ subtest 'Normal event again' => sub { my $called; $e->on(test1 => sub { $called++ }); $e->emit('test1'); - is $called, 1, 'event was emitted once'; + is $called, 1, 'event was emitted once'; is scalar @{$e->subscribers('test1')}, 1, 'one subscriber'; $e->emit('test1'); $e->unsubscribe(test1 => $e->subscribers('test1')->[0]); - is $called, 2, 'event was emitted twice'; + is $called, 2, 'event was emitted twice'; is scalar @{$e->subscribers('test1')}, 0, 'no subscribers'; $e->emit('test1'); is $called, 2, 'event was not emitted again'; @@ -62,7 +62,7 @@ subtest 'One-time event' => sub { $e->unsubscribe(one_time => sub { }); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); - is $once, 1, 'event was emitted once'; + is $once, 1, 'event was emitted once'; is scalar @{$e->subscribers('one_time')}, 0, 'no subscribers'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; @@ -99,13 +99,13 @@ subtest 'Nested one-time events' => sub { ); is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); - is $once, 0, 'only first event was emitted'; + is $once, 0, 'only first event was emitted'; is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); - is $once, 0, 'only second event was emitted'; + is $once, 0, 'only second event was emitted'; is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber'; $e->emit('one_time'); - is $once, 1, 'third event was emitted'; + is $once, 1, 'third event was emitted'; is scalar @{$e->subscribers('one_time')}, 0, 'no subscribers'; $e->emit('one_time'); is $once, 1, 'event was not emitted again'; @@ -135,11 +135,11 @@ subtest 'Unsubscribe' => sub { $e->unsubscribe(foo => $e->once(foo => sub { $counter++ })); is scalar @{$e->subscribers('foo')}, 3, 'three subscribers'; $e->emit('foo')->unsubscribe(foo => $cb); - is $counter, 3, 'event was emitted three times'; + is $counter, 3, 'event was emitted three times'; is scalar @{$e->subscribers('foo')}, 2, 'two subscribers'; $e->emit('foo'); is $counter, 5, 'event was emitted two times'; - ok $e->has_subscribers('foo'), 'has subscribers'; + ok $e->has_subscribers('foo'), 'has subscribers'; ok !$e->unsubscribe('foo')->has_subscribers('foo'), 'no subscribers'; is scalar @{$e->subscribers('foo')}, 0, 'no subscribers'; $e->emit('foo'); diff --git a/t/mojo/exception.t b/t/mojo/exception.t index 7f71bd9061..0958c4b7d6 100644 --- a/t/mojo/exception.t +++ b/t/mojo/exception.t @@ -23,11 +23,11 @@ subtest 'Verbose' => sub { subtest 'Basics' => sub { my $e = Mojo::Exception->new; - is $e->message, 'Exception!', 'right message'; - is "$e", "Exception!\n", 'right message'; + is $e->message, 'Exception!', 'right message'; + is "$e", "Exception!\n", 'right message'; $e = Mojo::Exception->new('Test!'); - is $e->message, 'Test!', 'right message'; - is "$e", "Test!\n", 'right message'; + is $e->message, 'Test!', 'right message'; + is "$e", "Test!\n", 'right message'; }; subtest 'Context information' => sub { @@ -44,36 +44,36 @@ subtest 'Context information' => sub { }; my $e = $@; isa_ok $e, 'Mojo::Exception', 'right class'; - like $e->inspect, qr/^Works!/, 'right result'; - like $e->frames->[0][1], qr/exception\.t/, 'right file'; - is $e->lines_before->[0][0], $line, 'right number'; + like $e->inspect, qr/^Works!/, 'right result'; + like $e->frames->[0][1], qr/exception\.t/, 'right file'; + is $e->lines_before->[0][0], $line, 'right number'; is $e->lines_before->[0][1], ' my $line = __LINE__;', 'right line'; - is $e->lines_before->[1][0], $line + 1, 'right number'; - is $e->lines_before->[1][1], ' eval {', 'right line'; - is $e->lines_before->[2][0], $line + 2, 'right number'; + is $e->lines_before->[1][0], $line + 1, 'right number'; + is $e->lines_before->[1][1], ' eval {', 'right line'; + is $e->lines_before->[2][0], $line + 2, 'right number'; ok !$e->lines_before->[2][1], ' empty line'; - is $e->lines_before->[3][0], $line + 3, 'right number'; + is $e->lines_before->[3][0], $line + 3, 'right number'; is $e->lines_before->[3][1], ' # test', 'right line'; - is $e->lines_before->[4][0], $line + 4, 'right number'; + is $e->lines_before->[4][0], $line + 4, 'right number'; ok !$e->lines_before->[4][1], 'empty line'; - is $e->line->[0], $line + 5, 'right number'; - is $e->line->[1], " my \$wrapper = sub { Mojo::Exception->throw('Works!') };", 'right line'; - is $e->lines_after->[0][0], $line + 6, 'right number'; - is $e->lines_after->[0][1], ' $wrapper->();', 'right line'; - is $e->lines_after->[1][0], $line + 7, 'right number'; + is $e->line->[0], $line + 5, 'right number'; + is $e->line->[1], " my \$wrapper = sub { Mojo::Exception->throw('Works!') };", 'right line'; + is $e->lines_after->[0][0], $line + 6, 'right number'; + is $e->lines_after->[0][1], ' $wrapper->();', 'right line'; + is $e->lines_after->[1][0], $line + 7, 'right number'; ok !$e->lines_after->[1][1], 'empty line'; - is $e->lines_after->[2][0], $line + 8, 'right number'; + is $e->lines_after->[2][0], $line + 8, 'right number'; is $e->lines_after->[2][1], ' # test', 'right line'; - is $e->lines_after->[3][0], $line + 9, 'right number'; + is $e->lines_after->[3][0], $line + 9, 'right number'; ok !$e->lines_after->[3][1], 'empty line'; is $e->lines_after->[4][0], $line + 10, 'right number'; - is $e->lines_after->[4][1], ' };', 'right line'; + is $e->lines_after->[4][1], ' };', 'right line'; }; subtest 'Trace' => sub { sub wrapper2 { Mojo::Exception->new->trace(@_) } sub wrapper1 { wrapper2(@_) } - like wrapper1()->frames->[0][3], qr/wrapper2/, 'right subroutine'; + like wrapper1()->frames->[0][3], qr/wrapper2/, 'right subroutine'; like wrapper1(0)->frames->[0][3], qr/trace/, 'right subroutine'; like wrapper1(1)->frames->[0][3], qr/wrapper2/, 'right subroutine'; like wrapper1(2)->frames->[0][3], qr/wrapper1/, 'right subroutine'; @@ -87,13 +87,13 @@ subtest 'Inspect (UTF-8)' => sub { is_deeply $e->lines_after, [], 'no lines'; $e->inspect; is_deeply $e->lines_before->[-1], [2, 'use warnings;'], 'right line'; - is_deeply $e->line, [3, 'use utf8;'], 'right line'; - is_deeply $e->lines_after->[0], [4, ''], 'right line'; + is_deeply $e->line, [3, 'use utf8;'], 'right line'; + is_deeply $e->lines_after->[0], [4, ''], 'right line'; $e = Mojo::Exception->new("Died at $file line 4.")->inspect; - is_deeply $e->lines_before->[-1], [3, 'use utf8;'], 'right line'; - is_deeply $e->line, [4, ''], 'right line'; - is_deeply $e->lines_after->[0], [5, "my \$s = 'Über•résumé';"], 'right line'; + is_deeply $e->lines_before->[-1], [3, 'use utf8;'], 'right line'; + is_deeply $e->line, [4, ''], 'right line'; + is_deeply $e->lines_after->[0], [5, "my \$s = 'Über•résumé';"], 'right line'; $file = $file->sibling('non_utf8.txt'); $e = Mojo::Exception->new("Whatever at $file line 3."); @@ -102,12 +102,12 @@ subtest 'Inspect (UTF-8)' => sub { is_deeply $e->lines_after, [], 'no lines'; $e->inspect->inspect; is_deeply $e->lines_before->[-1], [2, 'use warnings;'], 'right line'; - is_deeply $e->line, [3, 'no utf8;'], 'right line'; - is_deeply $e->lines_after->[0], [4, ''], 'right line'; + is_deeply $e->line, [3, 'no utf8;'], 'right line'; + is_deeply $e->lines_after->[0], [4, ''], 'right line'; $e = Mojo::Exception->new("Died at $file line 4.")->inspect; - is_deeply $e->lines_before->[-1], [3, 'no utf8;'], 'right line'; - is_deeply $e->line, [4, ''], 'right line'; - is_deeply $e->lines_after->[0], [5, "my \$s = '\xDCber\x95r\xE9sum\xE9';"], 'right line'; + is_deeply $e->lines_before->[-1], [3, 'no utf8;'], 'right line'; + is_deeply $e->line, [4, ''], 'right line'; + is_deeply $e->lines_after->[0], [5, "my \$s = '\xDCber\x95r\xE9sum\xE9';"], 'right line'; }; subtest 'Context' => sub { @@ -118,8 +118,8 @@ subtest 'Context' => sub { $e = Mojo::Exception->new('Test!'); $e->frames([['Sandbox', 'template', 4], ['MyApp::Test', 'MyApp/Test.pm', 3], ['main', 'foo.pl', 4]]); $e->lines_before([[3, 'foo();']])->line([4, 'die;'])->lines_after([[5, 'bar();']]); - is $e, "Test! at template line 4.\n", 'right result'; - is $e->verbose(1), <verbose(1), < sub { is_deeply $e->lines_before, [], 'no lines'; is_deeply $e->line, [], 'no line'; is_deeply $e->lines_after, [], 'no lines'; - is $e->message, 'Exception!', 'right message'; + is $e->message, 'Exception!', 'right message'; $e = Mojo::Exception->new(undef)->inspect; is_deeply $e->lines_before, [], 'no lines'; is_deeply $e->line, [], 'no line'; is_deeply $e->lines_after, [], 'no lines'; - is $e->message, 'Exception!', 'right message'; + is $e->message, 'Exception!', 'right message'; $e = Mojo::Exception->new('')->inspect; is_deeply $e->lines_before, [], 'no lines'; is_deeply $e->line, [], 'no line'; is_deeply $e->lines_after, [], 'no lines'; - is $e->message, '', 'right message'; + is $e->message, '', 'right message'; }; subtest 'Check (string exception)' => sub { @@ -264,20 +264,20 @@ subtest 'Raise' => sub { my $err = $@; isa_ok $err, 'MyApp::X::Baz', 'is a MyApp::X::Baz'; isa_ok $err, 'Mojo::Exception', 'is a Mojo::Exception'; - like $err, qr/^test19/, 'right error'; + like $err, qr/^test19/, 'right error'; eval { raise 'MyApp::X::Baz', 'test20' }; $err = $@; isa_ok $err, 'MyApp::X::Baz', 'is a MyApp::X::Baz'; isa_ok $err, 'Mojo::Exception', 'is a Mojo::Exception'; - like $err, qr/^test20/, 'right error again'; + like $err, qr/^test20/, 'right error again'; eval { raise 'test22' }; $err = $@; isa_ok $err, 'Mojo::Exception', 'is a Mojo::Exception'; - like $err, qr/^test22/, 'right error'; + like $err, qr/^test22/, 'right error'; eval { raise 'MojoTest::X::Foo', 'test21' }; $err = $@; isa_ok $err, 'MojoTest::X::Foo', 'is a MojoTest::X::Baz'; - like $err, qr/^test21/, 'right error'; + like $err, qr/^test21/, 'right error'; eval { raise 'Mojo::Base', 'fail' }; like $@, qr/^Mojo::Base is not a Mojo::Exception subclass/, 'right error'; }; diff --git a/t/mojo/file.t b/t/mojo/file.t index 2d7e7dda6d..0dcdb4b245 100644 --- a/t/mojo/file.t +++ b/t/mojo/file.t @@ -11,9 +11,9 @@ use Mojo::Util qw(encode); subtest 'Constructor' => sub { is(Mojo::File->new, canonpath(getcwd), 'same path'); - is path(), canonpath(getcwd), 'same path'; - is path()->to_string, canonpath(getcwd), 'same path'; - is path('/foo/bar'), '/foo/bar', 'same path'; + is path(), canonpath(getcwd), 'same path'; + is path()->to_string, canonpath(getcwd), 'same path'; + is path('/foo/bar'), '/foo/bar', 'same path'; is path('foo', 'bar', 'baz'), catfile('foo', 'bar', 'baz'), 'same path'; }; @@ -32,7 +32,7 @@ subtest 'Siblings' => sub { subtest 'Array' => sub { is_deeply path('foo', 'bar')->to_array, [splitdir catfile('foo', 'bar')], 'same structure'; - is_deeply [@{path('foo', 'bar')}], [splitdir catfile('foo', 'bar')], 'same structure'; + is_deeply [@{path('foo', 'bar')}], [splitdir catfile('foo', 'bar')], 'same structure'; }; subtest 'Absolute' => sub { @@ -48,9 +48,9 @@ subtest 'Resolved' => sub { }; subtest 'basename' => sub { - is path('file.t')->to_abs->basename, basename(rel2abs 'file.t'), 'same path'; + is path('file.t')->to_abs->basename, basename(rel2abs 'file.t'), 'same path'; is path('file.t')->to_abs->basename('.t'), basename(rel2abs('file.t'), '.t'), 'same path'; - is path('file.t')->basename('.t'), basename('file.t', '.t'), 'same path'; + is path('file.t')->basename('.t'), basename('file.t', '.t'), 'same path'; }; subtest 'dirname' => sub { @@ -58,10 +58,10 @@ subtest 'dirname' => sub { }; subtest 'extname' => sub { - is path('.file.txt')->extname, 'txt', 'right extension'; - is path('file.txt')->extname, 'txt', 'right extension'; - is path('file')->extname, '', 'no extension'; - is path('.file')->extname, '', 'no extension'; + is path('.file.txt')->extname, 'txt', 'right extension'; + is path('file.txt')->extname, 'txt', 'right extension'; + is path('file')->extname, '', 'no extension'; + is path('.file')->extname, '', 'no extension'; is path('home', 'foo', 'file.txt')->extname, 'txt', 'right extension'; is path('home', 'foo', 'file.txt.gz')->extname, 'gz', 'right extension'; is path('home', 'foo', '.file.txt.gz')->extname, 'gz', 'right extension'; @@ -76,7 +76,7 @@ subtest 'Current file' => sub { subtest 'Checks' => sub { ok path(__FILE__)->to_abs->is_abs, 'path is absolute'; - ok !path('file.t')->is_abs, 'path is not absolute'; + ok !path('file.t')->is_abs, 'path is not absolute'; }; subtest 'Temporary directory' => sub { @@ -103,7 +103,7 @@ subtest 'Temporary file' => sub { my $file = tempfile(DIR => $dir); my $path = "$file"; ok -f $path, 'file exists'; - is $file->dirname, $dir, 'same directory'; + is $file->dirname, $dir, 'same directory'; is $file->spurt('test')->slurp, 'test', 'right result'; undef $file; ok !-f $path, 'file does not exist anymore'; @@ -153,7 +153,7 @@ subtest 'make_path' => sub { ok -d $subdir, 'directory exists'; my $nextdir = $dir->child('foo', 'foobar')->make_path({error => \my $error}); ok -d $nextdir, 'directory exists'; - ok $error, 'directory already existed'; + ok $error, 'directory already existed'; }; subtest 'remove' => sub { @@ -172,9 +172,9 @@ subtest 'remove_tree' => sub { is $dir->child('foo', 'bar', 'test.txt')->slurp, 'test!', 'right content'; my $subdir = $dir->child('foo', 'foobar')->make_path; ok -e $subdir->child('bar')->make_path->child('test.txt')->spurt('test'), 'file created'; - ok -d $subdir->remove_tree({keep_root => 1}), 'directory still exists'; - ok !-e $subdir->child('bar'), 'children have been removed'; - ok !-e $dir->child('foo')->remove_tree->to_string, 'directory has been removed'; + ok -d $subdir->remove_tree({keep_root => 1}), 'directory still exists'; + ok !-e $subdir->child('bar'), 'children have been removed'; + ok !-e $dir->child('foo')->remove_tree->to_string, 'directory has been removed'; }; subtest 'move_to' => sub { @@ -237,7 +237,7 @@ subtest 'lstat' => sub { subtest 'list/list_tree' => sub { is_deeply path('does_not_exist')->list->to_array, [], 'no files'; - is_deeply curfile->list->to_array, [], 'no files'; + is_deeply curfile->list->to_array, [], 'no files'; my $lib = curfile->sibling('lib', 'Mojo'); my @files = map { path($lib)->child(split /\//) } ('DeprecationTest.pm', 'LoaderException.pm', 'LoaderException2.pm', 'TestConnectProxy.pm'); @@ -253,7 +253,7 @@ subtest 'list/list_tree' => sub { is_deeply path($lib)->list({dir => 1, hidden => 1})->map('to_string')->to_array, [@hidden, @files], 'right files'; is_deeply path('does_not_exist')->list_tree->to_array, [], 'no files'; - is_deeply curfile->list_tree->to_array, [], 'no files'; + is_deeply curfile->list_tree->to_array, [], 'no files'; @files = map { path($lib)->child(split /\//) } ( 'BaseTest/Base1.pm', 'BaseTest/Base2.pm', 'BaseTest/Base3.pm', 'DeprecationTest.pm', @@ -312,13 +312,13 @@ subtest 'list/list_tree' => sub { subtest 'touch' => sub { my $dir = tempdir; my $file = $dir->child('test.txt'); - ok !-e $file, 'file does not exist'; + ok !-e $file, 'file does not exist'; ok -e $file->touch, 'file exists'; is $file->spurt('test!')->slurp, 'test!', 'right content'; - is $file->touch->slurp, 'test!', 'right content'; + is $file->touch->slurp, 'test!', 'right content'; my $future = time + 1000; utime $future, $future, $file->to_string; - is $file->stat->mtime, $future, 'right mtime'; + is $file->stat->mtime, $future, 'right mtime'; isnt $file->touch->stat->mtime, $future, 'different mtime'; }; @@ -332,8 +332,8 @@ subtest 'Dangerous paths' => sub { subtest 'I/O' => sub { my $dir = tempdir; my $file = $dir->child('test.txt')->spurt('just works!'); - is $file->slurp, 'just works!', 'right content'; - is $file->spurt('w', 'orks', ' too!')->slurp, 'works too!', 'right content'; + is $file->slurp, 'just works!', 'right content'; + is $file->spurt('w', 'orks', ' too!')->slurp, 'works too!', 'right content'; { no warnings 'redefine'; local *IO::Handle::syswrite = sub { $! = 0; 5 }; diff --git a/t/mojo/headers.t b/t/mojo/headers.t index c37ec9b47b..895f58fec5 100644 --- a/t/mojo/headers.t +++ b/t/mojo/headers.t @@ -11,30 +11,30 @@ subtest 'Basic functionality' => sub { is $headers->header('Connection'), 'close, keep-alive', 'right value'; $headers->remove('Connection'); is $headers->header('Connection'), undef, 'no value'; - is $headers->connection, undef, 'no value'; + is $headers->connection, undef, 'no value'; $headers->content_type('text/text')->content_type('text/html'); $headers->expect('continue-100'); $headers->connection('close'); - is $headers->content_type, 'text/html', 'right value'; - like $headers->to_string, qr/.*\x0d\x0a.*\x0d\x0a.*/, 'right format'; + is $headers->content_type, 'text/html', 'right value'; + like $headers->to_string, qr/.*\x0d\x0a.*\x0d\x0a.*/, 'right format'; my $hash = $headers->to_hash; is $hash->{Connection}, 'close', 'right value'; is $hash->{Expect}, 'continue-100', 'right value'; is $hash->{'Content-Type'}, 'text/html', 'right value'; $hash = $headers->to_hash(1); - is_deeply $hash->{Connection}, ['close'], 'right structure'; - is_deeply $hash->{Expect}, ['continue-100'], 'right structure'; - is_deeply $hash->{'Content-Type'}, ['text/html'], 'right structure'; + is_deeply $hash->{Connection}, ['close'], 'right structure'; + is_deeply $hash->{Expect}, ['continue-100'], 'right structure'; + is_deeply $hash->{'Content-Type'}, ['text/html'], 'right structure'; is_deeply [sort @{$headers->names}], [qw(Connection Content-Type Expect)], 'right structure'; $headers->expires('Thu, 01 Dec 1994 16:00:00 GMT'); $headers->cache_control('public'); is $headers->expires, 'Thu, 01 Dec 1994 16:00:00 GMT', 'right value'; is $headers->cache_control, 'public', 'right value'; $headers->etag('abc321'); - is $headers->etag, 'abc321', 'right value'; + is $headers->etag, 'abc321', 'right value'; is $headers->header('ETag'), $headers->etag, 'values are equal'; $headers->status('200 OK'); - is $headers->status, '200 OK', 'right value'; + is $headers->status, '200 OK', 'right value'; is $headers->header('Status'), $headers->status, 'values are equal'; }; @@ -98,9 +98,9 @@ subtest 'Common headers' => sub { is $headers->www_authenticate('foo')->www_authenticate, 'foo', 'right value'; is $headers->referrer('foo')->referrer, 'foo', 'right value'; - is $headers->referer, 'foo', 'right value'; - is $headers->referer('bar')->referer, 'bar', 'right value'; - is $headers->referrer, 'bar', 'right value'; + is $headers->referer, 'foo', 'right value'; + is $headers->referer('bar')->referer, 'bar', 'right value'; + is $headers->referrer, 'bar', 'right value'; }; subtest 'Clone' => sub { @@ -123,7 +123,7 @@ subtest 'Clone' => sub { is_deeply $clone->to_hash(1)->{Foo}, [[qw(bar baz)]], 'right structure'; $clone = $headers->clone; $headers->add(Expect => 'whatever'); - is_deeply $clone->to_hash(1), {Expect => ['100-continue']}, 'right structure'; + is_deeply $clone->to_hash(1), {Expect => ['100-continue']}, 'right structure'; is_deeply $headers->to_hash(1), {Expect => ['100-continue', 'whatever']}, 'right structure'; }; @@ -137,12 +137,12 @@ Cache-control: public Expires: Thu, 01 Dec 1994 16:00:00 GMT EOF - ok $headers->is_finished, 'parser is finished'; + ok $headers->is_finished, 'parser is finished'; is $headers->content_type, 'text/plain', 'right value'; is $headers->expect, '100-continue', 'right value'; is $headers->cache_control, 'public', 'right value'; is $headers->expires, 'Thu, 01 Dec 1994 16:00:00 GMT', 'right value'; - is $headers->header('o'), 'x', 'right value'; + is $headers->header('o'), 'x', 'right value'; }; subtest 'Parse multi-line headers' => sub { @@ -210,14 +210,14 @@ subtest 'Multiple headers with the same name' => sub { is $hash->{'X-Test2'}, 'foo', 'right value'; is $hash->{Connection}, 'a, b', 'right value'; $hash = $headers->to_hash(1); - is_deeply $hash->{'X-Test'}, [23, 24], 'right structure'; - is_deeply $hash->{'X-Test2'}, ['foo'], 'right structure'; + is_deeply $hash->{'X-Test'}, [23, 24], 'right structure'; + is_deeply $hash->{'X-Test2'}, ['foo'], 'right structure'; is_deeply $hash->{Connection}, ['a', 'b'], 'right structure'; $headers = Mojo::Headers->new->parse($headers->to_string . "\x0d\x0a\x0d\x0a"); is_deeply $headers->to_hash(1), {'X-Test' => [23, 24], 'X-Test2' => ['foo'], Connection => ['a', 'b']}, 'right structure'; - is $headers->header('X-Test'), '23, 24', 'right value'; - is $headers->connection, 'a, b', 'right value'; + is $headers->header('X-Test'), '23, 24', 'right value'; + is $headers->connection, 'a, b', 'right value'; is $headers->connection('c', 'd', 'e')->connection, 'c, d, e', 'right value'; }; @@ -226,19 +226,19 @@ subtest 'Headers in chunks' => sub { isa_ok $headers->parse(<is_finished, 'parser is not finished'; + ok !$headers->is_finished, 'parser is not finished'; ok !defined($headers->content_type), 'no value'; isa_ok $headers->parse(<is_finished, 'parser is not finished'; + ok !$headers->is_finished, 'parser is not finished'; ok !defined($headers->connection), 'no value'; isa_ok $headers->parse(<is_finished, 'parser is finished'; - is $headers->content_type, 'text/plain', 'right value'; + is $headers->content_type, 'text/plain', 'right value'; is $headers->header('X-Bender'), 'Bite my shiny, metal ass!', 'right value'; }; diff --git a/t/mojo/home.t b/t/mojo/home.t index d0e0957886..60919f7c13 100644 --- a/t/mojo/home.t +++ b/t/mojo/home.t @@ -55,9 +55,9 @@ subtest 'Current working directory' => sub { subtest 'Path generation' => sub { my $home = Mojo::Home->new(curfile->dirname); my $path = curfile->dirname; - is $home->rel_file('foo.txt'), $path->child('foo.txt'), 'right path'; - is $home->rel_file('foo/bar.txt'), $path->child('foo', 'bar.txt'), 'right path'; - is $home->rel_file('foo/bar.txt')->basename, 'bar.txt', 'right result'; + is $home->rel_file('foo.txt'), $path->child('foo.txt'), 'right path'; + is $home->rel_file('foo/bar.txt'), $path->child('foo', 'bar.txt'), 'right path'; + is $home->rel_file('foo/bar.txt')->basename, 'bar.txt', 'right result'; }; done_testing(); diff --git a/t/mojo/hypnotoad.t b/t/mojo/hypnotoad.t index 262fadd7e1..f7dd02ebcb 100644 --- a/t/mojo/hypnotoad.t +++ b/t/mojo/hypnotoad.t @@ -37,22 +37,22 @@ subtest 'Configure' => sub { $hypnotoad->configure('test'); is_deeply $hypnotoad->prefork->listen, ['http://*:8080'], 'right value'; $hypnotoad->configure('myserver'); - is $hypnotoad->prefork->accepts, 13, 'right value'; - is $hypnotoad->prefork->backlog, 43, 'right value'; - is $hypnotoad->prefork->graceful_timeout, 23, 'right value'; - is $hypnotoad->prefork->heartbeat_interval, 7, 'right value'; - is $hypnotoad->prefork->heartbeat_timeout, 9, 'right value'; - is $hypnotoad->prefork->inactivity_timeout, 5, 'right value'; - is $hypnotoad->prefork->keep_alive_timeout, 3, 'right value'; - is_deeply $hypnotoad->prefork->listen, ['http://*:8081'], 'right value'; - is $hypnotoad->prefork->max_clients, 1, 'right value'; - is $hypnotoad->prefork->max_requests, 3, 'right value'; - is $hypnotoad->prefork->pid_file, '/foo/bar.pid', 'right value'; - ok $hypnotoad->prefork->reverse_proxy, 'reverse proxy enabled'; - is $hypnotoad->prefork->spare, 4, 'right value'; + is $hypnotoad->prefork->accepts, 13, 'right value'; + is $hypnotoad->prefork->backlog, 43, 'right value'; + is $hypnotoad->prefork->graceful_timeout, 23, 'right value'; + is $hypnotoad->prefork->heartbeat_interval, 7, 'right value'; + is $hypnotoad->prefork->heartbeat_timeout, 9, 'right value'; + is $hypnotoad->prefork->inactivity_timeout, 5, 'right value'; + is $hypnotoad->prefork->keep_alive_timeout, 3, 'right value'; + is_deeply $hypnotoad->prefork->listen, ['http://*:8081'], 'right value'; + is $hypnotoad->prefork->max_clients, 1, 'right value'; + is $hypnotoad->prefork->max_requests, 3, 'right value'; + is $hypnotoad->prefork->pid_file, '/foo/bar.pid', 'right value'; + ok $hypnotoad->prefork->reverse_proxy, 'reverse proxy enabled'; + is $hypnotoad->prefork->spare, 4, 'right value'; is_deeply $hypnotoad->prefork->trusted_proxies, ['127.0.0.0/8'], 'right value'; - is $hypnotoad->prefork->workers, 7, 'right value'; - is $hypnotoad->upgrade_timeout, 45, 'right value'; + is $hypnotoad->prefork->workers, 7, 'right value'; + is $hypnotoad->upgrade_timeout, 45, 'right value'; }; subtest 'Hot deployment' => sub { @@ -226,7 +226,7 @@ EOF ok $tx->is_finished, 'transaction is finished'; ok !$tx->keep_alive, 'connection will not be kept alive'; ok !$tx->kept_alive, 'connection was not kept alive'; - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $first, 'same content'; $tx = $ua->get("http://127.0.0.1:$port1/hello"); @@ -242,7 +242,7 @@ EOF ok $tx->is_finished, 'transaction is finished'; ok !$tx->keep_alive, 'connection will not be kept alive'; ok !$tx->kept_alive, 'connection was not kept alive'; - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $second, 'same content'; }; diff --git a/t/mojo/ioloop.t b/t/mojo/ioloop.t index a53d414552..8a6ce59393 100644 --- a/t/mojo/ioloop.t +++ b/t/mojo/ioloop.t @@ -108,10 +108,10 @@ subtest 'Handle and reset' => sub { is $count, 0, 'no recurring events'; ok !Mojo::IOLoop->acceptor($id), 'acceptor has been removed'; ok !Mojo::IOLoop->stream($id2), 'stream has been removed'; - is $handle, $handle2, 'handles are equal'; + is $handle, $handle2, 'handles are equal'; isa_ok $handle, 'IO::Socket', 'right reference'; - is $reset, 1, 'reset event has been emitted once'; - is $close, 1, 'close event has been emitted once'; + is $reset, 1, 'reset event has been emitted once'; + is $close, 1, 'close event has been emitted once'; }; subtest 'Handle and reset with freeze' => sub { @@ -140,9 +140,9 @@ subtest 'Handle and reset with freeze' => sub { is $count, 0, 'no recurring events'; ok !Mojo::IOLoop->acceptor($id), 'acceptor has been removed'; ok !Mojo::IOLoop->stream($id2), 'stream has been removed'; - is $handle, $handle2, 'handles are equal'; + is $handle, $handle2, 'handles are equal'; isa_ok $handle, 'IO::Socket', 'right reference'; - is $reset, 1, 'reset event has been emitted once'; + is $reset, 1, 'reset event has been emitted once'; ok !$close, 'close event has not been emitted'; }; @@ -191,7 +191,7 @@ subtest 'Stream' => sub { ); $promise->wait; my $stream = Mojo::IOLoop::Stream->new($handle); - is $stream->timeout, 15, 'right default'; + is $stream->timeout, 15, 'right default'; is $stream->timeout(16)->timeout, 16, 'right timeout'; $id = Mojo::IOLoop->stream($stream); $stream->on(close => sub { Mojo::IOLoop->stop }); @@ -223,7 +223,7 @@ subtest 'Removed listen socket' => sub { like $ENV{MOJO_REUSE}, qr/(?:^|\,)127\.0\.0\.1:\Q$port\E:\Q$fd\E/, 'file descriptor can be reused'; $loop->start; unlike $ENV{MOJO_REUSE}, qr/(?:^|\,)127\.0\.0\.1:\Q$port\E:\Q$fd\E/, 'environment is clean'; - ok $connected, 'connected'; + ok $connected, 'connected'; ok !$loop->acceptor($id), 'acceptor has been removed'; }; @@ -294,7 +294,7 @@ subtest 'Stream throttling' => sub { is $server_before, $server_after, 'stream has been paused'; ok length($server) > length($server_after), 'stream has been resumed'; is $client, $client_after, 'stream was writable while paused'; - is $client, 'works!', 'full message has been written'; + is $client, 'works!', 'full message has been written'; is_deeply \@waiting, [6, 0], 'right buffer sizes'; }; @@ -326,7 +326,7 @@ subtest 'Graceful shutdown' => sub { $loop->timer(30 => sub { shift->stop; $err = 'failed' }); $loop->start; ok !$loop->stream($id), 'stopped gracefully'; - ok !$err, 'no error'; + ok !$err, 'no error'; is $finish, 1, 'finish event has been emitted once'; }; @@ -370,8 +370,8 @@ subtest 'Connection limit' => sub { $loop->client({port => $port} => sub { }) for 1 .. 2; $loop->timer(30 => sub { shift->stop; $err = 'failed' }); $loop->start; - ok !$err, 'no error'; - ok $accepting[0], 'accepting connections'; + ok !$err, 'no error'; + ok $accepting[0], 'accepting connections'; ok !$accepting[1], 'connection limit reached'; }; diff --git a/t/mojo/ioloop_tls.t b/t/mojo/ioloop_tls.t index 317d9bde44..aa48cb8c6a 100644 --- a/t/mojo/ioloop_tls.t +++ b/t/mojo/ioloop_tls.t @@ -111,7 +111,7 @@ is $client, 'test321', 'right content'; is $timeout, 1, 'server emitted timeout event once'; is $server_close, 1, 'server emitted close event once'; is $client_close, 1, 'client emitted close event once'; -ok $running, 'loop was running'; +ok $running, 'loop was running'; ok !$remove, 'event removed successfully'; ok !$server_err, 'no error'; @@ -140,7 +140,7 @@ Mojo::IOLoop->client( ); Mojo::IOLoop->start; ok !$server_err, 'no error'; -ok $client_err, 'has error'; +ok $client_err, 'has error'; # Invalid certificate authority (server) $loop = Mojo::IOLoop->new; @@ -166,7 +166,7 @@ $loop->client( ); $loop->start; ok !$server_err, 'no error'; -ok $client_err, 'has error'; +ok $client_err, 'has error'; # Valid client and server certificates ($running, $timeout, $server, $server_err, $server_close) = (); @@ -220,7 +220,7 @@ is $client, 'test321', 'right content'; is $timeout, 1, 'server emitted timeout event once'; is $server_close, 1, 'server emitted close event once'; is $client_close, 1, 'client emitted close event once'; -ok $running, 'loop was running'; +ok $running, 'loop was running'; ok !$server_err, 'no error'; # Invalid server certificate (unsigned) @@ -245,7 +245,7 @@ $loop->client( ); $loop->start; ok !$server_err, 'no error'; -ok $client_err, 'has error'; +ok $client_err, 'has error'; # Invalid server certificate (hostname) $loop = Mojo::IOLoop->new; @@ -270,7 +270,7 @@ $loop->client( ); $loop->start; ok !$server_err, 'no error'; -ok $client_err, 'has error'; +ok $client_err, 'has error'; # Invalid certificate authority (client) $loop = Mojo::IOLoop->new; @@ -294,7 +294,7 @@ $loop->client( ); $loop->start; ok !$server_err, 'no error'; -ok $client_err, 'has error'; +ok $client_err, 'has error'; # Ignore invalid client certificate $loop = Mojo::IOLoop->new; diff --git a/t/mojo/json.t b/t/mojo/json.t index 723f569ec7..f5f324a6c3 100644 --- a/t/mojo/json.t +++ b/t/mojo/json.t @@ -122,16 +122,16 @@ subtest 'Decode full spec example' => sub { } } EOF - is $hash->{Image}{Width}, 800, 'right value'; - is $hash->{Image}{Height}, 600, 'right value'; - is $hash->{Image}{Title}, 'View from 15th Floor', 'right value'; + is $hash->{Image}{Width}, 800, 'right value'; + is $hash->{Image}{Height}, 600, 'right value'; + is $hash->{Image}{Title}, 'View from 15th Floor', 'right value'; is $hash->{Image}{Thumbnail}{Url}, 'http://www.example.com/image/481989943', 'right value'; is $hash->{Image}{Thumbnail}{Height}, 125, 'right value'; is $hash->{Image}{Thumbnail}{Width}, 100, 'right value'; - is $hash->{Image}{IDs}[0], 116, 'right value'; - is $hash->{Image}{IDs}[1], 943, 'right value'; - is $hash->{Image}{IDs}[2], 234, 'right value'; - is $hash->{Image}{IDs}[3], 38793, 'right value'; + is $hash->{Image}{IDs}[0], 116, 'right value'; + is $hash->{Image}{IDs}[1], 943, 'right value'; + is $hash->{Image}{IDs}[2], 234, 'right value'; + is $hash->{Image}{IDs}[3], 38793, 'right value'; }; subtest 'Encode array' => sub { @@ -293,10 +293,10 @@ subtest 'Boolean shortcut' => sub { subtest 'Booleans in different contexts' => sub { ok true, 'true'; - is true, 1, 'right string value'; + is true, 1, 'right string value'; is true + 0, 1, 'right numeric value'; ok !false, 'false'; - is false, 0, 'right string value'; + is false, 0, 'right string value'; is false + 0, 0, 'right numeric value'; }; @@ -335,7 +335,7 @@ subtest 'Ensure numbers and strings are not upgraded' => sub { }; subtest '"inf" and "nan"' => sub { - like encode_json({test => 9**9**9}), qr/^{"test":".*"}$/, 'encode "inf" as string'; + like encode_json({test => 9**9**9}), qr/^{"test":".*"}$/, 'encode "inf" as string'; like encode_json({test => -sin(9**9**9)}), qr/^{"test":".*"}$/, 'encode "nan" as string'; }; diff --git a/t/mojo/json_pointer.t b/t/mojo/json_pointer.t index 9de35ead76..f141bed5fe 100644 --- a/t/mojo/json_pointer.t +++ b/t/mojo/json_pointer.t @@ -5,26 +5,26 @@ use Mojo::JSON::Pointer; subtest '"contains" (hash)' => sub { my $pointer = Mojo::JSON::Pointer->new({foo => 23, '' => 24}); - ok $pointer->contains(''), 'contains ""'; - ok $pointer->contains('/'), 'contains "/"'; - ok $pointer->contains('/foo'), 'contains "/foo"'; - ok !$pointer->contains('foo'), '"foo" is invalid'; - ok !$pointer->contains('/bar'), 'does not contains "/bar"'; + ok $pointer->contains(''), 'contains ""'; + ok $pointer->contains('/'), 'contains "/"'; + ok $pointer->contains('/foo'), 'contains "/foo"'; + ok !$pointer->contains('foo'), '"foo" is invalid'; + ok !$pointer->contains('/bar'), 'does not contains "/bar"'; ok $pointer->new({foo => {bar => undef}})->contains('/foo/bar'), 'contains "/foo/bar"'; }; subtest '"contains" (string)' => sub { my $pointer = Mojo::JSON::Pointer->new('works'); - ok $pointer->contains(''), 'contains ""'; - ok !$pointer->contains('/'), 'does not contain "/"'; - ok !$pointer->contains('/foo'), 'does not contain "/foo"'; + ok $pointer->contains(''), 'contains ""'; + ok !$pointer->contains('/'), 'does not contain "/"'; + ok !$pointer->contains('/foo'), 'does not contain "/foo"'; ok $pointer->new('0')->contains(''), 'contains ""'; }; subtest '"contains" (mixed)' => sub { my $pointer = Mojo::JSON::Pointer->new({foo => [0, 1, 2]}); - ok $pointer->contains(''), 'contains ""'; - ok $pointer->contains('/foo/0'), 'contains "/foo/0"'; + ok $pointer->contains(''), 'contains ""'; + ok $pointer->contains('/foo/0'), 'contains "/foo/0"'; ok !$pointer->contains('/foo/9'), 'does not contain "/foo/9"'; ok !$pointer->contains('/foo/bar'), 'does not contain "/foo/bar"'; ok !$pointer->contains('/0'), 'does not contain "/0"'; @@ -34,21 +34,21 @@ subtest '"contains" (mixed)' => sub { subtest '"get" (hash)' => sub { my $pointer = Mojo::JSON::Pointer->new({foo => 'bar', '' => 'baz'}); is_deeply $pointer->get(''), {foo => 'bar', '' => 'baz'}, '"" is "{foo => "bar", "" => "baz"}"'; - is $pointer->get('/'), 'baz', '"/" is "baz"'; - is $pointer->get('/foo'), 'bar', '"/foo" is "bar"'; - is $pointer->get('foo'), undef, '"foo" is invalid'; - is $pointer->new({foo => {bar => 42}})->get('/foo/bar'), 42, '"/foo/bar" is "42"'; + is $pointer->get('/'), 'baz', '"/" is "baz"'; + is $pointer->get('/foo'), 'bar', '"/foo" is "bar"'; + is $pointer->get('foo'), undef, '"foo" is invalid'; + is $pointer->new({foo => {bar => 42}})->get('/foo/bar'), 42, '"/foo/bar" is "42"'; is_deeply $pointer->new({foo => {23 => {baz => 0}}})->get('/foo/23'), {baz => 0}, '"/foo/23" is "{baz => 0}"'; - is $pointer->new({foo => {'' => 42}})->get('/foo/'), 42, '"/foo/" is "42"'; + is $pointer->new({foo => {'' => 42}})->get('/foo/'), 42, '"/foo/" is "42"'; is $pointer->new({foo => {'' => {'' => 42}}})->get('/foo//'), 42, '"/foo//" is "42"'; }; subtest '"get" (string)' => sub { my $pointer = Mojo::JSON::Pointer->new('works'); - is $pointer->get(''), 'works', '"" is "works"'; - is $pointer->get('/'), undef, '"/" is undef'; - is $pointer->get('/foo'), undef, '"/foo" is undef'; - is $pointer->new('0')->get(''), 0, '"/foo" is "0"'; + is $pointer->get(''), 'works', '"" is "works"'; + is $pointer->get('/'), undef, '"/" is undef'; + is $pointer->get('/foo'), undef, '"/foo" is undef'; + is $pointer->new('0')->get(''), 0, '"/foo" is "0"'; }; subtest '"get" (mixed)' => sub { @@ -73,7 +73,7 @@ subtest '"get" (encoded)' => sub { subtest 'Unicode' => sub { my $pointer = Mojo::JSON::Pointer->new; - is $pointer->new({'☃' => 'snowman'})->get('/☃'), 'snowman', 'found the snowman'; + is $pointer->new({'☃' => 'snowman'})->get('/☃'), 'snowman', 'found the snowman'; is $pointer->new->data({'☃' => ['snowman']})->get('/☃/0'), 'snowman', 'found the snowman'; }; @@ -91,18 +91,18 @@ subtest 'RFC 6901' => sub { 'm~n' => 8 }; my $pointer = Mojo::JSON::Pointer->new($hash); - is_deeply $pointer->get(''), $hash, 'empty pointer is whole document'; + is_deeply $pointer->get(''), $hash, 'empty pointer is whole document'; is_deeply $pointer->get('/foo'), ['bar', 'baz'], '"/foo" is "["bar", "baz"]"'; - is $pointer->get('/foo/0'), 'bar', '"/foo/0" is "bar"'; - is $pointer->get('/'), 0, '"/" is 0'; - is $pointer->get('/a~1b'), 1, '"/a~1b" is 1'; - is $pointer->get('/c%d'), 2, '"/c%d" is 2'; - is $pointer->get('/e^f'), 3, '"/e^f" is 3'; - is $pointer->get('/g|h'), 4, '"/g|h" is 4'; - is $pointer->get('/i\\j'), 5, '"/i\\\\j" is 5'; - is $pointer->get('/k"l'), 6, '"/k\\"l" is 6'; - is $pointer->get('/ '), 7, '"/ " is 7'; - is $pointer->get('/m~0n'), 8, '"/m~0n" is 8'; + is $pointer->get('/foo/0'), 'bar', '"/foo/0" is "bar"'; + is $pointer->get('/'), 0, '"/" is 0'; + is $pointer->get('/a~1b'), 1, '"/a~1b" is 1'; + is $pointer->get('/c%d'), 2, '"/c%d" is 2'; + is $pointer->get('/e^f'), 3, '"/e^f" is 3'; + is $pointer->get('/g|h'), 4, '"/g|h" is 4'; + is $pointer->get('/i\\j'), 5, '"/i\\\\j" is 5'; + is $pointer->get('/k"l'), 6, '"/k\\"l" is 6'; + is $pointer->get('/ '), 7, '"/ " is 7'; + is $pointer->get('/m~0n'), 8, '"/m~0n" is 8'; }; done_testing(); diff --git a/t/mojo/json_xs.t b/t/mojo/json_xs.t index c6ffeecfea..12a738b097 100644 --- a/t/mojo/json_xs.t +++ b/t/mojo/json_xs.t @@ -31,7 +31,7 @@ subtest 'Basics' => sub { $array = j('[]'); is_deeply $array, [], 'j() decode'; $bytes = j([]); - is $bytes, '[]', 'j() encode'; + is $bytes, '[]', 'j() encode'; is encode_json([true]), '[true]', 'true'; is encode_json([false]), '[false]', 'false'; }; @@ -67,7 +67,7 @@ subtest '"convert_blessed"' => sub { }; subtest '"stringify_infnan"' => sub { - like encode_json({test => 9**9**9}), qr/^{"test":".*"}$/, 'encode "inf" as string'; + like encode_json({test => 9**9**9}), qr/^{"test":".*"}$/, 'encode "inf" as string'; like encode_json({test => -sin(9**9**9)}), qr/^{"test":".*"}$/, 'encode "nan" as string'; }; diff --git a/t/mojo/loader.t b/t/mojo/loader.t index ae300f236e..6dd9df47b8 100644 --- a/t/mojo/loader.t +++ b/t/mojo/loader.t @@ -16,7 +16,7 @@ package MyLoaderTest::Foo::Baz; package main; subtest 'Single character core module' => sub { - ok !load_class('B'), 'loaded'; + ok !load_class('B'), 'loaded'; ok !!UNIVERSAL::can(B => 'svref_2object'), 'method found'; }; @@ -34,8 +34,8 @@ subtest 'Exception' => sub { is $e->lines_before->[3][1], 'foo {', 'right line'; is $e->lines_before->[4][0], 8, 'right number'; is $e->lines_before->[4][1], '', 'right line'; - is $e->line->[0], 9, 'right number'; - is $e->line->[1], "1;", 'right line'; + is $e->line->[0], 9, 'right number'; + is $e->line->[1], "1;", 'right line'; like "$e", qr/Missing right curly/, 'right message'; }; @@ -43,18 +43,18 @@ subtest 'Complicated exception' => sub { my $e = load_class 'Mojo::LoaderException2'; isa_ok $e, 'Mojo::Exception', 'right exception'; like $e->message, qr/Exception/, 'right message'; - is $e->lines_before->[0][0], 1, 'right number'; - is $e->lines_before->[0][1], 'package Mojo::LoaderException2;', 'right line'; - is $e->lines_before->[1][0], 2, 'right number'; - is $e->lines_before->[1][1], 'use Mojo::Base -strict;', 'right line'; - is $e->lines_before->[2][0], 3, 'right number'; - is $e->lines_before->[2][1], '', 'right line'; - is $e->line->[0], 4, 'right number'; - is $e->line->[1], 'Mojo::LoaderException2_2::throw_error();', 'right line'; - is $e->lines_after->[0][0], 5, 'right number'; - is $e->lines_after->[0][1], '', 'right line'; - is $e->lines_after->[1][0], 6, 'right number'; - is $e->lines_after->[1][1], '1;', 'right line'; + is $e->lines_before->[0][0], 1, 'right number'; + is $e->lines_before->[0][1], 'package Mojo::LoaderException2;', 'right line'; + is $e->lines_before->[1][0], 2, 'right number'; + is $e->lines_before->[1][1], 'use Mojo::Base -strict;', 'right line'; + is $e->lines_before->[2][0], 3, 'right number'; + is $e->lines_before->[2][1], '', 'right line'; + is $e->line->[0], 4, 'right number'; + is $e->line->[1], 'Mojo::LoaderException2_2::throw_error();', 'right line'; + is $e->lines_after->[0][0], 5, 'right number'; + is $e->lines_after->[0][1], '', 'right line'; + is $e->lines_after->[1][0], 6, 'right number'; + is $e->lines_after->[1][1], '1;', 'right line'; like "$e", qr/Exception/, 'right message'; }; @@ -65,14 +65,14 @@ subtest 'Search modules' => sub { is_deeply [find_modules 'Mojo::LoaderTest', {recursive => 1}], [qw(Mojo::LoaderTest::A Mojo::LoaderTest::B Mojo::LoaderTest::C Mojo::LoaderTest::E::F)], 'found the right modules'; - is_deeply [find_modules 'MyLoaderTest::DoesNotExist'], [], 'no modules found'; + is_deeply [find_modules 'MyLoaderTest::DoesNotExist'], [], 'no modules found'; is_deeply [find_modules 'MyLoaderTest::DoesNotExist', {recursive => 1}], [], 'no modules found'; }; subtest 'Search packages' => sub { my @pkgs = find_packages 'MyLoaderTest::Foo'; is_deeply \@pkgs, ['MyLoaderTest::Foo::Bar', 'MyLoaderTest::Foo::Baz'], 'found the right packages'; - is_deeply [find_packages 'MyLoaderTest::DoesNotExist'], [], 'no packages found'; + is_deeply [find_packages 'MyLoaderTest::DoesNotExist'], [], 'no packages found'; }; subtest 'Load' => sub { diff --git a/t/mojo/log.t b/t/mojo/log.t index cf5d934585..d78838e727 100644 --- a/t/mojo/log.t +++ b/t/mojo/log.t @@ -46,8 +46,8 @@ subtest 'Logging to STDERR' => sub { subtest 'Formatting' => sub { my $log = Mojo::Log->new; - like $log->format->(time, 'debug', 'Test 123'), qr/^\[.*\] \[debug\] Test 123\n$/, 'right format'; - like $log->format->(time, 'debug', qw(Test 1 2 3)), qr/^\[.*\] \[debug\] Test 1 2 3\n$/, 'right format'; + like $log->format->(time, 'debug', 'Test 123'), qr/^\[.*\] \[debug\] Test 123\n$/, 'right format'; + like $log->format->(time, 'debug', qw(Test 1 2 3)), qr/^\[.*\] \[debug\] Test 1 2 3\n$/, 'right format'; like $log->format->(time, 'error', 'I ♥ Mojolicious'), qr/^\[.*\] \[error\] I ♥ Mojolicious\n$/, 'right format'; like $log->format->(CORE::time, 'error', 'I ♥ Mojolicious'), qr/^\[.*\] \[error\] I ♥ Mojolicious\n$/, 'right format'; $log->format(sub { @@ -140,12 +140,12 @@ subtest 'History' => sub { like $content, qr/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{5}\] \[$$\] \[error\] First\n/, 'right error message'; like $content, qr/\[.*\] \[info\] Fourth Fifth\n/, 'right info message'; unlike $content, qr/debug/, 'no debug message'; - like $history->[0][0], qr/^[0-9.]+$/, 'right epoch time'; - is $history->[0][1], 'fatal', 'right level'; - is $history->[0][2], 'Second', 'right message'; - is $history->[1][1], 'info', 'right level'; - is $history->[1][2], 'Fourth', 'right message'; - is $history->[1][3], 'Fifth', 'right message'; + like $history->[0][0], qr/^[0-9.]+$/, 'right epoch time'; + is $history->[0][1], 'fatal', 'right level'; + is $history->[0][2], 'Second', 'right message'; + is $history->[1][1], 'info', 'right level'; + is $history->[1][2], 'Fourth', 'right message'; + is $history->[1][3], 'Fifth', 'right message'; ok !$history->[2], 'no more messages'; }; @@ -163,10 +163,10 @@ subtest '"debug"' => sub { my $log = Mojo::Log->new; is $log->level('debug')->level, 'debug', 'right level'; ok !$log->is_level('trace'), '"trace" log level is inactive'; - ok $log->is_level('debug'), '"debug" log level is active'; - ok $log->is_level('info'), '"info" log level is active'; - ok $log->is_level('warn'), '"warn" log level is active'; - ok $log->is_level('error'), '"error" log level is active'; + ok $log->is_level('debug'), '"debug" log level is active'; + ok $log->is_level('info'), '"info" log level is active'; + ok $log->is_level('warn'), '"warn" log level is active'; + ok $log->is_level('error'), '"error" log level is active'; }; subtest '"info"' => sub { @@ -174,9 +174,9 @@ subtest '"info"' => sub { is $log->level('info')->level, 'info', 'right level'; ok !$log->is_level('trace'), '"trace" log level is inactive'; ok !$log->is_level('debug'), '"debug" log level is inactive'; - ok $log->is_level('info'), '"info" log level is active'; - ok $log->is_level('warn'), '"warn" log level is active'; - ok $log->is_level('error'), '"error" log level is active'; + ok $log->is_level('info'), '"info" log level is active'; + ok $log->is_level('warn'), '"warn" log level is active'; + ok $log->is_level('error'), '"error" log level is active'; }; subtest '"warn"' => sub { @@ -185,8 +185,8 @@ subtest '"warn"' => sub { ok !$log->is_level('trace'), '"trace" log level is inactive'; ok !$log->is_level('debug'), '"debug" log level is inactive'; ok !$log->is_level('info'), '"info" log level is inactive'; - ok $log->is_level('warn'), '"warn" log level is active'; - ok $log->is_level('error'), '"error" log level is active'; + ok $log->is_level('warn'), '"warn" log level is active'; + ok $log->is_level('error'), '"error" log level is active'; }; subtest '"error"' => sub { @@ -196,7 +196,7 @@ subtest '"error"' => sub { ok !$log->is_level('debug'), '"debug" log level is inactive'; ok !$log->is_level('info'), '"info" log level is inactive'; ok !$log->is_level('warn'), '"warn" log level is inactive'; - ok $log->is_level('error'), '"error" log level is active'; + ok $log->is_level('error'), '"error" log level is active'; }; subtest '"fatal"' => sub { diff --git a/t/mojo/parameters.t b/t/mojo/parameters.t index 48743c0e3e..0b77f41f37 100644 --- a/t/mojo/parameters.t +++ b/t/mojo/parameters.t @@ -6,15 +6,15 @@ use Mojo::Parameters; subtest 'Basic functionality' => sub { my $params = Mojo::Parameters->new('foo=b%3Bar&baz=23'); my $params2 = Mojo::Parameters->new('x', 1, 'y', 2); - is $params->to_string, 'foo=b%3Bar&baz=23', 'right format'; - is $params2->to_string, 'x=1&y=2', 'right format'; - is $params->to_string, 'foo=b%3Bar&baz=23', 'right format'; + is $params->to_string, 'foo=b%3Bar&baz=23', 'right format'; + is $params2->to_string, 'x=1&y=2', 'right format'; + is $params->to_string, 'foo=b%3Bar&baz=23', 'right format'; is_deeply $params->pairs, ['foo', 'b;ar', 'baz', 23], 'right structure'; $params->append(a => 4, a => 5, b => 6, b => 7); is $params->to_string, 'foo=b%3Bar&baz=23&a=4&a=5&b=6&b=7', 'right format'; push @$params, c => 'f;oo'; - is $params->to_string, 'foo=b%3Bar&baz=23&a=4&a=5&b=6&b=7&c=f%3Boo', 'right format'; - is $params->remove('a')->to_string, 'foo=b%3Bar&baz=23&b=6&b=7&c=f%3Boo', 'right format'; + is $params->to_string, 'foo=b%3Bar&baz=23&a=4&a=5&b=6&b=7&c=f%3Boo', 'right format'; + is $params->remove('a')->to_string, 'foo=b%3Bar&baz=23&b=6&b=7&c=f%3Boo', 'right format'; }; subtest 'Clone' => sub { @@ -29,9 +29,9 @@ subtest 'Merge' => sub { my $params = Mojo::Parameters->new('foo=b%3Bar&baz=23&a=4&a=5&b=6&b=7&c=f%3Boo'); my $params2 = Mojo::Parameters->new('x', 1, 'y', 2); $params->merge($params2); - is $params->to_string, 'foo=b%3Bar&baz=23&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=2', 'right format'; - is $params2->to_string, 'x=1&y=2', 'right format'; - is $params->merge(baz => undef)->to_string, 'foo=b%3Bar&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=2', 'right format'; + is $params->to_string, 'foo=b%3Bar&baz=23&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=2', 'right format'; + is $params2->to_string, 'x=1&y=2', 'right format'; + is $params->merge(baz => undef)->to_string, 'foo=b%3Bar&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=2', 'right format'; is $params->merge(y => 3, z => [4, 5])->to_string, 'foo=b%3Bar&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=3&z=4&z=5', 'right format'; is $params->merge(Mojo::Parameters->new(z => 6))->to_string, 'foo=b%3Bar&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=3&z=6', @@ -49,13 +49,13 @@ subtest 'Merge (instances)' => sub { subtest 'Param' => sub { my $params = Mojo::Parameters->new('foo=b%3Bar&a=4&a=5&b=6&b=7&c=f%3Boo&x=1&y=3&z=6'); - is_deeply $params->param('foo'), 'b;ar', 'right structure'; + is_deeply $params->param('foo'), 'b;ar', 'right structure'; is_deeply $params->every_param('foo'), ['b;ar'], 'right structure'; - is_deeply $params->every_param('a'), [4, 5], 'right structure'; + is_deeply $params->every_param('a'), [4, 5], 'right structure'; $params->param(foo => 'bar'); - is_deeply [$params->param('foo')], ['bar'], 'right structure'; - is_deeply $params->param(foo => qw(baz yada))->every_param('foo'), [qw(baz yada)], 'right structure'; - is_deeply $params->names, [qw(a b c foo x y z)], 'right structure'; + is_deeply [$params->param('foo')], ['bar'], 'right structure'; + is_deeply $params->param(foo => qw(baz yada))->every_param('foo'), [qw(baz yada)], 'right structure'; + is_deeply $params->names, [qw(a b c foo x y z)], 'right structure'; }; subtest 'Append' => sub { @@ -67,16 +67,16 @@ subtest 'Append' => sub { $params = Mojo::Parameters->new(foo => '', bar => 'bar'); is $params->to_string, 'foo=&bar=bar', 'right format'; $params = Mojo::Parameters->new(bar => 'bar', foo => ''); - is $params->to_string, 'bar=bar&foo=', 'right format'; + is $params->to_string, 'bar=bar&foo=', 'right format'; is $params->append($params2)->to_string, 'bar=bar&foo=&x=1&y=2', 'right format'; - is $params2->to_string, 'x=1&y=2', 'right format'; + is $params2->to_string, 'x=1&y=2', 'right format'; }; subtest '"0"' => sub { my $params = Mojo::Parameters->new(0 => 0); - is $params->param(0), 0, 'right value'; + is $params->param(0), 0, 'right value'; is_deeply $params->every_param(0), [0], 'right value'; - is_deeply $params->every_param('foo'), [], 'no values'; + is_deeply $params->every_param('foo'), [], 'no values'; is $params->to_string, '0=0', 'right format'; $params = Mojo::Parameters->new($params->to_string); is $params->param(0), 0, 'right value'; @@ -134,8 +134,8 @@ subtest '"+"' => sub { $params = Mojo::Parameters->new('a=works+too'); is "$params", 'a=works+too', 'right format'; is_deeply $params->to_hash, {a => 'works too'}, 'right structure'; - is $params->param('a'), 'works too', 'right value'; - is "$params", 'a=works+too', 'right format'; + is $params->param('a'), 'works too', 'right value'; + is "$params", 'a=works+too', 'right format'; }; subtest 'Array values' => sub { @@ -163,16 +163,16 @@ subtest 'Unicode' => sub { my $params = Mojo::Parameters->new; $params->parse('input=say%20%22%C2%AB~%22;'); is_deeply $params->pairs, ['input', 'say "«~";'], 'right structure'; - is $params->param('input'), 'say "«~";', 'right value'; - is "$params", 'input=say+%22%C2%AB%7E%22%3B', 'right result'; + is $params->param('input'), 'say "«~";', 'right value'; + is "$params", 'input=say+%22%C2%AB%7E%22%3B', 'right result'; $params = Mojo::Parameters->new('♥=☃'); is_deeply $params->pairs, ['♥', '☃'], 'right structure'; - is $params->param('♥'), '☃', 'right value'; - is "$params", '%E2%99%A5=%E2%98%83', 'right result'; + is $params->param('♥'), '☃', 'right value'; + is "$params", '%E2%99%A5=%E2%98%83', 'right result'; $params = Mojo::Parameters->new('%E2%99%A5=%E2%98%83'); is_deeply $params->pairs, ['♥', '☃'], 'right structure'; - is $params->param('♥'), '☃', 'right value'; - is "$params", '%E2%99%A5=%E2%98%83', 'right result'; + is $params->param('♥'), '☃', 'right value'; + is "$params", '%E2%99%A5=%E2%98%83', 'right result'; }; subtest 'Reparse' => sub { @@ -184,8 +184,8 @@ subtest 'Reparse' => sub { subtest 'Replace' => sub { my $params = Mojo::Parameters->new('a=1&b=2'); $params->pairs([a => 2, b => 3]); - is $params->to_string, 'a=2&b=3', 'right result'; - is $params->pairs([])->to_string, '', 'right result'; + is $params->to_string, 'a=2&b=3', 'right result'; + is $params->pairs([])->to_string, '', 'right result'; }; subtest 'Query string' => sub { @@ -203,15 +203,15 @@ subtest '"%"' => sub { subtest 'Special characters' => sub { my $params = Mojo::Parameters->new('!$\'()*,:@/foo?=!$\'()*,:@/?&bar=23'); - is $params->param('!$\'()*,:@/foo?'), '!$\'()*,:@/?', 'right value'; - is $params->param('bar'), 23, 'right value'; + is $params->param('!$\'()*,:@/foo?'), '!$\'()*,:@/?', 'right value'; + is $params->param('bar'), 23, 'right value'; is "$params", '%21%24%27%28%29*%2C%3A%40%2Ffoo%3F=' . '%21%24%27%28%29*%2C%3A%40%2F%3F&bar=23', 'right result'; }; subtest 'No charset' => sub { my $params = Mojo::Parameters->new('%E5=%E4')->charset(undef); - is $params->param("\xe5"), "\xe4", 'right value'; - is "$params", '%E5=%E4', 'right result'; + is $params->param("\xe5"), "\xe4", 'right value'; + is "$params", '%E5=%E4', 'right result'; is $params->clone->to_string, '%E5=%E4', 'right result'; }; diff --git a/t/mojo/path.t b/t/mojo/path.t index 8e00228f6a..642a07bb88 100644 --- a/t/mojo/path.t +++ b/t/mojo/path.t @@ -6,13 +6,13 @@ use Mojo::Path; subtest 'Basic functionality' => sub { my $path = Mojo::Path->new; is $path->parse('/path')->to_string, '/path', 'right path'; - is $path->to_dir, '/', 'right directory'; - is_deeply $path->parts, ['path'], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + is $path->to_dir, '/', 'right directory'; + is_deeply $path->parts, ['path'], 'right structure'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; - is $path->parse('path/')->to_string, 'path/', 'right path'; - is $path->to_dir, 'path/', 'right directory'; - is $path->to_dir->to_abs_string, '/path/', 'right directory'; + is $path->parse('path/')->to_string, 'path/', 'right path'; + is $path->to_dir, 'path/', 'right directory'; + is $path->to_dir->to_abs_string, '/path/', 'right directory'; is_deeply $path->parts, ['path'], 'right structure'; ok !$path->leading_slash, 'no leading slash'; ok $path->trailing_slash, 'has trailing slash'; @@ -26,7 +26,7 @@ subtest 'Advanced' => sub { my $path = Mojo::Path->new('/AZaz09-._~!$&\'()*+,;=:@'); is $path->[0], 'AZaz09-._~!$&\'()*+,;=:@', 'right part'; is $path->[1], undef, 'no part'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; is "$path", '/AZaz09-._~!$&\'()*+,;=:@', 'right path'; push @$path, 'f/oo'; @@ -36,14 +36,14 @@ subtest 'Advanced' => sub { subtest 'Unicode' => sub { my $path = Mojo::Path->new; is $path->parse('/foo/♥/bar')->to_string, '/foo/%E2%99%A5/bar', 'right path'; - is $path->to_dir, '/foo/%E2%99%A5/', 'right directory'; - is_deeply $path->parts, [qw(foo ♥ bar)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + is $path->to_dir, '/foo/%E2%99%A5/', 'right directory'; + is_deeply $path->parts, [qw(foo ♥ bar)], 'right structure'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; - is $path->to_route, '/foo/♥/bar', 'right route'; + is $path->to_route, '/foo/♥/bar', 'right route'; is $path->parse('/foo/%E2%99%A5/~b@a:r+')->to_string, '/foo/%E2%99%A5/~b@a:r+', 'right path'; is_deeply $path->parts, [qw(foo ♥ ~b@a:r+)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; is $path->to_route, '/foo/♥/~b@a:r+', 'right route'; }; @@ -52,10 +52,10 @@ subtest 'Zero in path' => sub { my $path = Mojo::Path->new; is $path->parse('/path/0')->to_string, '/path/0', 'right path'; is_deeply $path->parts, [qw(path 0)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; $path = Mojo::Path->new('0'); - is_deeply $path->parts, [0], 'right structure'; + is_deeply $path->parts, [0], 'right structure'; is $path->to_string, '0', 'right path'; is $path->to_abs_string, '/0', 'right absolute path'; is $path->to_route, '/0', 'right route'; @@ -65,10 +65,10 @@ subtest 'Canonicalizing' => sub { my $path = Mojo::Path->new('/%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fpasswd'); is "$path", '/%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fpasswd', 'same path'; is_deeply $path->parts, ['', qw(.. .. .. .. .. .. .. .. .. .. etc passwd)], 'right structure'; - is "$path", '//../../../../../../../../../../etc/passwd', 'normalized path'; - is $path->canonicalize, '/../../../../../../../../../../etc/passwd', 'canonicalized path'; - is_deeply $path->parts, [qw(.. .. .. .. .. .. .. .. .. .. etc passwd)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + is "$path", '//../../../../../../../../../../etc/passwd', 'normalized path'; + is $path->canonicalize, '/../../../../../../../../../../etc/passwd', 'canonicalized path'; + is_deeply $path->parts, [qw(.. .. .. .. .. .. .. .. .. .. etc passwd)], 'right structure'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; }; @@ -76,20 +76,20 @@ subtest 'Canonicalizing (alternative)' => sub { my $path = Mojo::Path->new('%2ftest%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fpasswd'); is "$path", '%2ftest%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fpasswd', 'same path'; is_deeply $path->parts, [qw(test .. .. .. .. .. .. .. .. .. etc passwd)], 'right structure'; - is "$path", '/test/../../../../../../../../../etc/passwd', 'normalized path'; - is $path->canonicalize, '/../../../../../../../../etc/passwd', 'canonicalized path'; - is_deeply $path->parts, [qw(.. .. .. .. .. .. .. .. etc passwd)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + is "$path", '/test/../../../../../../../../../etc/passwd', 'normalized path'; + is $path->canonicalize, '/../../../../../../../../etc/passwd', 'canonicalized path'; + is_deeply $path->parts, [qw(.. .. .. .. .. .. .. .. etc passwd)], 'right structure'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; }; subtest 'Canonicalize (triple dot)' => sub { my $path = Mojo::Path->new('/foo/.../.../windows/win.ini'); is "$path", '/foo/.../.../windows/win.ini', 'same path'; - is_deeply $path->parts, [qw(foo ... ... windows win.ini)], 'right structure'; - is $path->canonicalize, '/foo/windows/win.ini', 'canonicalized path'; - is_deeply $path->parts, [qw(foo windows win.ini)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + is_deeply $path->parts, [qw(foo ... ... windows win.ini)], 'right structure'; + is $path->canonicalize, '/foo/windows/win.ini', 'canonicalized path'; + is_deeply $path->parts, [qw(foo windows win.ini)], 'right structure'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; }; @@ -97,18 +97,18 @@ subtest 'Canonicalizing (with escaped "%")' => sub { my $path = Mojo::Path->new('%2ftest%2f..%252f..%2f..%2f..%2f..%2fetc%2fpasswd'); is "$path", '%2ftest%2f..%252f..%2f..%2f..%2f..%2fetc%2fpasswd', 'same path'; is_deeply $path->parts, [qw(test ..%2f.. .. .. .. etc passwd)], 'right structure'; - is "$path", '/test/..%252f../../../../etc/passwd', 'normalized path'; - is $path->canonicalize, '/../etc/passwd', 'canonicalized path'; - is_deeply $path->parts, [qw(.. etc passwd)], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + is "$path", '/test/..%252f../../../../etc/passwd', 'normalized path'; + is $path->canonicalize, '/../etc/passwd', 'canonicalized path'; + is_deeply $path->parts, [qw(.. etc passwd)], 'right structure'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; }; subtest 'Contains' => sub { my $path = Mojo::Path->new('/foo/bar'); - ok $path->contains('/'), 'contains path'; - ok $path->contains('/foo'), 'contains path'; - ok $path->contains('/foo/bar'), 'contains path'; + ok $path->contains('/'), 'contains path'; + ok $path->contains('/foo'), 'contains path'; + ok $path->contains('/foo/bar'), 'contains path'; ok !$path->contains('/foobar'), 'does not contain path'; ok !$path->contains('/foo/b'), 'does not contain path'; ok !$path->contains('/foo/bar/baz'), 'does not contain path'; @@ -118,16 +118,16 @@ subtest 'Contains' => sub { ok !$path->contains('/♥foo'), 'does not contain path'; ok !$path->contains('/foo♥'), 'does not contain path'; $path = Mojo::Path->new('/'); - ok $path->contains('/'), 'contains path'; + ok $path->contains('/'), 'contains path'; ok !$path->contains('/foo'), 'does not contain path'; $path = Mojo::Path->new('/0'); - ok $path->contains('/'), 'contains path'; - ok $path->contains('/0'), 'contains path'; + ok $path->contains('/'), 'contains path'; + ok $path->contains('/0'), 'contains path'; ok !$path->contains('/0/0'), 'does not contain path'; $path = Mojo::Path->new('/0/♥.html'); - ok $path->contains('/'), 'contains path'; - ok $path->contains('/0'), 'contains path'; - ok $path->contains('/0/♥.html'), 'contains path'; + ok $path->contains('/'), 'contains path'; + ok $path->contains('/0'), 'contains path'; + ok $path->contains('/0/♥.html'), 'contains path'; ok !$path->contains('/0/♥'), 'does not contain path'; ok !$path->contains('/0/0.html'), 'does not contain path'; ok !$path->contains('/0.html'), 'does not contain path'; @@ -138,12 +138,12 @@ subtest 'Merge' => sub { my $path = Mojo::Path->new('/foo'); $path->merge('bar/baz'); is "$path", '/bar/baz', 'right path'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; $path = Mojo::Path->new('/foo/'); $path->merge('bar/baz'); is "$path", '/foo/bar/baz', 'right path'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; $path = Mojo::Path->new('/foo/'); $path->merge('bar/baz/'); @@ -153,7 +153,7 @@ subtest 'Merge' => sub { $path = Mojo::Path->new('/foo/'); $path->merge('/bar/baz'); is "$path", '/bar/baz', 'right path'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; is $path->to_route, '/bar/baz', 'right route'; $path = Mojo::Path->new('/foo/bar'); @@ -161,7 +161,7 @@ subtest 'Merge' => sub { is "$path", '/bar/baz/', 'right path'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; - is $path->to_route, '/bar/baz/', 'right route'; + is $path->to_route, '/bar/baz/', 'right route'; $path = Mojo::Path->new('foo/bar'); $path->merge('baz/yada'); is "$path", 'foo/baz/yada', 'right path'; @@ -173,39 +173,39 @@ subtest 'Merge' => sub { subtest 'Empty path elements' => sub { my $path = Mojo::Path->new('//'); is "$path", '//', 'right path'; - is_deeply $path->parts, [], 'no parts'; + is_deeply $path->parts, [], 'no parts'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; is "$path", '//', 'right normalized path'; $path = Mojo::Path->new('%2F%2f'); is "$path", '%2F%2f', 'right path'; - is_deeply $path->parts, [], 'no parts'; + is_deeply $path->parts, [], 'no parts'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; is "$path", '//', 'right normalized path'; $path = Mojo::Path->new('/foo//bar/23/'); is "$path", '/foo//bar/23/', 'right path'; - is_deeply $path->parts, ['foo', '', 'bar', 23], 'right structure'; + is_deeply $path->parts, ['foo', '', 'bar', 23], 'right structure'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; $path = Mojo::Path->new('//foo/bar/23/'); is "$path", '//foo/bar/23/', 'right path'; - is_deeply $path->parts, ['', 'foo', 'bar', 23], 'right structure'; + is_deeply $path->parts, ['', 'foo', 'bar', 23], 'right structure'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; $path = Mojo::Path->new('/foo///bar/23/'); is "$path", '/foo///bar/23/', 'right path'; - is_deeply $path->parts, ['foo', '', '', 'bar', 23], 'right structure'; + is_deeply $path->parts, ['foo', '', '', 'bar', 23], 'right structure'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; $path = Mojo::Path->new('///foo/bar/23/'); is "$path", '///foo/bar/23/', 'right path'; - is_deeply $path->parts, ['', '', 'foo', 'bar', 23], 'right structure'; + is_deeply $path->parts, ['', '', 'foo', 'bar', 23], 'right structure'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; $path = Mojo::Path->new('///foo///bar/23///'); is "$path", '///foo///bar/23///', 'right path'; - is_deeply $path->parts, ['', '', 'foo', '', '', 'bar', 23, '', ''], 'right structure'; + is_deeply $path->parts, ['', '', 'foo', '', '', 'bar', 23, '', ''], 'right structure'; ok $path->leading_slash, 'has leading slash'; ok $path->trailing_slash, 'has trailing slash'; }; @@ -213,7 +213,7 @@ subtest 'Empty path elements' => sub { subtest 'Escaped slash' => sub { my $path = Mojo::Path->new->parts(['foo/bar']); is_deeply $path->parts, ['foo/bar'], 'right structure'; - is "$path", 'foo%2Fbar', 'right path'; + is "$path", 'foo%2Fbar', 'right path'; is $path->to_string, 'foo%2Fbar', 'right path'; is $path->to_abs_string, '/foo%2Fbar', 'right absolute path'; is $path->to_route, '/foo/bar', 'right route'; @@ -222,12 +222,12 @@ subtest 'Escaped slash' => sub { subtest 'Unchanged path' => sub { my $path = Mojo::Path->new('/foob%E4r/-._~!$&\'()*+,;=:@'); is_deeply $path->clone->parts, ["foob\xe4r", '-._~!$&\'()*+,;=:@'], 'right structure'; - ok $path->contains("/foob\xe4r"), 'contains path'; - ok $path->contains("/foob\xe4r/-._~!\$&'()*+,;=:@"), 'contains path'; + ok $path->contains("/foob\xe4r"), 'contains path'; + ok $path->contains("/foob\xe4r/-._~!\$&'()*+,;=:@"), 'contains path'; ok !$path->contains("/foob\xe4r/-._~!\$&'()*+,;=:."), 'does not contain path'; - is $path->to_string, '/foob%E4r/-._~!$&\'()*+,;=:@', 'right path'; - is $path->to_abs_string, '/foob%E4r/-._~!$&\'()*+,;=:@', 'right absolute path'; - is $path->to_route, "/foob\xe4r/-._~!\$&'()*+,;=:@", 'right route'; + is $path->to_string, '/foob%E4r/-._~!$&\'()*+,;=:@', 'right path'; + is $path->to_abs_string, '/foob%E4r/-._~!$&\'()*+,;=:@', 'right absolute path'; + is $path->to_route, "/foob\xe4r/-._~!\$&'()*+,;=:@", 'right route'; is $path->clone->to_string, '/foob%E4r/-._~!$&\'()*+,;=:@', 'right path'; is $path->clone->to_abs_string, '/foob%E4r/-._~!$&\'()*+,;=:@', 'right absolute path'; is $path->clone->to_route, "/foob\xe4r/-._~!\$&'()*+,;=:@", 'right route'; @@ -245,23 +245,23 @@ subtest 'Reuse path' => sub { subtest 'Latin-1' => sub { my $path = Mojo::Path->new->charset('Latin-1')->parse('/foob%E4r'); is_deeply $path->parts, ['foobär'], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; - is "$path", '/foob%E4r', 'right path'; - is $path->to_string, '/foob%E4r', 'right path'; - is $path->to_abs_string, '/foob%E4r', 'right absolute path'; - is $path->to_route, '/foobär', 'right route'; + is "$path", '/foob%E4r', 'right path'; + is $path->to_string, '/foob%E4r', 'right path'; + is $path->to_abs_string, '/foob%E4r', 'right absolute path'; + is $path->to_route, '/foobär', 'right route'; is $path->clone->to_string, '/foob%E4r', 'right path'; }; subtest 'No charset' => sub { my $path = Mojo::Path->new->charset(undef)->parse('/%E4'); is_deeply $path->parts, ["\xe4"], 'right structure'; - ok $path->leading_slash, 'has leading slash'; + ok $path->leading_slash, 'has leading slash'; ok !$path->trailing_slash, 'no trailing slash'; - is "$path", '/%E4', 'right path'; - is $path->to_route, "/\xe4", 'right route'; - is $path->clone->to_string, '/%E4', 'right path'; + is "$path", '/%E4', 'right path'; + is $path->to_route, "/\xe4", 'right route'; + is $path->clone->to_string, '/%E4', 'right path'; }; done_testing(); diff --git a/t/mojo/prefork.t b/t/mojo/prefork.t index b4d9f67537..3aa94a8a5c 100644 --- a/t/mojo/prefork.t +++ b/t/mojo/prefork.t @@ -22,11 +22,11 @@ subtest 'Manage and clean up PID file' => sub { ok -e $file, 'file exists'; is path($file)->slurp, "-23\n", 'right process id'; ok !$prefork->check_pid, 'no process id'; - ok !-e $file, 'file has been cleaned up'; + ok !-e $file, 'file has been cleaned up'; $prefork->ensure_pid_file($$); ok -e $file, 'file exists'; - is path($file)->slurp, "$$\n", 'right process id'; - is $prefork->check_pid, $$, 'right process id'; + is path($file)->slurp, "$$\n", 'right process id'; + is $prefork->check_pid, $$, 'right process id'; undef $prefork; ok !-e $file, 'file has been cleaned up'; }; @@ -87,7 +87,7 @@ subtest 'Multiple workers and graceful shutdown' => sub { is scalar @spawn, 4, 'four workers spawned'; is scalar @reap, 4, 'four workers reaped'; ok !!grep { $worker eq $_ } @spawn, 'worker has a heartbeat'; - ok $graceful, 'server has been stopped gracefully'; + ok $graceful, 'server has been stopped gracefully'; is_deeply [sort @spawn], [sort @reap], 'same process ids'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'just works!', 'right content'; @@ -130,8 +130,8 @@ subtest 'One worker and immediate shutdown' => sub { $prefork->on(finish => sub { $graceful = pop }); $prefork->run; is $prefork->ioloop->max_accepts, 500, 'right value'; - is scalar @spawn, 1, 'one worker spawned'; - is scalar @reap, 1, 'one worker reaped'; + is scalar @spawn, 1, 'one worker spawned'; + is scalar @reap, 1, 'one worker reaped'; ok !$graceful, 'server has been stopped immediately'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'works too!', 'right content'; diff --git a/t/mojo/promise.t b/t/mojo/promise.t index 6feddda051..a8e2fe8b41 100644 --- a/t/mojo/promise.t +++ b/t/mojo/promise.t @@ -13,13 +13,13 @@ subtest 'Resolved' => sub { $promise->resolve('hello', 'world'); Mojo::IOLoop->one_tick; is_deeply \@results, ['hello', 'world'], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; $promise = Mojo::Promise->resolve('test'); $promise->then(sub { @results = @_ }, sub { @errors = @_ }); Mojo::IOLoop->one_tick; is_deeply \@results, ['test'], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; }; subtest 'Already resolved' => sub { @@ -28,7 +28,7 @@ subtest 'Already resolved' => sub { $promise->then(sub { @results = @_ }, sub { @errors = @_ }); Mojo::IOLoop->one_tick; is_deeply \@results, ['early'], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; }; subtest 'Resolved with finally' => sub { @@ -46,14 +46,14 @@ subtest 'Rejected' => sub { $promise->then(sub { @results = @_ }, sub { @errors = @_ }); $promise->reject('bye', 'world'); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, ['bye', 'world'], 'promise rejected'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, ['bye', 'world'], 'promise rejected'; $promise = Mojo::Promise->reject('test'); $promise->then(sub { @results = @_ }, sub { @errors = @_ }); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, ['test'], 'promise rejected'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, ['test'], 'promise rejected'; }; subtest 'Rejected early' => sub { @@ -61,8 +61,8 @@ subtest 'Rejected early' => sub { my (@results, @errors); $promise->then(sub { @results = @_ }, sub { @errors = @_ }); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, ['early'], 'promise rejected'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, ['early'], 'promise rejected'; }; subtest 'Rejected with finally' => sub { @@ -82,7 +82,7 @@ subtest 'Wrap' => sub { }); $promise->then(sub { @results = @_ }, sub { @errors = @_ })->wait; is_deeply \@results, ['resolved', '!'], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; (@results, @errors) = (); $promise = Mojo::Promise->new(sub { @@ -90,8 +90,8 @@ subtest 'Wrap' => sub { Mojo::IOLoop->timer(0 => sub { $reject->('rejected', '!') }); }); $promise->then(sub { @results = @_ }, sub { @errors = @_ })->wait; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, ['rejected', '!'], 'promise rejected'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, ['rejected', '!'], 'promise rejected'; }; subtest 'No state change' => sub { @@ -101,7 +101,7 @@ subtest 'No state change' => sub { $promise->resolve('pass')->reject('fail')->resolve('fail'); Mojo::IOLoop->one_tick; is_deeply \@results, ['pass'], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; }; subtest 'Resolved chained' => sub { @@ -197,8 +197,8 @@ subtest 'Promise returned by finally (rejected)' => sub { })->then(sub { @results = @_ }, sub { @errors = @_ }); $promise->resolve('failed'); $promise3->wait; - is_deeply \@results, [], 'promises not resolved'; - is_deeply \@errors, ['works'], 'promises rejected'; + is_deeply \@results, [], 'promises not resolved'; + is_deeply \@errors, ['works'], 'promises rejected'; }; subtest 'Exception in finally' => sub { @@ -220,7 +220,7 @@ subtest 'Clone' => sub { is $loop, $promise2->ioloop, 'same loop'; $loop->one_tick; is_deeply \@results, ['success'], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; }; subtest 'Exception in chain' => sub { @@ -230,8 +230,8 @@ subtest 'Exception in chain' => sub { ->catch(sub { @errors = @_ }); $promise->resolve('works'); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promises not resolved'; - is_deeply \@errors, ["test: works\n"], 'promises rejected'; + is_deeply \@results, [], 'promises not resolved'; + is_deeply \@errors, ["test: works\n"], 'promises rejected'; }; subtest 'Race' => sub { @@ -257,8 +257,8 @@ subtest 'Rejected race' => sub { $promise3->resolve('third'); $promise->resolve('first'); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promises not resolved'; - is_deeply \@errors, ['second'], 'promise rejected'; + is_deeply \@results, [], 'promises not resolved'; + is_deeply \@errors, ['second'], 'promise rejected'; }; subtest 'Any' => sub { @@ -284,8 +284,8 @@ subtest 'Any (all rejections)' => sub { $promise3->reject('third'); $promise->reject('first'); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promises not resolved'; - is_deeply \@errors, [['first'], ['second'], ['third']], 'promises rejected'; + is_deeply \@results, [], 'promises not resolved'; + is_deeply \@errors, [['first'], ['second'], ['third']], 'promises rejected'; }; subtest 'Timeout' => sub { @@ -294,8 +294,8 @@ subtest 'Timeout' => sub { my $promise2 = Mojo::Promise->new->timeout(0.025 => 'Timeout2'); my $promise3 = Mojo::Promise->race($promise, $promise2)->then(sub { @results = @_ })->catch(sub { @errors = @_ })->wait; - is_deeply \@results, [], 'promises not resolved'; - is_deeply \@errors, ['Timeout2'], 'promise rejected'; + is_deeply \@results, [], 'promises not resolved'; + is_deeply \@errors, ['Timeout2'], 'promise rejected'; }; subtest 'Timeout with default message' => sub { @@ -339,8 +339,8 @@ subtest 'Rejected all' => sub { $promise3->reject('third'); $promise->resolve('first'); Mojo::IOLoop->one_tick; - is_deeply \@results, [], 'promises not resolved'; - is_deeply \@errors, ['third'], 'promise rejected'; + is_deeply \@results, [], 'promises not resolved'; + is_deeply \@errors, ['third'], 'promise rejected'; }; subtest 'All settled' => sub { @@ -394,8 +394,8 @@ subtest 'Settle with promise' => sub { $promise2 = Mojo::Promise->new->reject($promise)->catch(sub { push @errors, 'first', @_; () }); $promise2->then(sub { push @results, 'second', @_ }); Mojo::IOLoop->one_tick; - is_deeply \@errors, ['first', $promise], 'promises rejected'; - is_deeply \@results, ['second'], 'promises resolved'; + is_deeply \@errors, ['first', $promise], 'promises rejected'; + is_deeply \@results, ['second'], 'promises resolved'; $promise->catch(sub { }); }; @@ -426,17 +426,17 @@ subtest 'Warnings' => sub { local $SIG{__WARN__} = sub { push @warn, shift }; Mojo::Promise->reject('one'); like $warn[0], qr/Unhandled rejected promise: one/, 'unhandled'; - is $warn[1], undef, 'no more warnings'; + is $warn[1], undef, 'no more warnings'; @warn = (); Mojo::Promise->reject('two')->then(sub { })->wait; like $warn[0], qr/Unhandled rejected promise: two/, 'unhandled'; - is $warn[1], undef, 'no more warnings'; + is $warn[1], undef, 'no more warnings'; @warn = (); Mojo::Promise->reject('three')->finally(sub { })->wait; like $warn[0], qr/Unhandled rejected promise: three/, 'unhandled'; - is $warn[1], undef, 'no more warnings'; + is $warn[1], undef, 'no more warnings'; @warn = (); my $promise = Mojo::Promise->new; @@ -445,7 +445,7 @@ subtest 'Warnings' => sub { is $warn[0], undef, 'no warnings'; undef $promise; like $warn[0], qr/Unhandled rejected promise: four/, 'unhandled'; - is $warn[1], undef, 'no more warnings'; + is $warn[1], undef, 'no more warnings'; }; subtest 'Warnings (multiple branches)' => sub { @@ -467,7 +467,7 @@ subtest 'Warnings (multiple branches)' => sub { $promise->wait; is_deeply \@errors, ['branches2'], 'promise rejected'; like $warn[0], qr/Unhandled rejected promise: branches2/, 'unhandled'; - is $warn[1], undef, 'no more warnings'; + is $warn[1], undef, 'no more warnings'; @warn = (); $promise = Mojo::Promise->new; @@ -477,7 +477,7 @@ subtest 'Warnings (multiple branches)' => sub { $promise->wait; like $warn[0], qr/Unhandled rejected promise: branches3/, 'unhandled'; like $warn[1], qr/Unhandled rejected promise: branches3/, 'unhandled'; - is $warn[2], undef, 'no more warnings'; + is $warn[2], undef, 'no more warnings'; }; subtest 'Map' => sub { @@ -487,7 +487,7 @@ subtest 'Map' => sub { is_deeply \@started, [1, 2, 3, 4, 5], 'all started without concurrency'; $promise->wait; is_deeply \@results, [[1], [2], [3], [4], [5]], 'correct result'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; }; subtest 'Map (with concurrency limit)' => sub { @@ -506,7 +506,7 @@ subtest 'Map (with concurrency limit)' => sub { 1 .. 7 )->then(sub { @results = @_ }, sub { @errors = @_ })->wait; is_deeply \@results, [[1], [2], [3], [4], [5], [6], [7]], 'correct result'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; }; subtest 'Map (with reject)' => sub { @@ -520,8 +520,8 @@ subtest 'Map (with reject)' => sub { }, 1 .. 5 )->then(sub { @results = @_ }, sub { @errors = @_ })->wait; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, [1], 'correct errors'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, [1], 'correct errors'; is_deeply \@started, [1, 2, 3], 'only initial batch started'; }; @@ -529,7 +529,7 @@ subtest 'Map (custom event loop)' => sub { my $ok; my $loop = Mojo::IOLoop->new; my $promise = Mojo::Promise->map(sub { Mojo::Promise->new->ioloop($loop)->resolve }, 1); - is $promise->ioloop, $loop, 'same loop'; + is $promise->ioloop, $loop, 'same loop'; isnt $promise->ioloop, Mojo::IOLoop->singleton, 'not the singleton'; $promise->then(sub { $ok = 1; $loop->stop }); $loop->start; diff --git a/t/mojo/proxy.t b/t/mojo/proxy.t index 7f67a8f094..2f3faa4238 100644 --- a/t/mojo/proxy.t +++ b/t/mojo/proxy.t @@ -17,8 +17,8 @@ subtest 'Proxy detection with uppercase variable names' => sub { is $proxy->http, undef, 'right proxy'; is $proxy->https, undef, 'right proxy'; ok !$proxy->is_needed('dummy.mojolicious.org'), 'no proxy needed'; - ok $proxy->is_needed('icious.org'), 'proxy needed'; - ok $proxy->is_needed('localhost'), 'proxy needed'; + ok $proxy->is_needed('icious.org'), 'proxy needed'; + ok $proxy->is_needed('localhost'), 'proxy needed'; }; subtest 'Proxy detection with lowercase variable names' => sub { @@ -33,16 +33,16 @@ subtest 'Proxy detection with lowercase variable names' => sub { my $proxy = Mojo::UserAgent::Proxy->new; $proxy->detect; is_deeply $proxy->not, ['localhost', 'localdomain', 'foo.com', 'example.com'], 'right list'; - is $proxy->http, 'proxy.example.com', 'right proxy'; - is $proxy->https, 'tunnel.example.com', 'right proxy'; - ok $proxy->is_needed('dummy.mojolicious.org'), 'proxy needed'; - ok $proxy->is_needed('icious.org'), 'proxy needed'; + is $proxy->http, 'proxy.example.com', 'right proxy'; + is $proxy->https, 'tunnel.example.com', 'right proxy'; + ok $proxy->is_needed('dummy.mojolicious.org'), 'proxy needed'; + ok $proxy->is_needed('icious.org'), 'proxy needed'; ok !$proxy->is_needed('localhost'), 'proxy needed'; ok !$proxy->is_needed('localhost.localdomain'), 'no proxy needed'; ok !$proxy->is_needed('foo.com'), 'no proxy needed'; ok !$proxy->is_needed('example.com'), 'no proxy needed'; ok !$proxy->is_needed('www.example.com'), 'no proxy needed'; - ok $proxy->is_needed('www.example.com.com'), 'proxy needed'; + ok $proxy->is_needed('www.example.com.com'), 'proxy needed'; }; done_testing(); diff --git a/t/mojo/psgi.t b/t/mojo/psgi.t index 7a273f9152..08c41461e3 100644 --- a/t/mojo/psgi.t +++ b/t/mojo/psgi.t @@ -71,7 +71,7 @@ subtest 'Binding' => sub { is $res->[0], 200, 'right status'; my %headers = @{$res->[1]}; ok keys(%headers) >= 3, 'enough headers'; - ok $headers{Date}, 'has "Date" value'; + ok $headers{Date}, 'has "Date" value'; is $headers{'Content-Length'}, 43, 'right "Content-Length" value'; is $headers{'Content-Type'}, 'application/json;charset=UTF-8', 'right "Content-Type" value'; my $params = ''; @@ -108,7 +108,7 @@ subtest 'Command' => sub { is $res->[0], 200, 'right status'; my %headers = @{$res->[1]}; ok keys(%headers) >= 3, 'enough headers'; - ok $headers{Date}, 'has "Date" value'; + ok $headers{Date}, 'has "Date" value'; is $headers{'Content-Length'}, 43, 'right "Content-Length" value'; is $headers{'Content-Type'}, 'application/json;charset=UTF-8', 'right "Content-Type" value'; my $params = ''; @@ -143,8 +143,8 @@ subtest 'Simple' => sub { is $headers{'Content-Type'}, 'text/html;charset=UTF-8', 'right "Content-Type" value'; my $body = ''; while (defined(my $chunk = $res->[2]->getline)) { $body .= $chunk } - is $body, 'Your Mojo is working!', 'right content'; - is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; + is $body, 'Your Mojo is working!', 'right content'; + is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; $res->[2]->close; is delete $ENV{MOJO_HELLO}, 'world', 'finish event has been emitted'; }; @@ -173,7 +173,7 @@ subtest 'HEAD request' => sub { is $headers{'Content-Type'}, 'text/html;charset=UTF-8', 'right "Content-Type" value'; my $body = ''; while (defined(my $chunk = $res->[2]->getline)) { $body .= $chunk } - is $body, '', 'no content'; + is $body, '', 'no content'; is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; $res->[2]->close; is delete $ENV{MOJO_HELLO}, 'world', 'finish event has been emitted'; @@ -235,8 +235,8 @@ subtest 'Reverse proxy' => sub { is $headers{'Content-Type'}, 'text/html;charset=UTF-8', 'right "Content-Type" value'; my $body = ''; while (defined(my $chunk = $res->[2]->getline)) { $body .= $chunk } - is $body, '192.0.2.1:https', 'right content'; - is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; + is $body, '192.0.2.1:https', 'right content'; + is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; $res->[2]->close; is delete $ENV{MOJO_HELLO}, 'world', 'finish event has been emitted'; }; @@ -272,8 +272,8 @@ subtest 'Trusted proxies' => sub { is $headers{'Content-Type'}, 'text/html;charset=UTF-8', 'right "Content-Type" value'; my $body = ''; while (defined(my $chunk = $res->[2]->getline)) { $body .= $chunk } - is $body, '10.10.10.10:https', 'right content'; - is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; + is $body, '10.10.10.10:https', 'right content'; + is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; $res->[2]->close; is delete $ENV{MOJO_HELLO}, 'world', 'finish event has been emitted'; }; @@ -308,8 +308,8 @@ subtest 'Trusted proxies (no REMOTE_ADDR)' => sub { is $headers{'Content-Type'}, 'text/html;charset=UTF-8', 'right "Content-Type" value'; my $body = ''; while (defined(my $chunk = $res->[2]->getline)) { $body .= $chunk } - is $body, 'https', 'right content'; - is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; + is $body, 'https', 'right content'; + is $ENV{MOJO_HELLO}, undef, 'finish event has not been emitted'; $res->[2]->close; is delete $ENV{MOJO_HELLO}, 'world', 'finish event has been emitted'; }; diff --git a/t/mojo/reactor_ev.t b/t/mojo/reactor_ev.t index ffd8278ada..dddfde11f1 100644 --- a/t/mojo/reactor_ev.t +++ b/t/mojo/reactor_ev.t @@ -11,7 +11,7 @@ use Mojo::Util qw(steady_time); # Instantiation use_ok 'Mojo::Reactor::EV'; my $reactor = Mojo::Reactor::EV->new; -is ref $reactor, 'Mojo::Reactor::EV', 'right object'; +is ref $reactor, 'Mojo::Reactor::EV', 'right object'; is ref Mojo::Reactor::EV->new, 'Mojo::Reactor::Poll', 'right object'; undef $reactor; is ref Mojo::Reactor::EV->new, 'Mojo::Reactor::EV', 'right object'; @@ -43,19 +43,19 @@ ok !$writable, 'handle is not writable'; my $client = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => $port); $reactor->timer(1 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable'; +ok $readable, 'handle is readable'; ok !$writable, 'handle is not writable'; # Accept my $server = $listen->accept; -ok $reactor->remove($listen), 'removed'; +ok $reactor->remove($listen), 'removed'; ok !$reactor->remove($listen), 'not removed again'; ($readable, $writable) = (); $reactor->io($client => sub { pop() ? $writable++ : $readable++ }); $reactor->again($reactor->timer(0.025 => sub { shift->stop })); $reactor->start; ok !$readable, 'handle is not readable'; -ok $writable, 'handle is writable'; +ok $writable, 'handle is writable'; print $client "hello!\n"; sleep 1; ok $reactor->remove($client), 'removed'; @@ -64,7 +64,7 @@ $reactor->io($server => sub { pop() ? $writable++ : $readable++ }); $reactor->watch($server, 1, 0); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable'; +ok $readable, 'handle is readable'; ok !$writable, 'handle is not writable'; ($readable, $writable) = (); $reactor->watch($server, 1, 1); @@ -82,7 +82,7 @@ ok !$writable, 'handle is not writable'; $reactor->watch($server, 1, 0); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable'; +ok $readable, 'handle is readable'; ok !$writable, 'handle is not writable'; ($readable, $writable) = (); $reactor->io($server => sub { pop() ? $writable++ : $readable++ }); @@ -107,24 +107,24 @@ my $done; ($readable, $writable, $timer, $recurring) = (); $reactor->timer(0.025 => sub { $done = shift->is_running }); $reactor->one_tick while !$done; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; -ok !$timer, 'timer was not triggered'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; +ok !$timer, 'timer was not triggered'; ok $recurring, 'recurring was triggered again'; ($readable, $writable, $timer, $recurring) = (); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; -ok !$timer, 'timer was not triggered'; -ok $recurring, 'recurring was triggered again'; -ok $reactor->remove($id), 'removed'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; +ok !$timer, 'timer was not triggered'; +ok $recurring, 'recurring was triggered again'; +ok $reactor->remove($id), 'removed'; ok !$reactor->remove($id), 'not removed again'; ($readable, $writable, $timer, $recurring) = (); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; ok !$timer, 'timer was not triggered'; ok !$recurring, 'recurring was not triggered again'; ($readable, $writable, $timer, $recurring) = (); @@ -133,9 +133,9 @@ is $reactor->next_tick(sub { $next_tick++ }), undef, 'returned undef'; $id = $reactor->recurring(0 => sub { $recurring++ }); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; -ok !$timer, 'timer was not triggered'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; +ok !$timer, 'timer was not triggered'; ok $recurring, 'recurring was triggered again'; ok $next_tick, 'next tick was triggered'; @@ -172,7 +172,7 @@ my $timer2; $reactor2->recurring(0 => sub { $timer2++ }); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $timer, 'timer was triggered'; +ok $timer, 'timer was triggered'; ok !$timer2, 'timer was not triggered'; $timer = $timer2 = 0; $reactor2->timer(0.025 => sub { shift->stop }); @@ -182,7 +182,7 @@ ok $timer2, 'timer was triggered'; $timer = $timer2 = 0; $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $timer, 'timer was triggered'; +ok $timer, 'timer was triggered'; ok !$timer2, 'timer was not triggered'; $timer = $timer2 = 0; $reactor2->timer(0.025 => sub { shift->stop }); @@ -209,7 +209,7 @@ $two = $reactor->timer( } ); $reactor->start; -is $pair, 2, 'timer pair was triggered'; +is $pair, 2, 'timer pair was triggered'; ok $single, 'single timer was triggered'; ok $last, 'timers were triggered in the right order'; @@ -306,8 +306,8 @@ Mojo::IOLoop->client( ); Mojo::IOLoop->singleton->reactor->start; ok !Mojo::IOLoop->is_running, 'loop is not running'; -like $server_err, qr/^Mojo::IOLoop already running/, 'right error'; -like $client_err, qr/^Mojo::IOLoop already running/, 'right error'; +like $server_err, qr/^Mojo::IOLoop already running/, 'right error'; +like $client_err, qr/^Mojo::IOLoop already running/, 'right error'; ok $server_running, 'loop is running'; ok $client_running, 'loop is running'; diff --git a/t/mojo/reactor_poll.t b/t/mojo/reactor_poll.t index bc2c64fd92..ed43080152 100644 --- a/t/mojo/reactor_poll.t +++ b/t/mojo/reactor_poll.t @@ -9,7 +9,7 @@ use Mojo::Util qw(steady_time); # Instantiation my $reactor = Mojo::Reactor::Poll->new; -is ref $reactor, 'Mojo::Reactor::Poll', 'right object'; +is ref $reactor, 'Mojo::Reactor::Poll', 'right object'; is ref Mojo::Reactor::Poll->new, 'Mojo::Reactor::Poll', 'right object'; undef $reactor; is ref Mojo::Reactor::Poll->new, 'Mojo::Reactor::Poll', 'right object'; @@ -41,19 +41,19 @@ ok !$writable, 'handle is not writable'; my $client = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => $port); $reactor->timer(1 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable'; +ok $readable, 'handle is readable'; ok !$writable, 'handle is not writable'; # Accept my $server = $listen->accept; -ok $reactor->remove($listen), 'removed'; +ok $reactor->remove($listen), 'removed'; ok !$reactor->remove($listen), 'not removed again'; ($readable, $writable) = (); $reactor->io($client => sub { pop() ? $writable++ : $readable++ }); $reactor->again($reactor->timer(0.025 => sub { shift->stop })); $reactor->start; ok !$readable, 'handle is not readable'; -ok $writable, 'handle is writable'; +ok $writable, 'handle is writable'; print $client "hello!\n"; sleep 1; ok $reactor->remove($client), 'removed'; @@ -62,7 +62,7 @@ $reactor->io($server => sub { pop() ? $writable++ : $readable++ }); $reactor->watch($server, 1, 0); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable'; +ok $readable, 'handle is readable'; ok !$writable, 'handle is not writable'; ($readable, $writable) = (); $reactor->watch($server, 1, 1); @@ -80,7 +80,7 @@ ok !$writable, 'handle is not writable'; $reactor->watch($server, 1, 0); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable'; +ok $readable, 'handle is readable'; ok !$writable, 'handle is not writable'; ($readable, $writable) = (); $reactor->io($server => sub { pop() ? $writable++ : $readable++ }); @@ -105,24 +105,24 @@ my $done; ($readable, $writable, $timer, $recurring) = (); $reactor->timer(0.025 => sub { $done = shift->is_running }); $reactor->one_tick while !$done; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; -ok !$timer, 'timer was not triggered'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; +ok !$timer, 'timer was not triggered'; ok $recurring, 'recurring was triggered again'; ($readable, $writable, $timer, $recurring) = (); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; -ok !$timer, 'timer was not triggered'; -ok $recurring, 'recurring was triggered again'; -ok $reactor->remove($id), 'removed'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; +ok !$timer, 'timer was not triggered'; +ok $recurring, 'recurring was triggered again'; +ok $reactor->remove($id), 'removed'; ok !$reactor->remove($id), 'not removed again'; ($readable, $writable, $timer, $recurring) = (); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; ok !$timer, 'timer was not triggered'; ok !$recurring, 'recurring was not triggered again'; ($readable, $writable, $timer, $recurring) = (); @@ -131,9 +131,9 @@ is $reactor->next_tick(sub { $next_tick++ }), undef, 'returned undef'; $id = $reactor->recurring(0 => sub { $recurring++ }); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $readable, 'handle is readable again'; -ok $writable, 'handle is writable again'; -ok !$timer, 'timer was not triggered'; +ok $readable, 'handle is readable again'; +ok $writable, 'handle is writable again'; +ok !$timer, 'timer was not triggered'; ok $recurring, 'recurring was triggered again'; ok $next_tick, 'next tick was triggered'; @@ -170,7 +170,7 @@ my $timer2; $reactor2->recurring(0 => sub { $timer2++ }); $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $timer, 'timer was triggered'; +ok $timer, 'timer was triggered'; ok !$timer2, 'timer was not triggered'; $timer = $timer2 = 0; $reactor2->timer(0.025 => sub { shift->stop }); @@ -180,7 +180,7 @@ ok $timer2, 'timer was triggered'; $timer = $timer2 = 0; $reactor->timer(0.025 => sub { shift->stop }); $reactor->start; -ok $timer, 'timer was triggered'; +ok $timer, 'timer was triggered'; ok !$timer2, 'timer was not triggered'; $timer = $timer2 = 0; $reactor2->timer(0.025 => sub { shift->stop }); @@ -207,7 +207,7 @@ $two = $reactor->timer( } ); $reactor->start; -is $pair, 2, 'timer pair was triggered'; +is $pair, 2, 'timer pair was triggered'; ok $single, 'single timer was triggered'; ok $last, 'timers were triggered in the right order'; @@ -304,8 +304,8 @@ Mojo::IOLoop->client( ); Mojo::IOLoop->singleton->reactor->start; ok !Mojo::IOLoop->is_running, 'loop is not running'; -like $server_err, qr/^Mojo::IOLoop already running/, 'right error'; -like $client_err, qr/^Mojo::IOLoop already running/, 'right error'; +like $server_err, qr/^Mojo::IOLoop already running/, 'right error'; +like $client_err, qr/^Mojo::IOLoop already running/, 'right error'; ok $server_running, 'loop is running'; ok $client_running, 'loop is running'; diff --git a/t/mojo/request.t b/t/mojo/request.t index caf434c49a..fbab5b7974 100644 --- a/t/mojo/request.t +++ b/t/mojo/request.t @@ -32,15 +32,15 @@ subtest 'Parse HTTP 1.1 message with huge "Cookie" header exceeding all limits' $req->parse("PUT /upload HTTP/1.1\x0d\x0aCookie: $huge\x0d\x0a"); ok $req->is_limit_exceeded, 'limit is exceeded'; $req->parse("Content-Length: 0\x0d\x0a\x0d\x0a"); - ok $finished, 'finish event has been emitted'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; - is $req->content->leftovers, '', 'no leftovers'; - is $req->error->{message}, 'Maximum message size exceeded', 'right error'; + is $req->content->leftovers, '', 'no leftovers'; + is $req->error->{message}, 'Maximum message size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - is $req->method, 'PUT', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/upload', 'right URL'; - is $req->cookie('a'), undef, 'no value'; + is $req->method, 'PUT', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/upload', 'right URL'; + is $req->cookie('a'), undef, 'no value'; }; subtest 'Parse HTTP 1.1 message with huge "Cookie" header exceeding line limit' => sub { @@ -53,11 +53,11 @@ subtest 'Parse HTTP 1.1 message with huge "Cookie" header exceeding line limit' ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum header size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; is $req->cookie('a'), undef, 'no value'; - is $req->body, '', 'no content'; + is $req->body, '', 'no content'; }; subtest 'Parse HTTP 1.1 message with huge "Cookie" header exceeding line limit (alternative)' => sub { @@ -67,11 +67,11 @@ subtest 'Parse HTTP 1.1 message with huge "Cookie" header exceeding line limit ( ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum header size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; is $req->cookie('a'), undef, 'no value'; - is $req->body, '', 'no content'; + is $req->body, '', 'no content'; }; subtest 'Parse HTTP 1.1 message with content exceeding line limit' => sub { @@ -80,11 +80,11 @@ subtest 'Parse HTTP 1.1 message with content exceeding line limit' => sub { $req->parse("GET / HTTP/1.1\x0d\x0a"); $req->parse("Content-Length: 655360\x0d\x0a\x0d\x0a@{['a=b; ' x 131072]}"); ok $req->is_finished, 'request is finished'; - is $req->error, undef, 'no error'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; - is $req->body, 'a=b; ' x 131072, 'right content'; + is $req->error, undef, 'no error'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; + is $req->body, 'a=b; ' x 131072, 'right content'; }; subtest 'Parse broken start-line' => sub { @@ -104,25 +104,25 @@ subtest 'Parse broken HTTP 1.1 message with header exceeding line limit' => sub ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum header size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; is $req->headers->header('Foo'), undef, 'no "Foo" value'; - is $req->body, '', 'no content'; + is $req->body, '', 'no content'; }; subtest 'Parse broken HTTP 1.1 message with start-line exceeding line limit' => sub { my $req = Mojo::Message::Request->new; - is $req->max_line_size, 8192, 'right size'; - is $req->headers->max_lines, 100, 'right number'; + is $req->max_line_size, 8192, 'right size'; + is $req->headers->max_lines, 100, 'right number'; $req->parse("GET /@{['abcd' x 131072]} HTTP/1.1"); ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum start-line size exceeded', 'right error'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '', 'no URL'; - is $req->cookie('a'), undef, 'no value'; - is $req->body, '', 'no content'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '', 'no URL'; + is $req->cookie('a'), undef, 'no value'; + is $req->body, '', 'no content'; }; subtest 'Parse broken HTTP 1.1 message with start-line exceeding line limit (alternative)' => sub { @@ -131,11 +131,11 @@ subtest 'Parse broken HTTP 1.1 message with start-line exceeding line limit (alt $req->parse('abcd' x 131072); ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum start-line size exceeded', 'right error'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '', 'no URL'; - is $req->cookie('a'), undef, 'no value'; - is $req->body, '', 'no content'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '', 'no URL'; + is $req->cookie('a'), undef, 'no value'; + is $req->body, '', 'no content'; }; subtest 'Parse pipelined HTTP 1.1 messages exceeding leftover limit' => sub { @@ -156,12 +156,12 @@ subtest 'Parse pipelined HTTP 1.1 messages exceeding leftover limit' => sub { is length($req->content->leftovers), 360138, 'right size'; $req->parse("GET /five HTTP/1.1\x0d\x0a"); $req->parse("Content-Length: 120000\x0d\x0a\x0d\x0a@{['e' x 120000]}"); - is length($req->content->leftovers), 360138, 'right size'; - is $req->error, undef, 'no error'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/one', 'right URL'; - is $req->body, 'a' x 120000, 'right content'; + is length($req->content->leftovers), 360138, 'right size'; + is $req->error, undef, 'no error'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/one', 'right URL'; + is $req->body, 'a' x 120000, 'right content'; }; subtest 'Parse pipelined HTTP 1.1 messages exceeding leftover limit (chunked)' => sub { @@ -186,21 +186,21 @@ subtest 'Parse pipelined HTTP 1.1 messages exceeding leftover limit (chunked)' = is length($req->content->leftovers), 360138, 'right size'; $req->parse("GET /five HTTP/1.1\x0d\x0a"); $req->parse("Content-Length: 120000\x0d\x0a\x0d\x0a@{['e' x 120000]}"); - is length($req->content->leftovers), 360138, 'right size'; - is $req->error, undef, 'no error'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/one', 'right URL'; - is $req->body, 'a' x 120000, 'right content'; + is length($req->content->leftovers), 360138, 'right size'; + is $req->error, undef, 'no error'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/one', 'right URL'; + is $req->body, 'a' x 120000, 'right content'; }; subtest 'Parse HTTP 1.1 start-line, no headers and body' => sub { my $req = Mojo::Message::Request->new; $req->parse("GET / HTTP/1.1\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; }; subtest 'Parse HTTP 1.1 start-line, no headers and body (small chunks)' => sub { @@ -241,9 +241,9 @@ subtest 'Parse HTTP 1.1 start-line, no headers and body (small chunks)' => sub { ok !$req->is_finished, 'request is not finished'; $req->parse("\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; }; subtest 'Parse pipelined HTTP 1.1 start-line, no headers and body' => sub { @@ -257,9 +257,9 @@ subtest 'Parse HTTP 1.1 start-line, no headers and body with leading CRLFs' => s my $req = Mojo::Message::Request->new; $req->parse("\x0d\x0a GET / HTTP/1.1\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; }; subtest 'Parse WebSocket handshake request' => sub { @@ -272,15 +272,15 @@ subtest 'Parse WebSocket handshake request' => sub { $req->parse("Upgrade: websocket\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; ok $req->is_handshake, 'request is WebSocket handshake'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/demo', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/demo', 'right URL'; is $req->headers->host, 'example.com', 'right "Host" value'; is $req->headers->connection, 'Upgrade', 'right "Connection" value'; is $req->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; is $req->headers->upgrade, 'websocket', 'right "Upgrade" value'; is $req->headers->sec_websocket_key, 'abcdef=', 'right "Sec-WebSocket-Key" value'; - is $req->body, '', 'no content'; + is $req->body, '', 'no content'; }; subtest 'Parse HTTP 1.0 start-line and headers, no body' => sub { @@ -288,11 +288,11 @@ subtest 'Parse HTTP 1.0 start-line and headers, no body' => sub { $req->parse("GET /foo/bar/baz.html HTTP/1.0\x0d\x0a"); $req->parse("Content-Type: text/plain;charset=UTF-8\x0d\x0a"); $req->parse("Content-Length: 0\x0d\x0a\x0d\x0a"); - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok !$req->is_handshake, 'request is not a WebSocket handshake'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html', 'right URL'; is $req->headers->content_type, 'text/plain;charset=UTF-8', 'right "Content-Type" value'; is $req->headers->content_length, 0, 'right "Content-Length" value'; is $req->content->charset, 'UTF-8', 'right charset'; @@ -303,11 +303,11 @@ subtest 'Parse HTTP 1.0 start-line and headers, no body (missing Content-Length) $req->parse("GET /foo/bar/baz.html HTTP/1.0\x0d\x0a"); $req->parse("Content-Type: text/plain\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, undef, 'no "Content-Length" value'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, undef, 'no "Content-Length" value'; }; subtest 'Parse full HTTP 1.0 request (file storage)' => sub { @@ -322,7 +322,7 @@ subtest 'Parse full HTTP 1.0 request (file storage)' => sub { } ); is $req->content->asset->max_memory_size, 12, 'right size'; - is $req->content->progress, 0, 'right progress'; + is $req->content->progress, 0, 'right progress'; $req->parse('GET /foo/bar/baz.html?fo'); is $req->content->progress, 0, 'right progress'; $req->parse("o=13 HTTP/1.0\x0d\x0aContent"); @@ -331,22 +331,22 @@ subtest 'Parse full HTTP 1.0 request (file storage)' => sub { $req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell"); is $req->content->progress, 4, 'right progress'; ok !$req->content->asset->is_file, 'stored in memory'; - ok !$upgrade, 'upgrade event has not been emitted'; + ok !$upgrade, 'upgrade event has not been emitted'; $req->parse("o World!\n"); ok $upgrade, 'upgrade event has been emitted'; - is $size, 0, 'file had no content yet'; + is $size, 0, 'file had no content yet'; is $req->content->asset->size, 13, 'file has content'; - is $req->content->progress, 13, 'right progress'; + is $req->content->progress, 13, 'right progress'; ok $req->content->asset->is_file, 'stored in file'; $req->parse("1234\nlalalala\n"); is $req->content->progress, 27, 'right progress'; ok $req->content->asset->is_file, 'stored in file'; - ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, 27, 'right "Content-Length" value'; + ok $req->is_finished, 'request is finished'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, 27, 'right "Content-Length" value'; }; subtest 'Parse HTTP 1.0 start-line and headers, no body (missing Content-Length)' => sub { @@ -355,11 +355,11 @@ subtest 'Parse HTTP 1.0 start-line and headers, no body (missing Content-Length) $req->parse("Content-Type: text/plain\x0d\x0a"); $req->parse("Connection: Close\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, undef, 'no "Content-Length" value'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, undef, 'no "Content-Length" value'; }; subtest 'Parse HTTP 1.0 start-line (with line size limit)' => sub { @@ -373,7 +373,7 @@ subtest 'Parse HTTP 1.0 start-line (with line size limit)' => sub { ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum start-line size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - ok $limit, 'limit is exceeded'; + ok $limit, 'limit is exceeded'; $req->error({message => 'Nothing important.'}); is $req->error->{message}, 'Nothing important.', 'right error'; ok $req->is_limit_exceeded, 'limit is still exceeded'; @@ -400,7 +400,7 @@ subtest 'Parse HTTP 1.0 start-line (with message size limit)' => sub { ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum message size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - ok $limit, 'limit is exceeded'; + ok $limit, 'limit is exceeded'; }; subtest 'Parse HTTP 1.0 start-line and headers (with message size limit)' => sub { @@ -436,9 +436,9 @@ subtest 'Parse HTTP 1.1 message with headers exceeding line limit' => sub { ok $req->is_finished, 'request is finished'; is $req->error->{message}, 'Maximum header size exceeded', 'right error'; ok $req->is_limit_exceeded, 'limit is exceeded'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; }; subtest 'Parse full HTTP 1.0 request (solitary LF)' => sub { @@ -451,13 +451,13 @@ subtest 'Parse full HTTP 1.0 request (solitary LF)' => sub { $req->parse("plain\x0aContent-Length: 27\x0a\x0aH"); $req->parse("ello World!\n1234\nlalalala\n"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, 27, 'right "Content-Length" value'; - is $req->body, "Hello World!\n1234\nlalalala\n", 'right content'; - is $body, "Hello World!\n1234\nlalalala\n", 'right content'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, 27, 'right "Content-Length" value'; + is $req->body, "Hello World!\n1234\nlalalala\n", 'right content'; + is $body, "Hello World!\n1234\nlalalala\n", 'right content'; }; subtest 'Parse full HTTP 1.0 request (no scheme and empty elements in path)' => sub { @@ -468,13 +468,13 @@ subtest 'Parse full HTTP 1.0 request (no scheme and empty elements in path)' => $req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell"); $req->parse("o World!\n1234\nlalalala\n"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url->host, undef, 'no host'; - is $req->url->path, '//foo/bar//baz.html', 'right path'; - is $req->url, '//foo/bar//baz.html?foo=13', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, 27, 'right "Content-Length" value'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url->host, undef, 'no host'; + is $req->url->path, '//foo/bar//baz.html', 'right path'; + is $req->url, '//foo/bar//baz.html?foo=13', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, 27, 'right "Content-Length" value'; }; subtest 'Parse full HTTP 1.0 request (behind reverse proxy)' => sub { @@ -487,9 +487,9 @@ subtest 'Parse full HTTP 1.0 request (behind reverse proxy)' => sub { $req->parse("X-Forwarded-For: 192.168.2.1, 127.0.0.1\x0d\x0a\x0d\x0a"); $req->parse("Hello World!\n1234\nlalalala\n"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; is $req->url->to_abs, 'http://mojolicious.org/foo/bar/baz.html?foo=13', 'right absolute URL'; is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $req->headers->content_length, 27, 'right "Content-Length" value'; @@ -506,13 +506,13 @@ subtest 'Parse full HTTP 1.0 request with zero chunk' => sub { $req->parse("o World!\n123"); $req->parse('0'); $req->parse("\nlalalala\n"); - ok $finished, 'finish event has been emitted'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, 27, 'right "Content-Length" value'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, 27, 'right "Content-Length" value'; }; subtest 'Parse full HTTP 1.0 request with UTF-8 form input' => sub { @@ -524,12 +524,12 @@ subtest 'Parse full HTTP 1.0 request with UTF-8 form input' => sub { $req->parse("\x0d\x0a\x0d\x0a"); $req->parse('name=%E2%98%83'); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; is $req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; is $req->headers->content_length, 14, 'right "Content-Length" value'; - is $req->param('name'), '☃', 'right value'; + is $req->param('name'), '☃', 'right value'; }; subtest 'Parse HTTP 1.1 gzip compressed request (no decompression)' => sub { @@ -542,13 +542,13 @@ subtest 'Parse HTTP 1.1 gzip compressed request (no decompression)' => sub { ok $req->content->is_compressed, 'content is compressed'; $req->parse($compressed); ok $req->content->is_compressed, 'content is still compressed'; - ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + ok $req->is_finished, 'request is finished'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $req->headers->content_length, length($compressed), 'right "Content-Length" value'; - is $req->body, $compressed, 'right content'; + is $req->body, $compressed, 'right content'; }; subtest 'Parse HTTP 1.1 chunked request' => sub { @@ -570,13 +570,13 @@ subtest 'Parse HTTP 1.1 chunked request' => sub { $req->parse("0\x0d\x0a\x0d\x0a"); is $req->content->progress, 28, 'right progress'; ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; - is $req->headers->content_length, 13, 'right "Content-Length" value'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->content->asset->size, 13, 'right size'; - is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->headers->content_length, 13, 'right "Content-Length" value'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->content->asset->size, 13, 'right size'; + is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; }; subtest 'Parse HTTP 1.1 chunked request with callbacks' => sub { @@ -605,12 +605,12 @@ subtest 'Parse HTTP 1.1 chunked request with callbacks' => sub { is $finish, 'foo=13', 'finished'; is $progress, '/foo/bar/baz.html', 'made progress'; ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; - is $req->headers->content_length, 13, 'right "Content-Length" value'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $buffer, 'abcdabcdefghi', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->headers->content_length, 13, 'right "Content-Length" value'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $buffer, 'abcdabcdefghi', 'right content'; }; subtest 'Parse HTTP 1.1 "application/x-www-form-urlencoded"' => sub { @@ -620,17 +620,17 @@ subtest 'Parse HTTP 1.1 "application/x-www-form-urlencoded"' => sub { $req->parse("Content-Type: application/x-www-form-urlencoded\x0d\x0a"); $req->parse("\x0d\x0afoo=bar&+tset=23+&foo=bar"); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; is $req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; - is $req->content->asset->size, 25, 'right size'; - is $req->content->asset->slurp, 'foo=bar&+tset=23+&foo=bar', 'right content'; + is $req->content->asset->size, 25, 'right size'; + is $req->content->asset->slurp, 'foo=bar&+tset=23+&foo=bar', 'right content'; is_deeply $req->body_params->to_hash->{foo}, [qw(bar bar)], 'right values'; - is $req->body_params->to_hash->{' tset'}, '23 ', 'right value'; - is $req->body_params, 'foo=bar&+tset=23+&foo=bar', 'right parameters'; + is $req->body_params->to_hash->{' tset'}, '23 ', 'right value'; + is $req->body_params, 'foo=bar&+tset=23+&foo=bar', 'right parameters'; is_deeply $req->params->to_hash->{foo}, [qw(bar bar 13)], 'right values'; - is_deeply $req->every_param('foo'), [qw(bar bar 13)], 'right values'; + is_deeply $req->every_param('foo'), [qw(bar bar 13)], 'right values'; is $req->param(' tset'), '23 ', 'right value'; $req->param('set', 'single'); is $req->param('set'), 'single', 'setting single param works'; @@ -652,17 +652,17 @@ subtest 'Parse HTTP 1.1 chunked request with trailing headers' => sub { $req->parse("0\x0d\x0a"); $req->parse("X-Trailer1: test\x0d\x0a"); $req->parse("X-Trailer2: 123\x0d\x0a\x0d\x0a"); - ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; - is $req->query_params, 'foo=13&bar=23', 'right parameters'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value'; - is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value'; - is $req->headers->content_length, 13, 'right "Content-Length" value'; - is $req->content->asset->size, 13, 'right size'; - is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; + ok $req->is_finished, 'request is finished'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; + is $req->query_params, 'foo=13&bar=23', 'right parameters'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value'; + is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value'; + is $req->headers->content_length, 13, 'right "Content-Length" value'; + is $req->content->asset->size, 13, 'right size'; + is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; }; subtest 'Parse HTTP 1.1 chunked request with trailing headers (different variation)' => sub { @@ -676,17 +676,17 @@ subtest 'Parse HTTP 1.1 chunked request with trailing headers (different variati $req->parse("9\x0d\x0a"); $req->parse("abcdefghi\x0d\x0a"); $req->parse("0\x0d\x0aX-Trailer: 777\x0d\x0a\x0d\x0aLEFTOVER"); - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; is $req->method, 'POST', 'right method'; is $req->version, '1.1', 'right version'; is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; is $req->query_params, 'foo=13&bar=23', 'right parameters'; ok !defined $req->headers->transfer_encoding, 'no "Transfer-Encoding" value'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->header('X-Trailer'), '777', 'right "X-Trailer" value'; - is $req->headers->content_length, 13, 'right "Content-Length" value'; - is $req->content->asset->size, 13, 'right size'; - is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->header('X-Trailer'), '777', 'right "X-Trailer" value'; + is $req->headers->content_length, 13, 'right "Content-Length" value'; + is $req->content->asset->size, 13, 'right size'; + is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; }; subtest 'Parse HTTP 1.1 chunked request with trailing headers (different variation)' => sub { @@ -700,17 +700,17 @@ subtest 'Parse HTTP 1.1 chunked request with trailing headers (different variati $req->parse("9\x0d\x0a"); $req->parse("abcdefghi\x0d\x0a"); $req->parse("0\x0d\x0aX-Trailer1: test\x0d\x0aX-Trailer2: 123\x0d\x0a\x0d\x0a"); - ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; - is $req->query_params, 'foo=13&bar=23', 'right parameters'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value'; - is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value'; - is $req->headers->content_length, 13, 'right "Content-Length" value'; - is $req->content->asset->size, 13, 'right size'; - is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; + ok $req->is_finished, 'request is finished'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; + is $req->query_params, 'foo=13&bar=23', 'right parameters'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value'; + is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value'; + is $req->headers->content_length, 13, 'right "Content-Length" value'; + is $req->content->asset->size, 13, 'right size'; + is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; }; subtest 'Parse HTTP 1.1 chunked request with trailing headers (no Trailer header)' => sub { @@ -723,17 +723,17 @@ subtest 'Parse HTTP 1.1 chunked request with trailing headers (no Trailer header $req->parse("9\x0d\x0a"); $req->parse("abcdefghi\x0d\x0a"); $req->parse("0\x0d\x0aX-Trailer1: test\x0d\x0aX-Trailer2: 123\x0d\x0a\x0d\x0a"); - ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; - is $req->query_params, 'foo=13&bar=23', 'right parameters'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value'; - is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value'; - is $req->headers->content_length, 13, 'right "Content-Length" value'; - is $req->content->asset->size, 13, 'right size'; - is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; + ok $req->is_finished, 'request is finished'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13&bar=23', 'right URL'; + is $req->query_params, 'foo=13&bar=23', 'right parameters'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value'; + is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value'; + is $req->headers->content_length, 13, 'right "Content-Length" value'; + is $req->content->asset->size, 13, 'right size'; + is $req->content->asset->slurp, 'abcdabcdefghi', 'right content'; }; subtest 'Parse HTTP 1.1 multipart request' => sub { @@ -762,7 +762,7 @@ subtest 'Parse HTTP 1.1 multipart request' => sub { $req->parse("print \"Hello World :)\\n\"\n"); $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--"); is $req->content->progress, 416, 'right progress'; - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok $req->content->is_multipart, 'multipart content'; is $req->body, '', 'no content'; is $req->method, 'GET', 'right method'; @@ -772,14 +772,14 @@ subtest 'Parse HTTP 1.1 multipart request' => sub { is $req->headers->content_type, 'multipart/form-data; boundary=----------0xKhTmLbOuNdArY', 'right "Content-Type" value'; is $req->headers->content_length, 416, 'right "Content-Length" value'; - ok !$req->content->parts->[0]->is_multipart, 'no multipart content'; - ok !$req->content->parts->[1]->is_multipart, 'no multipart content'; - ok !$req->content->parts->[2]->is_multipart, 'no multipart content'; + ok !$req->content->parts->[0]->is_multipart, 'no multipart content'; + ok !$req->content->parts->[1]->is_multipart, 'no multipart content'; + ok !$req->content->parts->[2]->is_multipart, 'no multipart content'; ok !$req->content->parts->[0]->asset->is_file, 'stored in memory'; is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n", 'right content'; - is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; - is $req->body_params->to_hash->{text2}, '', 'right value'; - is $req->upload('upload')->filename, 'hello.pl', 'right filename'; + is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; + is $req->body_params->to_hash->{text2}, '', 'right value'; + is $req->upload('upload')->filename, 'hello.pl', 'right filename'; ok !$req->upload('upload')->asset->is_file, 'stored in memory'; is $req->upload('upload')->asset->size, 69, 'right size'; my $tempdir = tempdir; @@ -829,7 +829,7 @@ subtest 'Parse HTTP 1.1 multipart request (too big for memory)' => sub { $req->parse("=\"bye.txt\"\x0d\x0a"); $req->parse("Content-Type: application/octet-stream\x0d\x0a\x0d\x0a"); $req->parse("Bye!\x0d\x0a------------0xKhTmLbOuNdArY--"); - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok $req->content->is_multipart, 'multipart content'; is $req->body, '', 'no content'; is $req->method, 'GET', 'right method'; @@ -839,19 +839,19 @@ subtest 'Parse HTTP 1.1 multipart request (too big for memory)' => sub { is $req->headers->content_type, 'multipart/form-data; boundary=----------0xKhTmLbOuNdArY', 'right "Content-Type" value'; is $req->headers->content_length, 562, 'right "Content-Length" value'; - ok !$req->content->parts->[0]->is_multipart, 'no multipart content'; - ok !$req->content->parts->[1]->is_multipart, 'no multipart content'; - ok !$req->content->parts->[2]->is_multipart, 'no multipart content'; + ok !$req->content->parts->[0]->is_multipart, 'no multipart content'; + ok !$req->content->parts->[1]->is_multipart, 'no multipart content'; + ok !$req->content->parts->[2]->is_multipart, 'no multipart content'; ok $req->content->parts->[0]->asset->is_file, 'stored in file'; - is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n", 'right content'; - is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; - is $req->body_params->to_hash->{text2}, '', 'right value'; - is $req->upload('upload')->filename, 'bye.txt', 'right filename'; - is $req->upload('upload')->asset->size, 4, 'right size'; - is $req->every_upload('upload')->[0]->filename, 'hello.pl', 'right filename'; + is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n", 'right content'; + is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; + is $req->body_params->to_hash->{text2}, '', 'right value'; + is $req->upload('upload')->filename, 'bye.txt', 'right filename'; + is $req->upload('upload')->asset->size, 4, 'right size'; + is $req->every_upload('upload')->[0]->filename, 'hello.pl', 'right filename'; ok $req->every_upload('upload')->[0]->asset->is_file, 'stored in file'; - is $req->every_upload('upload')->[0]->asset->size, 69, 'right size'; - is $req->every_upload('upload')->[1]->filename, 'bye.txt', 'right filename'; + is $req->every_upload('upload')->[0]->asset->size, 69, 'right size'; + is $req->every_upload('upload')->[1]->filename, 'bye.txt', 'right filename'; ok !$req->every_upload('upload')->[1]->asset->is_file, 'stored in memory'; is $req->every_upload('upload')->[1]->asset->size, 4, 'right size'; }; @@ -909,7 +909,7 @@ subtest 'Parse HTTP 1.1 multipart request (with callbacks and stream)' => sub { $req->parse("print \"Hello World :)\\n\"\n"); is $stream, "#!/usr/bin/perl\n\nuse strict;\nuse war", 'right content'; $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--"); - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok $req->content->is_multipart, 'multipart content'; is $req->method, 'GET', 'right method'; is $req->version, '1.1', 'right version'; @@ -922,8 +922,8 @@ subtest 'Parse HTTP 1.1 multipart request (with callbacks and stream)' => sub { ok !$req->content->parts->[1]->is_multipart, 'no multipart content'; ok !$req->content->parts->[2]->is_multipart, 'no multipart content'; is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n", 'right content'; - is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; - is $req->body_params->to_hash->{text2}, '', 'right value'; + is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; + is $req->body_params->to_hash->{text2}, '', 'right value'; is $stream, "#!/usr/bin/perl\n\n" . "use strict;\n" . "use warnings;\n\n" . "print \"Hello World :)\\n\"\n", 'right content'; }; @@ -949,7 +949,7 @@ subtest 'Parse HTTP 1.1 multipart request (without upgrade)' => sub { $req->parse("use warnings;\n\n"); $req->parse("print \"Hello World :)\\n\"\n"); $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--"); - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok !$req->content->is_multipart, 'no multipart content'; is $req->method, 'GET', 'right method'; is $req->version, '1.1', 'right version'; @@ -982,7 +982,7 @@ subtest 'Parse HTTP 1.1 multipart request with "0" filename' => sub { $req->parse("use warnings;\n\n"); $req->parse("print \"Hello World :)\\n\"\n"); $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--"); - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok $req->content->is_multipart, 'no multipart content'; is $req->method, 'GET', 'right method'; is $req->version, '1.1', 'right version'; @@ -995,10 +995,10 @@ subtest 'Parse HTTP 1.1 multipart request with "0" filename' => sub { ok !$req->content->parts->[1]->is_multipart, 'no multipart content'; ok !$req->content->parts->[2]->is_multipart, 'no multipart content'; is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n", 'right content'; - is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; - is $req->body_params->to_hash->{text2}, '', 'right value'; - is $req->body_params->to_hash->{upload}, undef, 'not a body parameter'; - is $req->upload('upload')->filename, '0', 'right filename'; + is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value'; + is $req->body_params->to_hash->{text2}, '', 'right value'; + is $req->body_params->to_hash->{upload}, undef, 'not a body parameter'; + is $req->upload('upload')->filename, '0', 'right filename'; ok !$req->upload('upload')->asset->is_file, 'stored in memory'; is $req->upload('upload')->asset->size, 69, 'right size'; }; @@ -1012,12 +1012,12 @@ subtest 'Parse full HTTP 1.1 proxy request with basic authentication' => sub { $req->parse("Content-Length: 13\x0d\x0a\x0d\x0a"); $req->parse("Hello World!\n"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url->base, 'http://127.0.0.1', 'right base URL'; - is $req->url->base->userinfo, 'Aladdin:open sesame', 'right base userinfo'; - is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; - is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url->base, 'http://127.0.0.1', 'right base URL'; + is $req->url->base->userinfo, 'Aladdin:open sesame', 'right base userinfo'; + is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; + is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; }; subtest 'Parse full HTTP 1.1 proxy connect request with basic authentication' => sub { @@ -1027,9 +1027,9 @@ subtest 'Parse full HTTP 1.1 proxy connect request with basic authentication' => $req->parse("Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\x0d\x0a"); $req->parse("Content-Length: 0\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'CONNECT', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '//127.0.0.1:3000', 'right URL'; + is $req->method, 'CONNECT', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '//127.0.0.1:3000', 'right URL'; is $req->url->host, '127.0.0.1', 'right host'; is $req->url->port, '3000', 'right port'; is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; @@ -1041,9 +1041,9 @@ subtest 'Build minimal HTTP 1.1 request' => sub { $req->url->parse('http://127.0.0.1/'); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/', 'right absolute URL'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; }; @@ -1055,9 +1055,9 @@ subtest 'Build HTTP 1.1 start-line and header' => sub { $req->headers->expect('100-continue'); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; @@ -1071,17 +1071,17 @@ subtest 'Build HTTP 1.1 start-line and header (with clone)' => sub { my $clone = $req->clone; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; $clone = Mojo::Message::Request->new->parse($clone->to_string); ok $clone->is_finished, 'request is finished'; - is $clone->method, 'GET', 'right method'; - is $clone->version, '1.1', 'right version'; - is $clone->url, '/foo/bar', 'right URL'; + is $clone->method, 'GET', 'right method'; + is $clone->version, '1.1', 'right version'; + is $clone->url, '/foo/bar', 'right URL'; is $clone->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $clone->headers->expect, '100-continue', 'right "Expect" value'; is $clone->headers->host, '127.0.0.1', 'right "Host" value'; @@ -1099,17 +1099,17 @@ subtest 'Build HTTP 1.1 start-line and header (with clone and changes)' => sub { push @{$clone->url->path->parts}, 'baz'; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; $clone = Mojo::Message::Request->new->parse($clone->to_string); ok $clone->is_finished, 'request is finished'; - is $clone->method, 'POST', 'right method'; - is $clone->version, '1.2', 'right version'; - is $clone->url, '/foo/bar/baz', 'right URL'; + is $clone->method, 'POST', 'right method'; + is $clone->version, '1.2', 'right version'; + is $clone->url, '/foo/bar/baz', 'right URL'; is $clone->url->to_abs, 'http://127.0.0.1/foo/bar/baz', 'right absolute URL'; is $clone->headers->expect, 'nothing', 'right "Expect" value'; is $clone->headers->host, '127.0.0.1', 'right "Host" value'; @@ -1125,15 +1125,15 @@ subtest 'Build full HTTP 1.1 request' => sub { $req->body("Hello World!\n"); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; - ok $finished, 'finish event has been emitted'; + is $req->body, "Hello World!\n", 'right content'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; }; @@ -1154,21 +1154,21 @@ subtest 'Build HTTP 1.1 request parts with progress' => sub { $req->url->parse('http://127.0.0.1/foo/bar'); $req->headers->expect('100-continue'); $req->body("Hello World!\n"); - ok !$state, 'no state'; - ok !$progress, 'no progress'; - ok !$finished, 'not finished'; + ok !$state, 'no state'; + ok !$progress, 'no progress'; + ok !$finished, 'not finished'; ok $req->build_start_line, 'built start-line'; is $state, 'start_line', 'made progress on start_line'; ok $progress, 'made progress'; $progress = 0; - ok !$finished, 'not finished'; + ok !$finished, 'not finished'; ok $req->build_headers, 'built headers'; is $state, 'headers', 'made progress on headers'; ok $progress, 'made progress'; $progress = 0; - ok !$finished, 'not finished'; + ok !$finished, 'not finished'; ok $req->build_body, 'built body'; - is $state, 'body', 'made progress on headers'; + is $state, 'body', 'made progress on headers'; ok $progress, 'made progress'; ok $finished, 'finished'; }; @@ -1184,28 +1184,28 @@ subtest 'Build full HTTP 1.1 request (with clone)' => sub { my $clone = $req->clone; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; - ok $finished, 'finish event has been emitted'; + is $req->body, "Hello World!\n", 'right content'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; $finished = undef; $clone = Mojo::Message::Request->new->parse($clone->to_string); ok $clone->is_finished, 'request is finished'; - is $clone->method, 'GET', 'right method'; - is $clone->version, '1.1', 'right version'; - is $clone->url, '/foo/bar', 'right URL'; + is $clone->method, 'GET', 'right method'; + is $clone->version, '1.1', 'right version'; + is $clone->url, '/foo/bar', 'right URL'; is $clone->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $clone->headers->expect, '100-continue', 'right "Expect" value'; is $clone->headers->host, '127.0.0.1', 'right "Host" value'; is $clone->headers->content_length, '13', 'right "Content-Length" value'; - is $clone->body, "Hello World!\n", 'right content'; - ok !$finished, 'finish event has been emitted'; + is $clone->body, "Hello World!\n", 'right content'; + ok !$finished, 'finish event has been emitted'; ok $clone->is_finished, 'request is finished'; }; @@ -1217,28 +1217,28 @@ subtest 'Build full HTTP 1.1 request (roundtrip)' => sub { $req->body("Hello World!\n"); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; my $req2 = Mojo::Message::Request->new->parse($req->to_string); - is $req->content->leftovers, '', 'no leftovers'; - is $req->error, undef, 'no error'; - is $req2->content->leftovers, '', 'no leftovers'; - is $req2->error, undef, 'no error'; + is $req->content->leftovers, '', 'no leftovers'; + is $req->error, undef, 'no error'; + is $req2->content->leftovers, '', 'no leftovers'; + is $req2->error, undef, 'no error'; ok $req2->is_finished, 'request is finished'; - is $req2->method, 'GET', 'right method'; - is $req2->version, '1.1', 'right version'; - is $req2->url, '/foo/bar', 'right URL'; + is $req2->method, 'GET', 'right method'; + is $req2->version, '1.1', 'right version'; + is $req2->url, '/foo/bar', 'right URL'; is $req2->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req2->headers->expect, '100-continue', 'right "Expect" value'; is $req2->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; }; subtest 'Build HTTP 1.1 request body' => sub { @@ -1251,7 +1251,7 @@ subtest 'Build HTTP 1.1 request body' => sub { $req->body("Hello World!\n"); my $i = 0; while (my $chunk = $req->get_body_chunk($i)) { $i += length $chunk } - ok $finished, 'finish event has been emitted'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; }; @@ -1260,13 +1260,13 @@ subtest 'Build HTTP 1.1 POST request without body' => sub { $req->method('POST'); $req->url->parse('http://127.0.0.1/foo/bar'); $req = Mojo::Message::Request->new->parse($req->to_string); - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, 0, 'right "Content-Length" value'; - is $req->body, '', 'no content'; + is $req->body, '', 'no content'; ok $req->is_finished, 'request is finished'; }; @@ -1283,9 +1283,9 @@ subtest 'Build WebSocket handshake request' => sub { $req->headers->upgrade('websocket'); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/demo', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/demo', 'right URL'; is $req->url->to_abs, 'http://example.com/demo', 'right absolute URL'; is $req->headers->connection, 'Upgrade', 'right "Connection" value'; is $req->headers->upgrade, 'websocket', 'right "Upgrade" value'; @@ -1293,8 +1293,8 @@ subtest 'Build WebSocket handshake request' => sub { is $req->headers->content_length, undef, 'no "Content-Length" value'; is $req->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Key" value'; is $req->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $req->body, '', 'no content'; - ok $finished, 'finish event has been emitted'; + is $req->body, '', 'no content'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; }; @@ -1310,9 +1310,9 @@ subtest 'Build WebSocket handshake request (with clone)' => sub { my $clone = $req->clone; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/demo', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/demo', 'right URL'; is $req->url->to_abs, 'http://example.com/demo', 'right absolute URL'; is $req->headers->connection, 'Upgrade', 'right "Connection" value'; is $req->headers->upgrade, 'websocket', 'right "Upgrade" value'; @@ -1320,13 +1320,13 @@ subtest 'Build WebSocket handshake request (with clone)' => sub { is $req->headers->content_length, undef, 'no "Content-Length" value'; is $req->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Key" value'; is $req->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $req->body, '', 'no content'; + is $req->body, '', 'no content'; ok $req->is_finished, 'request is finished'; $clone = Mojo::Message::Request->new->parse($clone->to_string); ok $clone->is_finished, 'request is finished'; - is $clone->method, 'GET', 'right method'; - is $clone->version, '1.1', 'right version'; - is $clone->url, '/demo', 'right URL'; + is $clone->method, 'GET', 'right method'; + is $clone->version, '1.1', 'right version'; + is $clone->url, '/demo', 'right URL'; is $clone->url->to_abs, 'http://example.com/demo', 'right absolute URL'; is $clone->headers->connection, 'Upgrade', 'right "Connection" value'; is $clone->headers->upgrade, 'websocket', 'right "Upgrade" value'; @@ -1334,7 +1334,7 @@ subtest 'Build WebSocket handshake request (with clone)' => sub { is $req->headers->content_length, undef, 'no "Content-Length" value'; is $clone->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Key" value'; is $clone->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $clone->body, '', 'no content'; + is $clone->body, '', 'no content'; ok $clone->is_finished, 'request is finished'; }; @@ -1352,9 +1352,9 @@ subtest 'Build WebSocket handshake proxy request' => sub { $req->proxy(Mojo::URL->new('http://127.0.0.2:8080')); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/demo', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/demo', 'right URL'; is $req->url->to_abs, 'http://example.com/demo', 'right absolute URL'; is $req->headers->connection, 'Upgrade', 'right "Connection" value'; is $req->headers->upgrade, 'websocket', 'right "Upgrade" value'; @@ -1362,8 +1362,8 @@ subtest 'Build WebSocket handshake proxy request' => sub { is $req->headers->content_length, undef, 'no "Content-Length" value'; is $req->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Key" value'; is $req->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $req->body, '', 'no content'; - ok $finished, 'finish event has been emitted'; + is $req->body, '', 'no content'; + ok $finished, 'finish event has been emitted'; ok $req->is_finished, 'request is finished'; }; @@ -1376,14 +1376,14 @@ subtest 'Build full HTTP 1.1 proxy request' => sub { $req->proxy(Mojo::URL->new('http://127.0.0.2:8080')); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; }; subtest 'Build full HTTP 1.1 proxy request (proxy disabled)' => sub { @@ -1394,13 +1394,13 @@ subtest 'Build full HTTP 1.1 proxy request (proxy disabled)' => sub { $req->via_proxy(0)->proxy(Mojo::URL->new('http://127.0.0.2:8080')); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; }; subtest 'Build full HTTP 1.1 proxy request (HTTPS)' => sub { @@ -1412,14 +1412,14 @@ subtest 'Build full HTTP 1.1 proxy request (HTTPS)' => sub { $req->proxy(Mojo::URL->new('http://127.0.0.2:8080')); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->headers->expect, '100-continue', 'right "Expect" value'; is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; }; subtest 'Build full HTTP 1.1 proxy request with basic authentication' => sub { @@ -1431,9 +1431,9 @@ subtest 'Build full HTTP 1.1 proxy request with basic authentication' => sub { $req->proxy(Mojo::URL->new('http://Aladdin:open%20sesame@127.0.0.2:8080')); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; is $req->headers->authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'right "Authorization" value'; @@ -1441,7 +1441,7 @@ subtest 'Build full HTTP 1.1 proxy request with basic authentication' => sub { is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->proxy_authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'right "Proxy-Authorization" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; }; subtest 'Build full HTTP 1.1 proxy request with basic authentication (and clone)' => sub { @@ -1454,9 +1454,9 @@ subtest 'Build full HTTP 1.1 proxy request with basic authentication (and clone) my $clone = $req->clone; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, 'http://127.0.0.1/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; is $req->headers->authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'right "Authorization" value'; @@ -1464,12 +1464,12 @@ subtest 'Build full HTTP 1.1 proxy request with basic authentication (and clone) is $req->headers->host, '127.0.0.1', 'right "Host" value'; is $req->headers->proxy_authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'right "Proxy-Authorization" value'; is $req->headers->content_length, '13', 'right "Content-Length" value'; - is $req->body, "Hello World!\n", 'right content'; + is $req->body, "Hello World!\n", 'right content'; $clone = Mojo::Message::Request->new->parse($clone->to_string); ok $clone->is_finished, 'request is finished'; - is $clone->method, 'GET', 'right method'; - is $clone->version, '1.1', 'right version'; - is $clone->url, 'http://127.0.0.1/foo/bar', 'right URL'; + is $clone->method, 'GET', 'right method'; + is $clone->version, '1.1', 'right version'; + is $clone->url, 'http://127.0.0.1/foo/bar', 'right URL'; is $clone->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is $clone->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; is $clone->headers->authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'right "Authorization" value'; @@ -1477,7 +1477,7 @@ subtest 'Build full HTTP 1.1 proxy request with basic authentication (and clone) is $clone->headers->host, '127.0.0.1', 'right "Host" value'; is $clone->headers->proxy_authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', 'right "Proxy-Authorization" value'; is $clone->headers->content_length, '13', 'right "Content-Length" value'; - is $clone->body, "Hello World!\n", 'right content'; + is $clone->body, "Hello World!\n", 'right content'; }; subtest 'Build full HTTP 1.1 proxy connect request with basic authentication' => sub { @@ -1487,9 +1487,9 @@ subtest 'Build full HTTP 1.1 proxy connect request with basic authentication' => $req->proxy(Mojo::URL->new('http://Aladdin:open%20sesame@127.0.0.2:8080')); $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'CONNECT', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '//xn--bcher-kva.ch:3000', 'right URL'; + is $req->method, 'CONNECT', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '//xn--bcher-kva.ch:3000', 'right URL'; is $req->url->host, 'xn--bcher-kva.ch', 'right host'; is $req->url->port, '3000', 'right port'; is $req->url->to_abs, 'http://xn--bcher-kva.ch:3000', 'right absolute URL'; @@ -1513,14 +1513,14 @@ subtest 'Build HTTP 1.1 multipart request' => sub { push @{$req->content->parts}, $content; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; - is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; - is $req->headers->host, '127.0.0.1', 'right "Host" value'; - is $req->headers->content_length, '106', 'right "Content-Length" value'; - is $req->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; - is $req->content->parts->[0]->asset->slurp, 'Hallo Welt lalalala!', 'right content'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; + is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; + is $req->headers->host, '127.0.0.1', 'right "Host" value'; + is $req->headers->content_length, '106', 'right "Content-Length" value'; + is $req->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; + is $req->content->parts->[0]->asset->slurp, 'Hallo Welt lalalala!', 'right content'; is $req->content->parts->[1]->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $req->content->parts->[1]->asset->slurp, "lala\nfoobar\nperl rocks\n", 'right content'; }; @@ -1540,26 +1540,26 @@ subtest 'Build HTTP 1.1 multipart request (with clone)' => sub { my $clone = $req->clone; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; - is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; - is $req->headers->host, '127.0.0.1', 'right "Host" value'; - is $req->headers->content_length, '106', 'right "Content-Length" value'; - is $req->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; - is $req->content->parts->[0]->asset->slurp, 'Hallo Welt lalalala!', 'right content'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; + is $req->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; + is $req->headers->host, '127.0.0.1', 'right "Host" value'; + is $req->headers->content_length, '106', 'right "Content-Length" value'; + is $req->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; + is $req->content->parts->[0]->asset->slurp, 'Hallo Welt lalalala!', 'right content'; is $req->content->parts->[1]->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $req->content->parts->[1]->asset->slurp, "lala\nfoobar\nperl rocks\n", 'right content'; $clone = Mojo::Message::Request->new->parse($clone->to_string); ok $clone->is_finished, 'request is finished'; - is $clone->method, 'GET', 'right method'; - is $clone->version, '1.1', 'right version'; - is $clone->url, '/foo/bar', 'right URL'; - is $clone->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; - is $clone->headers->host, '127.0.0.1', 'right "Host" value'; - is $clone->headers->content_length, '106', 'right "Content-Length" value'; - is $clone->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; - is $clone->content->parts->[0]->asset->slurp, 'Hallo Welt lalalala!', 'right content'; + is $clone->method, 'GET', 'right method'; + is $clone->version, '1.1', 'right version'; + is $clone->url, '/foo/bar', 'right URL'; + is $clone->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; + is $clone->headers->host, '127.0.0.1', 'right "Host" value'; + is $clone->headers->content_length, '106', 'right "Content-Length" value'; + is $clone->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; + is $clone->content->parts->[0]->asset->slurp, 'Hallo Welt lalalala!', 'right content'; is $clone->content->parts->[1]->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $clone->content->parts->[1]->asset->slurp, "lala\nfoobar\nperl rocks\n", 'right content'; }; @@ -1584,13 +1584,13 @@ subtest 'Build HTTP 1.1 chunked request' => sub { is $req->clone, undef, 'dynamic requests cannot be cloned'; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo/bar', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo/bar', 'right URL'; is $req->url->to_abs, 'http://127.0.0.1:8080/foo/bar', 'right absolute URL'; is $req->headers->host, '127.0.0.1:8080', 'right "Host" value'; is $req->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; - is $req->body, "hello world!hello world2!\n\n", 'right content'; + is $req->body, "hello world!hello world2!\n\n", 'right content'; ok $counter, 'right counter'; }; @@ -1604,13 +1604,13 @@ subtest 'Build HTTP 1.1 chunked request' => sub { is $req->clone, undef, 'dynamic requests cannot be cloned'; $req = Mojo::Message::Request->new->parse($req->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; - is $req->url->to_abs, 'http://127.0.0.1/', 'right absolute URL'; - is $req->headers->host, '127.0.0.1', 'right "Host" value'; - is $req->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; - is $req->body, "hello world!hello world2!\n\n", 'right content'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; + is $req->url->to_abs, 'http://127.0.0.1/', 'right absolute URL'; + is $req->headers->host, '127.0.0.1', 'right "Host" value'; + is $req->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; + is $req->body, "hello world!hello world2!\n\n", 'right content'; }; subtest 'Build full HTTP 1.1 request with cookies' => sub { @@ -1625,22 +1625,22 @@ subtest 'Build full HTTP 1.1 request with cookies' => sub { my $req2 = Mojo::Message::Request->new; $req2->parse($req->to_string); ok $req2->is_finished, 'request is finished'; - is $req2->method, 'GET', 'right method'; - is $req2->version, '1.1', 'right version'; + is $req2->method, 'GET', 'right method'; + is $req2->version, '1.1', 'right version'; is $req2->headers->expect, '100-continue', 'right "Expect" value'; is $req2->headers->host, '127.0.0.1', 'right "Host" value'; is $req2->headers->content_length, 13, 'right "Content-Length" value'; is $req2->headers->cookie, 'foo=bar; bar=baz; baz=yada', 'right "Cookie" value'; - is $req2->url, '/foo/bar?0', 'right URL'; - is $req2->url->to_abs, 'http://127.0.0.1/foo/bar?0', 'right absolute URL'; + is $req2->url, '/foo/bar?0', 'right URL'; + is $req2->url->to_abs, 'http://127.0.0.1/foo/bar?0', 'right absolute URL'; ok defined $req2->cookie('foo'), 'cookie "foo" exists'; ok defined $req2->cookie('bar'), 'cookie "bar" exists'; ok defined $req2->cookie('baz'), 'cookie "baz" exists'; ok !defined $req2->cookie('yada'), 'cookie "yada" does not exist'; - is $req2->cookie('foo')->value, 'bar', 'right value'; - is $req2->cookie('bar')->value, 'baz', 'right value'; - is $req2->cookie('baz')->value, 'yada', 'right value'; - is $req2->body, "Hello World!\n", 'right content'; + is $req2->cookie('foo')->value, 'bar', 'right value'; + is $req2->cookie('bar')->value, 'baz', 'right value'; + is $req2->cookie('baz')->value, 'yada', 'right value'; + is $req2->body, "Hello World!\n", 'right content'; }; subtest 'Build HTTP 1.1 request with cookies sharing the same name' => sub { @@ -1656,14 +1656,14 @@ subtest 'Build HTTP 1.1 request with cookies sharing the same name' => sub { my $req2 = Mojo::Message::Request->new; $req2->parse($req->to_string); ok $req2->is_finished, 'request is finished'; - is $req2->method, 'GET', 'right method'; - is $req2->version, '1.1', 'right version'; + is $req2->method, 'GET', 'right method'; + is $req2->version, '1.1', 'right version'; is $req2->headers->host, '127.0.0.1', 'right "Host" value'; is $req2->headers->cookie, 'foo=bar; foo=baz; foo=yada; bar=foo', 'right "Cookie" value'; - is $req2->url, '/foo/bar', 'right URL'; - is $req2->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; + is $req2->url, '/foo/bar', 'right URL'; + is $req2->url->to_abs, 'http://127.0.0.1/foo/bar', 'right absolute URL'; is_deeply [map { $_->value } @{$req2->every_cookie('foo')}], [qw(bar baz yada)], 'right values'; - is_deeply [map { $_->value } @{$req2->every_cookie('bar')}], ['foo'], 'right values'; + is_deeply [map { $_->value } @{$req2->every_cookie('bar')}], ['foo'], 'right values'; }; subtest 'Parse full HTTP 1.0 request with cookies and progress callback' => sub { @@ -1672,45 +1672,45 @@ subtest 'Parse full HTTP 1.0 request with cookies and progress callback' => sub $req->on(progress => sub { $counter++ }); is $counter, 0, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse('GET /foo/bar/baz.html?fo'); is $counter, 1, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse("o=13 HTTP/1.0\x0d\x0aContent"); is $counter, 2, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse('-Type: text/'); is $counter, 3, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse("plain\x0d\x0a"); is $counter, 4, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse('Cookie: foo=bar; bar=baz'); is $counter, 5, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse("\x0d\x0a"); is $counter, 6, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse("Content-Length: 27\x0d\x0a\x0d\x0aHell"); is $counter, 7, 'right count'; ok $req->content->is_parsing_body, 'is parsing body'; - ok !$req->is_finished, 'request is not finished'; + ok !$req->is_finished, 'request is not finished'; $req->parse("o World!\n1234\nlalalala\n"); is $counter, 8, 'right count'; ok !$req->content->is_parsing_body, 'is not parsing body'; - ok $req->is_finished, 'request is finished'; - ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, 27, 'right "Content-Length" value'; + ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/foo/bar/baz.html?foo=13', 'right URL'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, 27, 'right "Content-Length" value'; my $cookies = $req->cookies; is $cookies->[0]->name, 'foo', 'right name'; is $cookies->[0]->value, 'bar', 'right value'; @@ -1734,29 +1734,29 @@ subtest 'Parse and clone multipart/form-data request (changing size)' => sub { $req->parse("\x0aContent-Disposition: form-data; name=\"Text\"\x0a"); $req->parse("\x0d\x0a\x0d\x0a------WebKitFormBoundaryi5BnD9J9zoTMiSuP--"); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/example/testform_handler', 'right URL'; - is $req->headers->content_length, 318, 'right "Content-Length" value'; - is $req->param('Vorname'), 'T', 'right value'; - is $req->param('Zuname'), '', 'right value'; - is $req->param('Text'), '', 'right value'; - is $req->content->parts->[0]->asset->slurp, 'T', 'right content'; - is $req->content->leftovers, '', 'no leftovers'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/example/testform_handler', 'right URL'; + is $req->headers->content_length, 318, 'right "Content-Length" value'; + is $req->param('Vorname'), 'T', 'right value'; + is $req->param('Zuname'), '', 'right value'; + is $req->param('Text'), '', 'right value'; + is $req->content->parts->[0]->asset->slurp, 'T', 'right content'; + is $req->content->leftovers, '', 'no leftovers'; $req = Mojo::Message::Request->new->parse($req->clone->to_string); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/example/testform_handler', 'right URL'; - is $req->headers->content_length, 323, 'right "Content-Length" value'; - is $req->param('Vorname'), 'T', 'right value'; - is $req->param('Zuname'), '', 'right value'; - is $req->param('Text'), '', 'right value'; - is $req->content->parts->[0]->asset->slurp, 'T', 'right content'; - is $req->content->leftovers, '', 'no leftovers'; - is $req->content->get_body_chunk(322), "\x0a", 'right chunk'; - is $req->content->get_body_chunk(321), "\x0d\x0a", 'right chunk'; - is $req->content->get_body_chunk(320), "-\x0d\x0a", 'right chunk'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/example/testform_handler', 'right URL'; + is $req->headers->content_length, 323, 'right "Content-Length" value'; + is $req->param('Vorname'), 'T', 'right value'; + is $req->param('Zuname'), '', 'right value'; + is $req->param('Text'), '', 'right value'; + is $req->content->parts->[0]->asset->slurp, 'T', 'right content'; + is $req->content->leftovers, '', 'no leftovers'; + is $req->content->get_body_chunk(322), "\x0a", 'right chunk'; + is $req->content->get_body_chunk(321), "\x0d\x0a", 'right chunk'; + is $req->content->get_body_chunk(320), "-\x0d\x0a", 'right chunk'; }; subtest 'Parse multipart/form-data request with charset' => sub { @@ -1777,11 +1777,11 @@ subtest 'Parse multipart/form-data request with charset' => sub { . "Host: 127.0.0.1:3000\x0d\x0a\x0d\x0a" . $multipart); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/example/yatta', 'right URL'; - is $req->param($yatta), $yatta, 'right value'; - is $req->content->parts->[0]->asset->slurp, $yatta_sjis, 'right content'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/example/yatta', 'right URL'; + is $req->param($yatta), $yatta, 'right value'; + is $req->content->parts->[0]->asset->slurp, $yatta_sjis, 'right content'; }; subtest 'WebKit multipart/form-data request' => sub { @@ -1804,13 +1804,13 @@ subtest 'WebKit multipart/form-data request' => sub { ok !$req->is_finished, 'request is not finished'; $req->parse("\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/example/testform_handler', 'right URL'; - is $req->param('Vorname'), 'T', 'right value'; - is $req->param('Zuname'), '', 'right value'; - is $req->param('Text'), '', 'right value'; - is $req->content->parts->[0]->asset->slurp, 'T', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/example/testform_handler', 'right URL'; + is $req->param('Vorname'), 'T', 'right value'; + is $req->param('Zuname'), '', 'right value'; + is $req->param('Text'), '', 'right value'; + is $req->content->parts->[0]->asset->slurp, 'T', 'right content'; }; subtest 'Chrome 35 multipart/form-data request (with quotation marks)' => sub { @@ -1836,9 +1836,9 @@ subtest 'Chrome 35 multipart/form-data request (with quotation marks)' => sub { $req->parse("\x0d\x0a\x0d\x0atest\x0d\x0a"); $req->parse("------WebKitFormBoundaryMTelhBLWA9N3KXAR--\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; is $req->upload('foo \\%22bar%22 baz\\')->filename, 'fo\\%22o%22.txt\\', 'right filename'; is $req->upload('foo \\%22bar%22 baz\\')->slurp, 'test', 'right content'; }; @@ -1865,9 +1865,9 @@ subtest 'Firefox 24 multipart/form-data request (with quotation marks)' => sub { $req->parse('-----------------------------2077320124187767'); $req->parse("4789807986058--\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/', 'right URL'; is $req->upload('foo \\\"bar\" baz')->filename, 'fo\\\\"o\\".txt', 'right filename'; is $req->upload('foo \\\"bar\" baz')->slurp, 'test', 'right content'; }; @@ -1914,9 +1914,9 @@ subtest 'Chrome 5 multipart/form-data request (UTF-8)' => sub { . "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3\x0d\x0a\x0d\x0a" . $chrome); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/', 'right URL'; is $req->cookie('mojolicious')->value, 'BAcIMTIzNDU2NzgECAgIAwIAAAAXDGFsZXgudm9yb25vdgQAAAB1c2VyBp6FjksAAAAABwA' . 'AAGV4cGlyZXM=--1641adddfe885276cda0deb7475f153a', 'right value'; like $req->headers->content_type, qr!multipart/form-data!, 'right "Content-Type" value'; @@ -1927,12 +1927,12 @@ subtest 'Chrome 5 multipart/form-data request (UTF-8)' => sub { is $req->param('phone'), '1234567890', 'right value'; is $req->param('submit'), 'Сохранить', 'right value'; my $upload = $req->upload('avatar'); - is $upload->isa('Mojo::Upload'), 1, 'right upload'; - is $upload->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; - is $upload->filename, 'аватар.jpg', 'right filename'; - is $upload->size, 4, 'right size'; - is $upload->slurp, '1234', 'right content'; - is $req->content->parts->[0]->asset->slurp, $fname, 'right content'; + is $upload->isa('Mojo::Upload'), 1, 'right upload'; + is $upload->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; + is $upload->filename, 'аватар.jpg', 'right filename'; + is $upload->size, 4, 'right size'; + is $upload->slurp, '1234', 'right content'; + is $req->content->parts->[0]->asset->slurp, $fname, 'right content'; }; subtest 'Firefox 3.5.8 multipart/form-data request (UTF-8)' => sub { @@ -1981,9 +1981,9 @@ subtest 'Firefox 3.5.8 multipart/form-data request (UTF-8)' => sub { . "Content-Length: @{[length $firefox]}\x0d\x0a\x0d\x0a" . $firefox); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/', 'right URL'; is $req->cookie('mojolicious')->value, 'BAcIMTIzNDU2NzgECAgIAwIAAAAXDGFsZXgudm9yb25vdgQAAAB1c2VyBiWFjksAAAAABwA' . 'AAGV4cGlyZXM=--cd933a37999e0fa8d7804205e89193a7', 'right value'; like $req->headers->content_type, qr!multipart/form-data!, 'right "Content-Type" value'; @@ -1994,12 +1994,12 @@ subtest 'Firefox 3.5.8 multipart/form-data request (UTF-8)' => sub { is $req->param('phone'), '1234567890', 'right value'; is $req->param('submit'), 'Сохранить', 'right value'; my $upload = $req->upload('avatar'); - is $upload->isa('Mojo::Upload'), 1, 'right upload'; - is $upload->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; - is $upload->filename, 'аватар.jpg', 'right filename'; - is $upload->size, 4, 'right size'; - is $upload->slurp, '1234', 'right content'; - is $req->content->parts->[0]->asset->slurp, $fname, 'right content'; + is $upload->isa('Mojo::Upload'), 1, 'right upload'; + is $upload->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; + is $upload->filename, 'аватар.jpg', 'right filename'; + is $upload->size, 4, 'right size'; + is $upload->slurp, '1234', 'right content'; + is $req->content->parts->[0]->asset->slurp, $fname, 'right content'; }; subtest 'Opera 9.8 multipart/form-data request (UTF-8)' => sub { @@ -2044,9 +2044,9 @@ subtest 'Opera 9.8 multipart/form-data request (UTF-8)' => sub { . "8xwSn56f0\x0d\x0a\x0d\x0a" . $opera); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.0', 'right version'; - is $req->url, '/', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.0', 'right version'; + is $req->url, '/', 'right URL'; is $req->cookie('mojolicious')->value, 'BAcIMTIzNDU2NzgECAgIAwIAAAAXDGFsZXgudm9yb25vdgQAAAB1c2VyBhaIjksAAAAABwA' . 'AAGV4cGlyZXM=--78a58a94f98ae5b75a489be1189f2672', 'right value'; like $req->headers->content_type, qr!multipart/form-data!, 'right "Content-Type" value'; @@ -2057,12 +2057,12 @@ subtest 'Opera 9.8 multipart/form-data request (UTF-8)' => sub { is $req->param('phone'), '1234567890', 'right value'; is $req->param('submit'), 'Сохранить', 'right value'; my $upload = $req->upload('avatar'); - is $upload->isa('Mojo::Upload'), 1, 'right upload'; - is $upload->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; - is $upload->filename, 'аватар.jpg', 'right filename'; - is $upload->size, 4, 'right size'; - is $upload->slurp, '1234', 'right content'; - is $req->content->parts->[0]->asset->slurp, $fname, 'right content'; + is $upload->isa('Mojo::Upload'), 1, 'right upload'; + is $upload->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; + is $upload->filename, 'аватар.jpg', 'right filename'; + is $upload->size, 4, 'right size'; + is $upload->slurp, '1234', 'right content'; + is $req->content->parts->[0]->asset->slurp, $fname, 'right content'; }; subtest 'Firefox 14 multipart/form-data request (UTF-8)' => sub { @@ -2089,34 +2089,34 @@ subtest 'Firefox 14 multipart/form-data request (UTF-8)' => sub { $req->parse("Content-Length: @{[length $firefox]}\x0d\x0a\x0d\x0a"); $req->parse($firefox); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/foo', 'right URL'; + is $req->method, 'POST', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/foo', 'right URL'; like $req->headers->content_type, qr!multipart/form-data!, 'right "Content-Type" value'; - is $req->upload('☃')->name, '☃', 'right name'; - is $req->upload('☃')->filename, 'foo bär ☃.txt', 'right filename'; - is $req->upload('☃')->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->upload('☃')->asset->size, 8, 'right size'; - is $req->upload('☃')->asset->slurp, 'test 123', 'right content'; + is $req->upload('☃')->name, '☃', 'right name'; + is $req->upload('☃')->filename, 'foo bär ☃.txt', 'right filename'; + is $req->upload('☃')->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->upload('☃')->asset->size, 8, 'right size'; + is $req->upload('☃')->asset->slurp, 'test 123', 'right content'; }; subtest 'Parse "~" in URL' => sub { my $req = Mojo::Message::Request->new; $req->parse("GET /~foobar/ HTTP/1.1\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/~foobar/', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/~foobar/', 'right URL'; }; subtest 'Parse ":" in URL' => sub { my $req = Mojo::Message::Request->new; $req->parse("GET /perldoc?Mojo::Message::Request HTTP/1.1\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, '/perldoc?Mojo::Message::Request', 'right URL'; - is $req->url->query->pairs->[0], 'Mojo::Message::Request', 'right value'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, '/perldoc?Mojo::Message::Request', 'right URL'; + is $req->url->query->pairs->[0], 'Mojo::Message::Request', 'right value'; }; subtest 'Parse lots of special characters in URL' => sub { @@ -2124,9 +2124,9 @@ subtest 'Parse lots of special characters in URL' => sub { $req->parse("GET /09azAZ!\$%&'()*+,-./:;=?@[\\]^_`{|}~\xC3\x9F#abc "); $req->parse("HTTP/1.1\x0d\x0a\x0d\x0a"); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->version, '1.1', 'right version'; - is $req->url, "/09azAZ!\$%&'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~%C3%83%C2%9F", 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->version, '1.1', 'right version'; + is $req->url, "/09azAZ!\$%&'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~%C3%83%C2%9F", 'right URL'; }; subtest 'Abstract methods' => sub { diff --git a/t/mojo/request_cgi.t b/t/mojo/request_cgi.t index 587eff19d3..a9a4401943 100644 --- a/t/mojo/request_cgi.t +++ b/t/mojo/request_cgi.t @@ -23,15 +23,15 @@ subtest 'Parse Lighttpd CGI environment variables and body' => sub { $req->parse('World'); is $body, 1, 'body event has been emitted once'; ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->url->path, 'foo/bar', 'right path'; + is $req->method, 'POST', 'right method'; + is $req->url->path, 'foo/bar', 'right path'; is $req->url->base->path, '/te+st/index.cgi/', 'right base path'; is $req->url->base->host, 'localhost', 'right base host'; is $req->url->base->port, 8080, 'right base port'; - is $req->url->query, 'lalala=23&bar=baz', 'right query'; - is $req->version, '1.0', 'right version'; - is $req->headers->dnt, 1, 'right "DNT" value'; - is $req->body, 'Hello World', 'right content'; + is $req->url->query, 'lalala=23&bar=baz', 'right query'; + is $req->version, '1.0', 'right version'; + is $req->headers->dnt, 1, 'right "DNT" value'; + is $req->body, 'Hello World', 'right content'; is $req->url->to_abs->to_string, 'http://localhost:8080/te+st/index.cgi/foo/bar?lalala=23&bar=baz', 'right absolute URL'; }; @@ -51,15 +51,15 @@ subtest 'Parse Lighttpd CGI environment variables and body (behind reverse proxy }); $req->parse('Hello World'); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->url->path, 'foo/bar', 'right path'; - is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->url->base->host, 'mojolicious.org', 'right base host'; - is $req->url->base->port, undef, 'no base port'; - is $req->url->query, 'lalala=23&bar=baz', 'right query'; - is $req->version, '1.0', 'right version'; - is $req->headers->dnt, 1, 'right "DNT" value'; - is $req->body, 'Hello World', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->url->path, 'foo/bar', 'right path'; + is $req->url->base->path, '/test/index.cgi/', 'right base path'; + is $req->url->base->host, 'mojolicious.org', 'right base host'; + is $req->url->base->port, undef, 'no base port'; + is $req->url->query, 'lalala=23&bar=baz', 'right query'; + is $req->version, '1.0', 'right version'; + is $req->headers->dnt, 1, 'right "DNT" value'; + is $req->body, 'Hello World', 'right content'; is $req->url->to_abs->to_string, 'http://mojolicious.org/test/index.cgi/foo/bar?lalala=23&bar=baz', 'right absolute URL'; }; @@ -79,15 +79,15 @@ subtest 'Parse Apache CGI environment variables and body' => sub { }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->url->path, 'foo/bar', 'right path'; - is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->base->port, 8080, 'right base port'; - is $req->url->query, 'lalala=23&bar=baz', 'right query'; - is $req->version, '1.0', 'right version'; - is $req->headers->dnt, 1, 'right "DNT" value'; - is $req->body, 'hello=world', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->url->path, 'foo/bar', 'right path'; + is $req->url->base->path, '/test/index.cgi/', 'right base path'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->base->port, 8080, 'right base port'; + is $req->url->query, 'lalala=23&bar=baz', 'right query'; + is $req->version, '1.0', 'right version'; + is $req->headers->dnt, 1, 'right "DNT" value'; + is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right value'; is $req->url->to_abs->to_string, 'http://localhost:8080/test/index.cgi/foo/bar?lalala=23&bar=baz', 'right absolute URL'; @@ -117,21 +117,21 @@ subtest 'Parse Apache CGI environment variables and body (file storage)' => sub is $req->content->progress, 6, 'right progress'; $req->parse('World!'); ok !$req->content->is_parsing_body, 'is not parsing body'; - ok $req->content->asset->is_file, 'stored in file'; + ok $req->content->asset->is_file, 'stored in file'; is $req->content->progress, 12, 'right progress'; - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok !$req->content->is_multipart, 'no multipart content'; - is $req->method, 'POST', 'right method'; - is $req->url->path, 'foo/bar', 'right path'; - is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->base->port, 8080, 'right base port'; - is $req->url->query, 'lalala=23&bar=baz', 'right query'; - is $req->version, '1.1', 'right version'; - is $req->headers->dnt, 1, 'right "DNT" value'; - is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $req->headers->content_length, 12, 'right "Content-Length" value'; - is $req->body, 'Hello World!', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->url->path, 'foo/bar', 'right path'; + is $req->url->base->path, '/test/index.cgi/', 'right base path'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->base->port, 8080, 'right base port'; + is $req->url->query, 'lalala=23&bar=baz', 'right query'; + is $req->version, '1.1', 'right version'; + is $req->headers->dnt, 1, 'right "DNT" value'; + is $req->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $req->headers->content_length, 12, 'right "Content-Length" value'; + is $req->body, 'Hello World!', 'right content'; is $req->url->to_abs->to_string, 'http://localhost:8080/test/index.cgi/foo/bar?lalala=23&bar=baz', 'right absolute URL'; }; @@ -153,22 +153,22 @@ subtest 'Parse Apache CGI environment variables with basic authentication' => su }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->url->path, 'foo/bar', 'right path'; - is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->base->port, 8080, 'right base port'; - is $req->url->query, 'lalala=23&bar=baz', 'right query'; - is $req->version, '1.0', 'right version'; - is $req->headers->dnt, 1, 'right "DNT" value'; - is $req->body, 'hello=world', 'right content'; + is $req->method, 'POST', 'right method'; + is $req->url->path, 'foo/bar', 'right path'; + is $req->url->base->path, '/test/index.cgi/', 'right base path'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->base->port, 8080, 'right base port'; + is $req->url->query, 'lalala=23&bar=baz', 'right query'; + is $req->version, '1.0', 'right version'; + is $req->headers->dnt, 1, 'right "DNT" value'; + is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right value'; is $req->url->to_abs->to_string, 'http://localhost:8080/test/index.cgi/foo/bar?lalala=23&bar=baz', 'right absolute URL'; - is $req->url->base, 'http://localhost:8080/test/index.cgi/', 'right base URL'; - is $req->url->base->userinfo, 'Aladdin:open sesame', 'right userinfo'; - is $req->url, 'foo/bar?lalala=23&bar=baz', 'right URL'; - is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; + is $req->url->base, 'http://localhost:8080/test/index.cgi/', 'right base URL'; + is $req->url->base->userinfo, 'Aladdin:open sesame', 'right userinfo'; + is $req->url, 'foo/bar?lalala=23&bar=baz', 'right URL'; + is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo'; }; subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { @@ -190,12 +190,12 @@ subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { SERVER_PROTOCOL => 'HTTP/1.1' }); ok !$finished, 'not finished'; - ok $progress, 'made progress'; + ok $progress, 'made progress'; $progress = 0; is $req->content->progress, 0, 'right progress'; $req->parse('request=&ajax=true&login=test&password=111&'); ok !$finished, 'not finished'; - ok $progress, 'made progress'; + ok $progress, 'made progress'; $progress = 0; is $req->content->progress, 43, 'right progress'; $req->parse('edition=db6d8b30-16df-4ecd-be2f-c8194f94e1f4'); @@ -203,8 +203,8 @@ subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { ok $progress, 'made progress'; is $req->content->progress, 87, 'right progress'; ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->url->path, '', 'no path'; + is $req->method, 'POST', 'right method'; + is $req->url->path, '', 'no path'; is $req->url->base->path, '/index.pl/', 'right base path'; is $req->url->base->host, 'test1', 'right base host'; is $req->url->base->port, undef, 'no base port'; @@ -212,11 +212,11 @@ subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { is $req->version, '1.1', 'right version'; is $req->body, 'request=&ajax=true&login=test&password=111&' . 'edition=db6d8b30-16df-4ecd-be2f-c8194f94e1f4', 'right content'; - is $req->param('ajax'), 'true', 'right value'; - is $req->param('login'), 'test', 'right value'; - is $req->param('password'), '111', 'right value'; - is $req->param('edition'), 'db6d8b30-16df-4ecd-be2f-c8194f94e1f4', 'right value'; - is $req->url->to_abs->to_string, 'http://test1/index.pl/', 'right absolute URL'; + is $req->param('ajax'), 'true', 'right value'; + is $req->param('login'), 'test', 'right value'; + is $req->param('password'), '111', 'right value'; + is $req->param('edition'), 'db6d8b30-16df-4ecd-be2f-c8194f94e1f4', 'right value'; + is $req->url->to_abs->to_string, 'http://test1/index.pl/', 'right absolute URL'; }; subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { @@ -234,8 +234,8 @@ subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { $req->parse('request=&ajax=true&login=test&password=111&'); $req->parse('edition=db6d8b30-16df-4ecd-be2f-c8194f94e1f4'); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; - is $req->url->path, '', 'no path'; + is $req->method, 'POST', 'right method'; + is $req->url->path, '', 'no path'; is $req->url->base->path, '/index.pl/', 'right base path'; is $req->url->base->host, 'test1', 'right base host'; is $req->url->base->port, undef, 'no base port'; @@ -243,11 +243,11 @@ subtest 'Parse Apache 2.2 (win32) CGI environment variables and body' => sub { is $req->version, '1.1', 'right version'; is $req->body, 'request=&ajax=true&login=test&password=111&' . 'edition=db6d8b30-16df-4ecd-be2f-c8194f94e1f4', 'right content'; - is $req->param('ajax'), 'true', 'right value'; - is $req->param('login'), 'test', 'right value'; - is $req->param('password'), '111', 'right value'; - is $req->param('edition'), 'db6d8b30-16df-4ecd-be2f-c8194f94e1f4', 'right value'; - is $req->url->to_abs->to_string, 'http://test1/index.pl/', 'right absolute URL'; + is $req->param('ajax'), 'true', 'right value'; + is $req->param('login'), 'test', 'right value'; + is $req->param('password'), '111', 'right value'; + is $req->param('edition'), 'db6d8b30-16df-4ecd-be2f-c8194f94e1f4', 'right value'; + is $req->url->to_abs->to_string, 'http://test1/index.pl/', 'right absolute URL'; }; subtest 'Parse Apache 2.2.14 CGI environment variables and body (root)' => sub { @@ -279,12 +279,12 @@ subtest 'Parse Apache 2.2.14 CGI environment variables and body (root)' => sub { }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'POST', 'right method'; + is $req->method, 'POST', 'right method'; is $req->url->base->host, '127.0.0.1', 'right base host'; is $req->url->base->port, 13028, 'right base port'; - is $req->url->path, '', 'no path'; - is $req->url->base->path, '/upload/', 'right base path'; - is $req->version, '1.1', 'right version'; + is $req->url->path, '', 'no path'; + is $req->url->base->path, '/upload/', 'right base path'; + is $req->version, '1.1', 'right version'; ok !$req->is_secure, 'not secure'; is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right parameters'; @@ -306,13 +306,13 @@ subtest 'Parse Apache 2.2.11 CGI environment variables and body (HTTPS=ON)' => s }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->path, 'foo/bar', 'right path'; + is $req->method, 'GET', 'right method'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->path, 'foo/bar', 'right path'; is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->version, '1.0', 'right version'; + is $req->version, '1.0', 'right version'; ok $req->is_secure, 'is secure'; - is $req->body, 'hello=world', 'right content'; + is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right parameters'; is $req->url->to_abs->to_string, 'https://localhost/test/index.cgi/foo/bar', 'right absolute URL'; }; @@ -331,12 +331,12 @@ subtest 'Parse Apache 2.2.11 CGI environment variables and body (trailing slash) }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->path, 'foo/bar/', 'right path'; + is $req->method, 'GET', 'right method'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->path, 'foo/bar/', 'right path'; is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->version, '1.0', 'right version'; - is $req->body, 'hello=world', 'right content'; + is $req->version, '1.0', 'right version'; + is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right parameters'; is $req->url->to_abs->to_string, 'http://localhost/test/index.cgi/foo/bar/', 'right absolute URL'; }; @@ -354,12 +354,12 @@ subtest 'Parse Apache 2.2.11 CGI environment variables and body (no SCRIPT_NAME) }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->path, '/foo/bar', 'right path'; - is $req->url->base->path, '', 'no base path'; - is $req->version, '1.0', 'right version'; - is $req->body, 'hello=world', 'right content'; + is $req->method, 'GET', 'right method'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->path, '/foo/bar', 'right path'; + is $req->url->base->path, '', 'no base path'; + is $req->version, '1.0', 'right version'; + is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right parameters'; is $req->url->to_abs->to_string, 'http://localhost/foo/bar', 'right absolute URL'; }; @@ -377,12 +377,12 @@ subtest 'Parse Apache 2.2.11 CGI environment variables and body (no PATH_INFO)' }); $req->parse('hello=world'); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->url->base->host, 'localhost', 'right base host'; - is $req->url->path, '', 'no path'; + is $req->method, 'GET', 'right method'; + is $req->url->base->host, 'localhost', 'right base host'; + is $req->url->path, '', 'no path'; is $req->url->base->path, '/test/index.cgi/', 'right base path'; - is $req->version, '1.0', 'right version'; - is $req->body, 'hello=world', 'right content'; + is $req->version, '1.0', 'right version'; + is $req->body, 'hello=world', 'right content'; is_deeply $req->param('hello'), 'world', 'right parameters'; is $req->url->to_abs->to_string, 'http://localhost/test/index.cgi/', 'right absolute URL'; }; @@ -399,11 +399,11 @@ subtest 'Parse Apache 2.2.9 CGI environment variables (root without PATH_INFO)' SERVER_PROTOCOL => 'HTTP/1.1', }); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->url->base->host, 'getmyapp.org', 'right base host'; - is $req->url->path, '', 'no path'; - is $req->url->base->path, '/cgi-bin/myapp/myapp.pl/', 'right base path'; - is $req->version, '1.1', 'right version'; + is $req->method, 'GET', 'right method'; + is $req->url->base->host, 'getmyapp.org', 'right base host'; + is $req->url->path, '', 'no path'; + is $req->url->base->path, '/cgi-bin/myapp/myapp.pl/', 'right base path'; + is $req->version, '1.1', 'right version'; is $req->url->to_abs->to_string, 'http://getmyapp.org/cgi-bin/myapp/myapp.pl/', 'right absolute URL'; }; @@ -446,13 +446,13 @@ subtest 'Parse Apache mod_fastcgi CGI environment variables (multipart file uplo is $req->content->progress, 128, 'right progress'; $req->parse("\x0d\x0a--8jXGX--"); is $req->content->progress, 139, 'right progress'; - ok $req->is_finished, 'request is finished'; + ok $req->is_finished, 'request is finished'; ok $req->content->is_multipart, 'multipart content'; - is $req->method, 'POST', 'right method'; - is $req->url->base->host, '127.0.0.1', 'right base host'; - is $req->url->path, '/upload', 'right path'; - is $req->url->base->path, '', 'no base path'; - is $req->version, '1.1', 'right version'; + is $req->method, 'POST', 'right method'; + is $req->url->base->host, '127.0.0.1', 'right base host'; + is $req->url->path, '/upload', 'right path'; + is $req->url->base->path, '', 'no base path'; + is $req->version, '1.1', 'right version'; is $req->url->to_abs->to_string, 'http://127.0.0.1:13028/upload', 'right absolute URL'; my $file = $req->upload('file'); is $file->filename, 'file.txt', 'right filename'; @@ -473,8 +473,8 @@ subtest 'Parse IIS 7.5 like CGI environment (HTTPS=off)' => sub { SERVER_PROTOCOL => 'HTTP/1.1' }); ok $req->is_finished, 'request is finished'; - is $req->method, 'GET', 'right method'; - is $req->url->path, '', 'right URL'; + is $req->method, 'GET', 'right method'; + is $req->url->path, '', 'right URL'; is $req->url->base->protocol, 'http', 'right base protocol'; is $req->url->base->path, '/index.pl/', 'right base path'; is $req->url->base->host, 'test', 'right base host'; diff --git a/t/mojo/response.t b/t/mojo/response.t index 69ef82b5df..e44bcde360 100644 --- a/t/mojo/response.t +++ b/t/mojo/response.t @@ -79,24 +79,24 @@ subtest 'Common status codes' => sub { is $res->code(509)->default_message, 'Bandwidth Limit Exceeded', 'right message'; is $res->code(510)->default_message, 'Not Extended', 'right message'; is $res->code(511)->default_message, 'Network Authentication Required', 'right message'; - is $res->default_message(100), 'Continue', 'right message'; + is $res->default_message(100), 'Continue', 'right message'; }; subtest 'Status code ranges' => sub { my $res = Mojo::Message::Response->new; - ok $res->code(101)->is_info, 'is in range'; - ok $res->code(199)->is_info, 'is in range'; - ok $res->code(200)->is_success, 'is in range'; - ok $res->code(202)->is_success, 'is in range'; - ok $res->code(299)->is_success, 'is in range'; - ok $res->code(301)->is_redirect, 'is in range'; - ok $res->code(399)->is_redirect, 'is in range'; - ok $res->code(401)->is_client_error, 'is in range'; - ok $res->code(499)->is_client_error, 'is in range'; - ok $res->code(400)->is_error, 'is in range'; - ok $res->code(599)->is_error, 'is in range'; - ok $res->code(501)->is_server_error, 'is in range'; - ok $res->code(599)->is_server_error, 'is in range'; + ok $res->code(101)->is_info, 'is in range'; + ok $res->code(199)->is_info, 'is in range'; + ok $res->code(200)->is_success, 'is in range'; + ok $res->code(202)->is_success, 'is in range'; + ok $res->code(299)->is_success, 'is in range'; + ok $res->code(301)->is_redirect, 'is in range'; + ok $res->code(399)->is_redirect, 'is in range'; + ok $res->code(401)->is_client_error, 'is in range'; + ok $res->code(499)->is_client_error, 'is in range'; + ok $res->code(400)->is_error, 'is in range'; + ok $res->code(599)->is_error, 'is in range'; + ok $res->code(501)->is_server_error, 'is in range'; + ok $res->code(599)->is_server_error, 'is in range'; ok !$res->code(200)->is_info, 'not in range'; ok !$res->code(199)->is_success, 'not in range'; ok !$res->code(300)->is_success, 'not in range'; @@ -193,9 +193,9 @@ subtest 'Parse HTTP 1.0 response start-line and headers but no body' => sub { $res->parse("Content-Type: text/plain\x0d\x0a"); $res->parse("Content-Length: 0\x0d\x0a\x0d\x0a"); ok $res->is_finished, 'response is finished'; - is $res->code, 404, 'right status'; - is $res->message, 'Damn it', 'right message'; - is $res->version, '1.0', 'right version'; + is $res->code, 404, 'right status'; + is $res->message, 'Damn it', 'right message'; + is $res->version, '1.0', 'right version'; is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $res->headers->content_length, 0, 'right "Content-Length" value'; }; @@ -207,12 +207,12 @@ subtest 'Parse full HTTP 1.0 response' => sub { $res->parse("Content-Length: 27\x0d\x0a\x0d\x0a"); $res->parse("Hello World!\n1234\nlalalala\n"); ok $res->is_finished, 'response is finished'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.0', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $res->headers->content_length, 27, 'right "Content-Length" value'; - is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.0', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $res->headers->content_length, 27, 'right "Content-Length" value'; + is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; }; subtest 'Parse full HTTP 1.0 response (keep-alive)' => sub { @@ -221,10 +221,10 @@ subtest 'Parse full HTTP 1.0 response (keep-alive)' => sub { $res->parse("Connection: keep-alive\x0d\x0a\x0d\x0a"); $res->parse("HTTP/1.0 200 OK\x0d\x0a\x0d\x0a"); ok $res->is_finished, 'response is finished'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.0', 'right version'; - is $res->body, '', 'no content'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.0', 'right version'; + is $res->body, '', 'no content'; is $res->content->leftovers, "HTTP/1.0 200 OK\x0d\x0a\x0d\x0a", 'next response in leftovers'; }; @@ -237,13 +237,13 @@ subtest 'Parse full HTTP 1.0 response (no limit)' => sub { $res->parse("Content-Length: 27\x0d\x0a\x0d\x0a"); $res->parse("Hello World!\n1234\nlalalala\n"); ok $res->is_finished, 'response is finished'; - ok !$res->error, 'no error'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.0', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $res->headers->content_length, 27, 'right "Content-Length" value'; - is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; + ok !$res->error, 'no error'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.0', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $res->headers->content_length, 27, 'right "Content-Length" value'; + is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; }; subtest 'Parse broken start-line' => sub { @@ -260,12 +260,12 @@ subtest 'Parse full HTTP 1.0 response (missing Content-Length)' => sub { $res->parse("Connection: close\x0d\x0a\x0d\x0a"); $res->parse("Hello World!\n1234\nlalalala\n"); ok !$res->is_finished, 'response is not finished'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.0', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $res->headers->content_length, undef, 'no "Content-Length" value'; - is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.0', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $res->headers->content_length, undef, 'no "Content-Length" value'; + is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; }; subtest 'Parse full HTTP 1.0 response (missing Content-Length and Connection)' => sub { @@ -276,12 +276,12 @@ subtest 'Parse full HTTP 1.0 response (missing Content-Length and Connection)' = $res->parse("234\nlala"); $res->parse("lala\n"); ok !$res->is_finished, 'response is not finished'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.0', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $res->headers->content_length, undef, 'no "Content-Length" value'; - is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.0', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $res->headers->content_length, undef, 'no "Content-Length" value'; + is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; }; subtest 'Parse full HTTP 1.1 response (missing Content-Length)' => sub { @@ -290,16 +290,16 @@ subtest 'Parse full HTTP 1.1 response (missing Content-Length)' => sub { $res->parse("Content-Type: text/plain\x0d\x0a"); $res->parse("Connection: close\x0d\x0a\x0d\x0a"); $res->parse("Hello World!\n1234\nlalalala\n"); - ok !$res->is_finished, 'response is not finished'; - ok !$res->is_empty, 'response is not empty'; + ok !$res->is_finished, 'response is not finished'; + ok !$res->is_empty, 'response is not empty'; ok !$res->content->skip_body, 'body has not been skipped'; - ok $res->content->relaxed, 'relaxed response'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $res->headers->content_length, undef, 'no "Content-Length" value'; - is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; + ok $res->content->relaxed, 'relaxed response'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $res->headers->content_length, undef, 'no "Content-Length" value'; + is $res->body, "Hello World!\n1234\nlalalala\n", 'right content'; }; subtest 'Parse full HTTP 1.1 response (broken Content-Length)' => sub { @@ -308,12 +308,12 @@ subtest 'Parse full HTTP 1.1 response (broken Content-Length)' => sub { $res->parse("Content-Length: 123test\x0d\x0a\x0d\x0a"); $res->parse('Hello World!'); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_length, '123test', 'right "Content-Length" value'; - is $res->body, '', 'no content'; - is $res->content->leftovers, 'Hello World!', 'content in leftovers'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_length, '123test', 'right "Content-Length" value'; + is $res->body, '', 'no content'; + is $res->content->leftovers, 'Hello World!', 'content in leftovers'; }; subtest 'Parse full HTTP 1.1 response (100 Continue)' => sub { @@ -322,17 +322,17 @@ subtest 'Parse full HTTP 1.1 response (100 Continue)' => sub { $res->on(progress => sub { shift->headers->header('X-Progress' => 'two') }); $res->on(finish => sub { shift->headers->header('X-Finish' => 'three') }); $res->parse("HTTP/1.1 100 Continue\x0d\x0a\x0d\x0a"); - ok $res->is_finished, 'response is finished'; - ok $res->is_empty, 'response is empty'; + ok $res->is_finished, 'response is finished'; + ok $res->is_empty, 'response is empty'; ok $res->content->skip_body, 'body has been skipped'; - is $res->code, 100, 'right status'; - is $res->message, 'Continue', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_length, undef, 'no "Content-Length" value'; - is $res->headers->header('X-Body'), 'one', 'right "X-Body" value'; - is $res->headers->header('X-Progress'), 'two', 'right "X-Progress" value'; - is $res->headers->header('X-Finish'), 'three', 'right "X-Finish" value'; - is $res->body, '', 'no content'; + is $res->code, 100, 'right status'; + is $res->message, 'Continue', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_length, undef, 'no "Content-Length" value'; + is $res->headers->header('X-Body'), 'one', 'right "X-Body" value'; + is $res->headers->header('X-Progress'), 'two', 'right "X-Progress" value'; + is $res->headers->header('X-Finish'), 'three', 'right "X-Finish" value'; + is $res->body, '', 'no content'; }; subtest 'Parse full HTTP 1.1 response (304 Not Modified)' => sub { @@ -341,16 +341,16 @@ subtest 'Parse full HTTP 1.1 response (304 Not Modified)' => sub { $res->parse("Content-Type: text/html\x0d\x0a"); $res->parse("Content-Length: 9000\x0d\x0a"); $res->parse("Connection: keep-alive\x0d\x0a\x0d\x0a"); - ok $res->is_finished, 'response is finished'; - ok $res->is_empty, 'response is empty'; + ok $res->is_finished, 'response is finished'; + ok $res->is_empty, 'response is empty'; ok $res->content->skip_body, 'body has been skipped'; - is $res->code, 304, 'right status'; - is $res->message, 'Not Modified', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_type, 'text/html', 'right "Content-Type" value'; - is $res->headers->content_length, 9000, 'right "Content-Length" value'; - is $res->headers->connection, 'keep-alive', 'right "Connection" value'; - is $res->body, '', 'no content'; + is $res->code, 304, 'right status'; + is $res->message, 'Not Modified', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_type, 'text/html', 'right "Content-Type" value'; + is $res->headers->content_length, 9000, 'right "Content-Length" value'; + is $res->headers->connection, 'keep-alive', 'right "Connection" value'; + is $res->body, '', 'no content'; }; subtest 'Parse full HTTP 1.1 response (204 No Content)' => sub { @@ -361,18 +361,18 @@ subtest 'Parse full HTTP 1.1 response (204 No Content)' => sub { $res->parse("Content-Type: text/html\x0d\x0a"); $res->parse("Content-Length: 9001\x0d\x0a"); $res->parse("Connection: keep-alive\x0d\x0a\x0d\x0a"); - ok $res->is_finished, 'response is finished'; - ok $res->is_empty, 'response is empty'; + ok $res->is_finished, 'response is finished'; + ok $res->is_empty, 'response is empty'; ok $res->content->skip_body, 'body has been skipped'; - is $res->code, 204, 'right status'; - is $res->message, 'No Content', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_type, 'text/html', 'right "Content-Type" value'; - is $res->headers->content_length, 9001, 'right "Content-Length" value'; - is $res->headers->connection, 'keep-alive', 'right "Connection" value'; - is $res->headers->header('X-Body'), 'one', 'right "X-Body" value'; - is $res->headers->header('X-Finish'), 'two', 'right "X-Finish" value'; - is $res->body, '', 'no content'; + is $res->code, 204, 'right status'; + is $res->message, 'No Content', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_type, 'text/html', 'right "Content-Type" value'; + is $res->headers->content_length, 9001, 'right "Content-Length" value'; + is $res->headers->connection, 'keep-alive', 'right "Connection" value'; + is $res->headers->header('X-Body'), 'one', 'right "X-Body" value'; + is $res->headers->header('X-Finish'), 'two', 'right "X-Finish" value'; + is $res->body, '', 'no content'; }; subtest 'Parse HTTP 1.1 response (413 error in one big chunk)' => sub { @@ -382,10 +382,10 @@ subtest 'Parse HTTP 1.1 response (413 error in one big chunk)' => sub { . "Date: Tue, 09 Feb 2010 16:34:51 GMT\x0d\x0a" . "Server: Mojolicious (Perl)\x0d\x0a\x0d\x0a"); ok !$res->is_finished, 'response is not finished'; - is $res->code, 413, 'right status'; - is $res->message, 'Request Entity Too Large', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_length, undef, 'right "Content-Length" value'; + is $res->code, 413, 'right status'; + is $res->message, 'Request Entity Too Large', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_length, undef, 'right "Content-Length" value'; }; subtest 'Parse HTTP 1.1 chunked response (exceeding limit)' => sub { @@ -397,13 +397,13 @@ subtest 'Parse HTTP 1.1 chunked response (exceeding limit)' => sub { $res->parse("Transfer-Encoding: chunked\x0d\x0a\x0d\x0a"); ok !$res->is_limit_exceeded, 'limit is not exceeded'; $res->parse('a' x 1000); - ok $res->is_finished, 'response is finished'; + ok $res->is_finished, 'response is finished'; ok $res->content->is_finished, 'content is finished'; is $res->error->{message}, 'Maximum buffer size exceeded', 'right error'; ok $res->is_limit_exceeded, 'limit is not exceeded'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; }; @@ -418,12 +418,12 @@ subtest 'Parse HTTP 1.1 multipart response (exceeding limit)' => sub { ok !$res->content->is_limit_exceeded, 'limit is not exceeded'; $res->parse('a' x 200); ok $res->content->is_limit_exceeded, 'limit is exceeded'; - ok $res->is_finished, 'response is finished'; - ok $res->content->is_finished, 'content is finished'; + ok $res->is_finished, 'response is finished'; + ok $res->content->is_finished, 'content is finished'; is $res->error->{message}, 'Maximum buffer size exceeded', 'right error'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->content_type, 'multipart/form-data; boundary=----------0xKhTmLbOuNdArY', 'right "Content-Type" value'; }; @@ -439,13 +439,13 @@ subtest 'Parse HTTP 1.1 gzip compressed response (garbage bytes exceeding limit) ok !$res->content->is_limit_exceeded, 'limit is not exceeded'; $res->parse('a' x 995); ok $res->content->is_limit_exceeded, 'limit is exceeded'; - ok $res->is_finished, 'response is finished'; - ok $res->content->is_finished, 'content is finished'; + ok $res->is_finished, 'response is finished'; + ok $res->content->is_finished, 'content is finished'; is $res->error->{message}, 'Maximum buffer size exceeded', 'right error'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->body, '', 'no content'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->body, '', 'no content'; }; subtest 'Parse HTTP 1.1 chunked response' => sub { @@ -459,13 +459,13 @@ subtest 'Parse HTTP 1.1 chunked response' => sub { $res->parse("abcdefghi\x0d\x0a"); $res->parse("0\x0d\x0a\x0d\x0a"); ok $res->is_finished, 'response is finished'; - is $res->code, 500, 'right status'; - is $res->message, 'Internal Server Error', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; - is $res->headers->content_length, 13, 'right "Content-Length" value'; - is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; - is $res->body_size, 13, 'right size'; + is $res->code, 500, 'right status'; + is $res->message, 'Internal Server Error', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + is $res->headers->content_length, 13, 'right "Content-Length" value'; + is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; + is $res->body_size, 13, 'right size'; }; subtest 'Parse HTTP 1.1 multipart response' => sub { @@ -489,9 +489,9 @@ subtest 'Parse HTTP 1.1 multipart response' => sub { $res->parse("print \"Hello World :)\\n\"\n"); $res->parse("\x0d\x0a------------0xKhTmLbOuNdArY--"); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->content_type, 'multipart/form-data; boundary=----------0xKhTmLbOuNdArY', 'right "Content-Type" value'; ok !$res->content->parts->[0]->is_multipart, 'no multipart content'; @@ -531,23 +531,23 @@ subtest 'Parse HTTP 1.1 chunked multipart response with leftovers (at once)' => . "HTTP/1.0 200 OK\x0d\x0a\x0d\x0a"; $res->parse($multipart); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->content_type, 'multipart/form-data; boundary=----------0xKhTmLbOuNdArY', 'right "Content-Type" value'; is $res->headers->content_length, 418, 'right "Content-Length" value'; is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; - is $res->body_size, 418, 'right size'; + is $res->body_size, 418, 'right size'; ok !$res->content->parts->[0]->is_multipart, 'no multipart content'; ok !$res->content->parts->[1]->is_multipart, 'no multipart content'; ok !$res->content->parts->[2]->is_multipart, 'no multipart content'; is $res->content->parts->[0]->asset->slurp, "hallo welt test123\n", 'right content'; - is $res->upload('upload')->filename, 'hello.pl', 'right filename'; + is $res->upload('upload')->filename, 'hello.pl', 'right filename'; ok !$res->upload('upload')->asset->is_file, 'stored in memory'; - is $res->upload('upload')->asset->size, 69, 'right size'; - is $res->content->parts->[2]->headers->content_type, 'application/octet-stream', 'right "Content-Type" value'; - is $res->content->leftovers, "HTTP/1.0 200 OK\x0d\x0a\x0d\x0a", 'next response in leftovers'; + is $res->upload('upload')->asset->size, 69, 'right size'; + is $res->content->parts->[2]->headers->content_type, 'application/octet-stream', 'right "Content-Type" value'; + is $res->content->leftovers, "HTTP/1.0 200 OK\x0d\x0a\x0d\x0a", 'next response in leftovers'; }; subtest 'Parse HTTP 1.1 chunked multipart response (in multiple small chunks)' => sub { @@ -578,21 +578,21 @@ subtest 'Parse HTTP 1.1 chunked multipart response (in multiple small chunks)' = ok !$res->is_finished, 'response is not finished'; $res->parse("\x0d\x0a0\x0d\x0a\x0d\x0a"); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->content_type, 'multipart/parallel; boundary=AAA; charset=utf-8', 'right "Content-Type" value'; is $res->headers->content_length, 129, 'right "Content-Length" value'; is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; - is $res->body_size, 129, 'right size'; + is $res->body_size, 129, 'right size'; ok !$res->content->parts->[0]->is_multipart, 'no multipart content'; ok !$res->content->parts->[1]->is_multipart, 'no multipart content'; - is $res->content->parts->[0]->asset->slurp, 'abcd', 'right content'; - is $res->content->parts->[0]->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; - is $res->content->parts->[0]->headers->header('Content-ID'), 600050, 'right "Content-ID" value'; - is $res->content->parts->[1]->asset->slurp, 'efgh', 'right content'; - is $res->content->parts->[1]->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; - is $res->content->parts->[1]->headers->header('Content-ID'), 600051, 'right "Content-ID" value'; + is $res->content->parts->[0]->asset->slurp, 'abcd', 'right content'; + is $res->content->parts->[0]->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; + is $res->content->parts->[0]->headers->header('Content-ID'), 600050, 'right "Content-ID" value'; + is $res->content->parts->[1]->asset->slurp, 'efgh', 'right content'; + is $res->content->parts->[1]->headers->content_type, 'image/jpeg', 'right "Content-Type" value'; + is $res->content->parts->[1]->headers->header('Content-ID'), 600051, 'right "Content-ID" value'; }; subtest 'Parse HTTP 1.1 multipart response with missing boundary' => sub { @@ -615,9 +615,9 @@ subtest 'Parse HTTP 1.1 multipart response with missing boundary' => sub { $res->parse("print \"Hello World :)\\n\"\n"); $res->parse("\x0d\x0a------------0xKhTmLbOuNdArY--"); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->content_type, 'multipart/form-data; bo', 'right "Content-Type" value'; ok !$res->content->is_multipart, 'no multipart content'; like $res->content->asset->slurp, qr/hallo welt/, 'right content'; @@ -638,15 +638,15 @@ subtest 'Parse HTTP 1.1 gzip compressed response' => sub { $res->parse(substr($compressed, 1, length($compressed))); is $res->content->progress, length($compressed), 'right progress'; ok !$res->content->is_compressed, 'content is not compressed anymore'; - ok $res->is_finished, 'response is finished'; - ok !$res->error, 'no error'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + ok $res->is_finished, 'response is finished'; + ok !$res->error, 'no error'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $res->headers->content_length, length($uncompressed), 'right "Content-Length" value'; - is $res->headers->content_encoding, undef, 'no "Content-Encoding" value'; - is $res->body, $uncompressed, 'right content'; + is $res->headers->content_encoding, undef, 'no "Content-Encoding" value'; + is $res->body, $uncompressed, 'right content'; }; subtest 'Parse HTTP 1.1 chunked gzip compressed response' => sub { @@ -670,16 +670,16 @@ subtest 'Parse HTTP 1.1 chunked gzip compressed response' => sub { $res->parse("0\x0d\x0a\x0d\x0a"); ok !$res->content->is_chunked, 'content is not chunked anymore'; ok !$res->content->is_compressed, 'content is not compressed anymore'; - ok $res->is_finished, 'response is finished'; - ok !$res->error, 'no error'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; + ok $res->is_finished, 'response is finished'; + ok !$res->error, 'no error'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $res->headers->content_length, length($uncompressed), 'right "Content-Length" value'; - is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; - is $res->headers->content_encoding, undef, 'no "Content-Encoding" value'; - is $res->body, $uncompressed, 'right content'; + is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value'; + is $res->headers->content_encoding, undef, 'no "Content-Encoding" value'; + is $res->body, $uncompressed, 'right content'; }; subtest 'Build HTTP 1.1 response start-line with minimal headers' => sub { @@ -688,9 +688,9 @@ subtest 'Build HTTP 1.1 response start-line with minimal headers' => sub { $res->headers->date('Sun, 17 Aug 2008 16:27:35 GMT'); $res = Mojo::Message::Response->new->parse($res->to_string); ok $res->is_finished, 'response is finished'; - is $res->code, '404', 'right status'; - is $res->message, 'Not Found', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, '404', 'right status'; + is $res->message, 'Not Found', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; is $res->headers->content_length, 0, 'right "Content-Length" value'; }; @@ -702,11 +702,11 @@ subtest 'Build HTTP 1.1 response start-line with minimal headers (strange messag $res->headers->date('Sun, 17 Aug 2008 16:27:35 GMT'); $res = Mojo::Message::Response->new->parse($res->to_string); ok $res->is_finished, 'response is finished'; - is $res->code, '404', 'right status'; - is $res->message, 'Looks-0k!@ ;\':" #$%^<>,.\\o/ &*()', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; - is $res->headers->content_length, 0, 'right "Content-Length" value'; + is $res->code, '404', 'right status'; + is $res->message, 'Looks-0k!@ ;\':" #$%^<>,.\\o/ &*()', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; + is $res->headers->content_length, 0, 'right "Content-Length" value'; }; subtest 'Build HTTP 1.1 response start-line and header' => sub { @@ -716,9 +716,9 @@ subtest 'Build HTTP 1.1 response start-line and header' => sub { $res->headers->date('Sun, 17 Aug 2008 16:27:35 GMT'); $res = Mojo::Message::Response->new->parse($res->to_string); ok $res->is_finished, 'response is finished'; - is $res->code, '200', 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, '200', 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->connection, 'keep-alive', 'right "Connection" value'; is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; }; @@ -731,13 +731,13 @@ subtest 'Build full HTTP 1.1 response' => sub { $res->body("Hello World!\n"); $res = Mojo::Message::Response->new->parse($res->to_string); ok $res->is_finished, 'response is finished'; - is $res->code, '200', 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, '200', 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->connection, 'keep-alive', 'right "Connection" value'; is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; is $res->headers->content_length, '13', 'right "Content-Length" value'; - is $res->body, "Hello World!\n", 'right content'; + is $res->body, "Hello World!\n", 'right content'; }; subtest 'Build HTTP 1.1 response parts with progress' => sub { @@ -755,21 +755,21 @@ subtest 'Build HTTP 1.1 response parts with progress' => sub { $res->headers->connection('keep-alive'); $res->headers->date('Sun, 17 Aug 2008 16:27:35 GMT'); $res->body("Hello World!\n"); - ok !$state, 'no state'; - ok !$progress, 'no progress'; - ok !$finished, 'not finished'; + ok !$state, 'no state'; + ok !$progress, 'no progress'; + ok !$finished, 'not finished'; ok $res->build_start_line, 'built start-line'; is $state, 'start_line', 'made progress on start_line'; ok $progress, 'made progress'; $progress = 0; - ok !$finished, 'not finished'; + ok !$finished, 'not finished'; ok $res->build_headers, 'built headers'; is $state, 'headers', 'made progress on headers'; ok $progress, 'made progress'; $progress = 0; - ok !$finished, 'not finished'; + ok !$finished, 'not finished'; ok $res->build_body, 'built body'; - is $state, 'body', 'made progress on headers'; + is $state, 'body', 'made progress on headers'; ok $progress, 'made progress'; ok $finished, 'finished'; }; @@ -785,12 +785,12 @@ subtest 'Build HTTP 1.1 response with dynamic content' => sub { ok $res->content->is_dynamic, 'dynamic content'; $res = Mojo::Message::Response->new->parse($res->to_string); ok !$res->content->is_dynamic, 'no dynamic content'; - ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->content_length, '12', 'right "Content-Length" value'; - is $res->body, 'Hello World!', 'right content'; + ok $res->is_finished, 'response is finished'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->content_length, '12', 'right "Content-Length" value'; + is $res->body, 'Hello World!', 'right content'; }; subtest 'Build HTTP 1.1 multipart response' => sub { @@ -807,13 +807,13 @@ subtest 'Build HTTP 1.1 multipart response' => sub { push @{$res->content->parts}, $content; $res = Mojo::Message::Response->new->parse($res->to_string); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; - is $res->headers->content_length, '110', 'right "Content-Length" value'; - is $res->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; - is $res->content->parts->[0]->asset->slurp, 'Hallo Welt lalalalalala!', 'right content'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; + is $res->headers->content_length, '110', 'right "Content-Length" value'; + is $res->headers->content_type, 'multipart/mixed; boundary=7am1X', 'right "Content-Type" value'; + is $res->content->parts->[0]->asset->slurp, 'Hallo Welt lalalalalala!', 'right content'; is $res->content->parts->[1]->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $res->content->parts->[1]->asset->slurp, "lala\nfoobar\nperl rocks\n", 'right content'; }; @@ -826,16 +826,16 @@ subtest 'Parse response with cookie' => sub { $res->parse("Set-Cookie: foo=bar; path=/test\x0d\x0a\x0d\x0a"); $res->parse("Hello World!\n1234\nlalalala\n"); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.0', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.0', 'right version'; is $res->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $res->headers->content_length, 27, 'right "Content-Length" value'; is $res->headers->set_cookie, 'foo=bar; path=/test', 'right "Set-Cookie" value'; my $cookies = $res->cookies; - is $cookies->[0]->name, 'foo', 'right name'; - is $cookies->[0]->value, 'bar', 'right value'; - is $cookies->[0]->path, '/test', 'right path'; + is $cookies->[0]->name, 'foo', 'right name'; + is $cookies->[0]->value, 'bar', 'right value'; + is $cookies->[0]->path, '/test', 'right path'; is $res->cookie('foo')->value, 'bar', 'right value'; is $res->cookie('foo')->path, '/test', 'right path'; }; @@ -847,17 +847,17 @@ subtest 'Parse WebSocket handshake response' => sub { $res->parse("Connection: Upgrade\x0d\x0a"); $res->parse("Sec-WebSocket-Accept: abcdef=\x0d\x0a"); $res->parse("Sec-WebSocket-Protocol: sample\x0d\x0a\x0d\x0a"); - ok $res->is_finished, 'response is finished'; - ok $res->is_empty, 'response is empty'; + ok $res->is_finished, 'response is finished'; + ok $res->is_empty, 'response is empty'; ok $res->content->skip_body, 'body has been skipped'; - is $res->code, 101, 'right status'; - is $res->message, 'Switching Protocols', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->upgrade, 'websocket', 'right "Upgrade" value'; - is $res->headers->connection, 'Upgrade', 'right "Connection" value'; - is $res->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Accept" value'; - is $res->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $res->body, '', 'no content'; + is $res->code, 101, 'right status'; + is $res->message, 'Switching Protocols', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->upgrade, 'websocket', 'right "Upgrade" value'; + is $res->headers->connection, 'Upgrade', 'right "Connection" value'; + is $res->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Accept" value'; + is $res->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; + is $res->body, '', 'no content'; ok !defined $res->headers->content_length, '"Content-Length" does not exist'; }; @@ -869,18 +869,18 @@ subtest 'Parse WebSocket handshake response (with frame)' => sub { $res->parse("Sec-WebSocket-Accept: abcdef=\x0d\x0a"); $res->parse("Sec-WebSocket-Protocol: sample\x0d\x0a"); $res->parse("\x0d\x0a\x81\x08\x77\x68\x61\x74\x65\x76\x65\x72"); - ok $res->is_finished, 'response is finished'; - ok $res->is_empty, 'response is empty'; + ok $res->is_finished, 'response is finished'; + ok $res->is_empty, 'response is empty'; ok $res->content->skip_body, 'body has been skipped'; - is $res->code, 101, 'right status'; - is $res->message, 'Switching Protocols', 'right message'; - is $res->version, '1.1', 'right version'; - is $res->headers->upgrade, 'websocket', 'right "Upgrade" value'; - is $res->headers->connection, 'Upgrade', 'right "Connection" value'; - is $res->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Accept" value'; - is $res->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $res->body, '', 'no content'; - is $res->content->leftovers, "\x81\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'frame in leftovers'; + is $res->code, 101, 'right status'; + is $res->message, 'Switching Protocols', 'right message'; + is $res->version, '1.1', 'right version'; + is $res->headers->upgrade, 'websocket', 'right "Upgrade" value'; + is $res->headers->connection, 'Upgrade', 'right "Connection" value'; + is $res->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Accept" value'; + is $res->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; + is $res->body, '', 'no content'; + is $res->content->leftovers, "\x81\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'frame in leftovers'; ok !defined $res->headers->content_length, '"Content-Length" does not exist'; }; @@ -894,16 +894,16 @@ subtest 'Build WebSocket handshake response' => sub { $res->headers->sec_websocket_protocol('sample'); $res = Mojo::Message::Response->new->parse($res->to_string); ok $res->is_finished, 'response is finished'; - is $res->code, '101', 'right status'; - is $res->message, 'Switching Protocols', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, '101', 'right status'; + is $res->message, 'Switching Protocols', 'right message'; + is $res->version, '1.1', 'right version'; is $res->headers->connection, 'Upgrade', 'right "Connection" value'; is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value'; ok !defined $res->headers->content_length, '"Content-Length" does not exist'; is $res->headers->upgrade, 'websocket', 'right "Upgrade" value'; is $res->headers->sec_websocket_accept, 'abcdef=', 'right "Sec-WebSocket-Accept" value'; is $res->headers->sec_websocket_protocol, 'sample', 'right "Sec-WebSocket-Protocol" value'; - is $res->body, '', 'no content'; + is $res->body, '', 'no content'; ok !defined $res->headers->content_length, '"Content-Length" does not exist'; }; @@ -918,9 +918,9 @@ subtest 'Build and parse HTTP 1.1 response with 3 cookies' => sub { my $res2 = Mojo::Message::Response->new; $res2->parse($res->to_string); ok $res2->is_finished, 'response is finished'; - is $res2->code, 404, 'right status'; - is $res2->version, '1.1', 'right version'; - is $res2->headers->content_length, 0, 'right "Content-Length" value'; + is $res2->code, 404, 'right status'; + is $res2->version, '1.1', 'right version'; + is $res2->headers->content_length, 0, 'right "Content-Length" value'; ok defined $res2->cookie('foo'), 'cookie "foo" exists'; ok defined $res2->cookie('bar'), 'cookie "bar" exists'; ok defined $res2->cookie('baz'), 'cookie "baz" exists'; @@ -952,7 +952,7 @@ subtest 'Build dynamic response body' => sub { $res->content->write('hello!' => sub { $invocant = shift }); $res->content->write('hello world!')->write(''); ok !$res->content->is_chunked, 'no chunked content'; - ok $res->content->is_dynamic, 'dynamic content'; + ok $res->content->is_dynamic, 'dynamic content'; is $res->build_body, "hello!hello world!", 'right format'; isa_ok $invocant, 'Mojo::Content::Single', 'right invocant'; }; @@ -988,7 +988,7 @@ subtest 'Build response with callback (consistency calls)' => sub { is $res->headers->connection, undef, 'no "Connection" value'; ok $res->content->is_dynamic, 'dynamic content'; is $count, length($body), 'right length'; - is $full, $body, 'right content'; + is $full, $body, 'right content'; }; subtest 'Build response with callback (no Content-Length header)' => sub { @@ -1012,7 +1012,7 @@ subtest 'Build response with callback (no Content-Length header)' => sub { is $res->headers->connection, 'close', 'right "Connection" value'; ok $res->content->is_dynamic, 'dynamic content'; is $count, length($body), 'right length'; - is $full, $body, 'right content'; + is $full, $body, 'right content'; }; subtest 'Body' => sub { @@ -1026,7 +1026,7 @@ subtest 'Body' => sub { $res->body('hi there!'); is $res->body, 'hi there!', 'right content'; $res->body(0); - is $res->body, 0, 'right content'; + is $res->body, 0, 'right content'; is $res->body('hello!')->body, 'hello!', 'right content'; $res->content(Mojo::Content::MultiPart->new); $res->body('hi!'); @@ -1036,13 +1036,13 @@ subtest 'Body' => sub { subtest 'Text' => sub { my $res = Mojo::Message::Response->new; my $snowman = encode 'UTF-8', '☃'; - is $res->body($snowman)->text, '☃', 'right content'; + is $res->body($snowman)->text, '☃', 'right content'; is $res->body($snowman)->dom->text, '☃', 'right text'; $res = Mojo::Message::Response->new; my $yatta = encode 'shift_jis', 'やった'; is $res->body($yatta)->text, $yatta, 'right content'; $res->headers->content_type('text/plain;charset=shift_jis'); - is $res->body($yatta)->text, 'やった', 'right content'; + is $res->body($yatta)->text, 'やった', 'right content'; is $res->body($yatta)->dom->text, 'やった', 'right text'; }; @@ -1050,9 +1050,9 @@ subtest 'Body exceeding memory limit (no upgrade)' => sub { local $ENV{MOJO_MAX_MEMORY_SIZE} = 8; my $res = Mojo::Message::Response->new; $res->body('hi there!'); - is $res->body, 'hi there!', 'right content'; - is $res->content->asset->max_memory_size, 8, 'right size'; - is $res->content->asset->size, 9, 'right size'; + is $res->body, 'hi there!', 'right content'; + is $res->content->asset->max_memory_size, 8, 'right size'; + is $res->content->asset->size, 9, 'right size'; ok !$res->content->asset->is_file, 'stored in memory'; }; @@ -1063,12 +1063,12 @@ subtest 'Parse response and extract JSON data' => sub { $res->parse("Content-Length: 27\x0a\x0a"); $res->parse(encode_json({foo => 'bar', baz => [1, 2, 3]})); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is_deeply $res->json, {foo => 'bar', baz => [1, 2, 3]}, 'right JSON data'; - is $res->json('/foo'), 'bar', 'right result'; - is $res->json('/baz/1'), 2, 'right result'; + is $res->json('/foo'), 'bar', 'right result'; + is $res->json('/baz/1'), 2, 'right result'; is_deeply $res->json('/baz'), [1, 2, 3], 'right result'; $res->json->{baz}[1] = 4; is_deeply $res->json('/baz'), [1, 4, 3], 'right result'; @@ -1081,24 +1081,24 @@ subtest 'Parse response and extract HTML' => sub { $res->parse("Content-Length: 51\x0a\x0a"); $res->parse('

    foobarbaz

    '); ok $res->is_finished, 'response is finished'; - is $res->code, 200, 'right status'; - is $res->message, 'OK', 'right message'; - is $res->version, '1.1', 'right version'; + is $res->code, 200, 'right status'; + is $res->message, 'OK', 'right message'; + is $res->version, '1.1', 'right version'; is $res->dom->at('p')->text, 'foo', 'right value'; is $res->dom->at('p > a')->text, 'bar', 'right value'; - is $res->dom('p')->first->text, 'foo', 'right value'; + is $res->dom('p')->first->text, 'foo', 'right value'; is_deeply $res->dom('p > a')->map('text')->to_array, [qw(bar baz)], 'right values'; my @text = $res->dom('a')->map(content => 'yada')->first->root->find('p > a')->map('text')->each; - is_deeply \@text, [qw(yada yada)], 'right values'; + is_deeply \@text, [qw(yada yada)], 'right values'; is_deeply $res->dom('p > a')->map('text')->to_array, [qw(yada yada)], 'right values'; @text = $res->dom->find('a')->map(content => 'test')->first->root->find('p > a')->map('text')->each; - is_deeply \@text, [qw(test test)], 'right values'; + is_deeply \@text, [qw(test test)], 'right values'; is_deeply $res->dom->find('p > a')->map('text')->to_array, [qw(test test)], 'right values'; my $dir = tempdir; my $file = $dir->child('single.html'); is $res->save_to($file)->body, '

    foobarbaz

    ', 'right content'; - is $file->slurp, '

    foobarbaz

    ', 'right content'; + is $file->slurp, '

    foobarbaz

    ', 'right content'; }; subtest 'Build DOM from response with charset' => sub { diff --git a/t/mojo/template.t b/t/mojo/template.t index e90edd9217..6b55eec84a 100644 --- a/t/mojo/template.t +++ b/t/mojo/template.t @@ -617,7 +617,7 @@ test test EOF isa_ok $output, 'Mojo::Exception', 'right exception'; -is $output->message, "x\n", 'right message'; +is $output->message, "x\n", 'right message'; is $output->lines_before->[0][0], 1, 'right number'; is $output->lines_before->[0][1], 'test', 'right line'; is $output->lines_before->[1][0], 2, 'right number'; @@ -647,10 +647,10 @@ is $output->lines_before->[2][0], 3, 'right number'; is $output->lines_before->[2][1], '% {', 'right line'; is $output->lines_before->[3][0], 4, 'right number'; is $output->lines_before->[3][1], '%= 1 + 1', 'right line'; -is $output->line->[0], 5, 'right number'; -is $output->line->[1], 'test', 'right line'; -like "$output", qr/Missing right curly/, 'right result'; -like $output->frames->[0][1], qr/Template\.pm$/, 'right file'; +is $output->line->[0], 5, 'right number'; +is $output->line->[1], 'test', 'right line'; +like "$output", qr/Missing right curly/, 'right result'; +like $output->frames->[0][1], qr/Template\.pm$/, 'right file'; # Exception in module $mt = Mojo::Template->new; @@ -673,12 +673,12 @@ is $output->lines_before->[3][0], 17, 'right number' is $output->lines_before->[3][1], 'use Mojo::Base -strict;', 'right line'; is $output->lines_before->[4][0], 18, 'right number'; is $output->lines_before->[4][1], '', 'right line'; -is $output->line->[0], 19, 'right number'; -is $output->line->[1], "sub exception { die 'ohoh' }", 'right line'; -is $output->lines_after->[0][0], 20, 'right number'; -is $output->lines_after->[0][1], '', 'right line'; -is $output->lines_after->[1][0], 21, 'right number'; -is $output->lines_after->[1][1], 'package main;', 'right line'; +is $output->line->[0], 19, 'right number'; +is $output->line->[1], "sub exception { die 'ohoh' }", 'right line'; +is $output->lines_after->[0][0], 20, 'right number'; +is $output->lines_after->[0][1], '', 'right line'; +is $output->lines_after->[1][0], 21, 'right number'; +is $output->lines_after->[1][1], 'package main;', 'right line'; like "$output", qr/ohoh/, 'right result'; # Exception in template @@ -694,20 +694,20 @@ test EOF isa_ok $output, 'Mojo::Exception', 'right exception'; like $output->message, qr/oops!/, 'right message'; -is $output->lines_before->[0][0], 1, 'right number'; -is $output->lines_before->[0][1], 'test', 'right line'; -is $output->lines_before->[1][0], 2, 'right number'; -is $output->lines_before->[1][1], '123\\', 'right line'; -is $output->lines_before->[2][0], 3, 'right number'; -is $output->lines_before->[2][1], '456', 'right line'; -is $output->lines_before->[3][0], 4, 'right number'; -is $output->lines_before->[3][1], ' %# This dies', 'right line'; -is $output->line->[0], 5, 'right number'; -is $output->line->[1], "% die 'oops!';", 'right line'; -is $output->lines_after->[0][0], 6, 'right number'; -is $output->lines_after->[0][1], '%= 1 + 1', 'right line'; -is $output->lines_after->[1][0], 7, 'right number'; -is $output->lines_after->[1][1], 'test', 'right line'; +is $output->lines_before->[0][0], 1, 'right number'; +is $output->lines_before->[0][1], 'test', 'right line'; +is $output->lines_before->[1][0], 2, 'right number'; +is $output->lines_before->[1][1], '123\\', 'right line'; +is $output->lines_before->[2][0], 3, 'right number'; +is $output->lines_before->[2][1], '456', 'right line'; +is $output->lines_before->[3][0], 4, 'right number'; +is $output->lines_before->[3][1], ' %# This dies', 'right line'; +is $output->line->[0], 5, 'right number'; +is $output->line->[1], "% die 'oops!';", 'right line'; +is $output->lines_after->[0][0], 6, 'right number'; +is $output->lines_after->[0][1], '%= 1 + 1', 'right line'; +is $output->lines_after->[1][0], 7, 'right number'; +is $output->lines_after->[1][1], 'test', 'right line'; $output->frames([['Sandbox', 'template', 5], ['main', 'template.t', 673]]); is $output, <lines_before->[0][2], 'contains code'; is $output->lines_before->[1][0], 2, 'right number'; is $output->lines_before->[1][1], '123', 'right line'; ok $output->lines_before->[1][2], 'contains code'; -is $output->lines_before->[2][0], 3, 'right number'; -is $output->lines_before->[2][1], '%', 'right line'; -is $output->lines_before->[2][2], ' ', 'right code'; -is $output->line->[0], 4, 'right number'; -is $output->line->[1], "% die 'oops!';", 'right line'; -is $output->lines_after->[0][0], 5, 'right number'; -is $output->lines_after->[0][1], '%', 'right line'; -is $output->lines_after->[0][2], ' ', 'right code'; -is $output->lines_after->[1][0], 6, 'right number'; -is $output->lines_after->[1][1], ' %', 'right line'; -is $output->lines_after->[1][2], ' ', 'right code'; -is $output->lines_after->[2][0], 7, 'right number'; -is $output->lines_after->[2][1], '%', 'right line'; -is $output->lines_after->[2][2], ' ', 'right code'; +is $output->lines_before->[2][0], 3, 'right number'; +is $output->lines_before->[2][1], '%', 'right line'; +is $output->lines_before->[2][2], ' ', 'right code'; +is $output->line->[0], 4, 'right number'; +is $output->line->[1], "% die 'oops!';", 'right line'; +is $output->lines_after->[0][0], 5, 'right number'; +is $output->lines_after->[0][1], '%', 'right line'; +is $output->lines_after->[0][2], ' ', 'right code'; +is $output->lines_after->[1][0], 6, 'right number'; +is $output->lines_after->[1][1], ' %', 'right line'; +is $output->lines_after->[1][2], ' ', 'right code'; +is $output->lines_after->[2][0], 7, 'right number'; +is $output->lines_after->[2][1], '%', 'right line'; +is $output->lines_after->[2][2], ' ', 'right code'; like "$output", qr/oops! at template line 4/, 'right result'; # Exception in nested template @@ -1142,12 +1142,12 @@ $file = curfile->sibling('templates', 'exception.mt'); $output = $mt->render_file($file); isa_ok $output, 'Mojo::Exception', 'right exception'; like $output->message, qr/exception\.mt line 2/, 'message contains filename'; -is $output->lines_before->[0][0], 1, 'right number'; -is $output->lines_before->[0][1], 'test', 'right line'; -is $output->line->[0], 2, 'right number'; -is $output->line->[1], '% die;', 'right line'; -is $output->lines_after->[0][0], 3, 'right number'; -is $output->lines_after->[0][1], '123', 'right line'; +is $output->lines_before->[0][0], 1, 'right number'; +is $output->lines_before->[0][1], 'test', 'right line'; +is $output->line->[0], 2, 'right number'; +is $output->line->[1], '% die;', 'right line'; +is $output->lines_after->[0][0], 3, 'right number'; +is $output->lines_after->[0][1], '123', 'right line'; like "$output", qr/exception\.mt line 2/, 'right result'; # Exception in file (different name) @@ -1155,12 +1155,12 @@ $mt = Mojo::Template->new; $output = $mt->name('"foo.mt" from DATA section')->render_file($file); isa_ok $output, 'Mojo::Exception', 'right exception'; like $output->message, qr/foo\.mt from DATA section line 2/, 'message contains filename'; -is $output->lines_before->[0][0], 1, 'right number'; -is $output->lines_before->[0][1], 'test', 'right line'; -is $output->line->[0], 2, 'right number'; -is $output->line->[1], '% die;', 'right line'; -is $output->lines_after->[0][0], 3, 'right number'; -is $output->lines_after->[0][1], '123', 'right line'; +is $output->lines_before->[0][0], 1, 'right number'; +is $output->lines_before->[0][1], 'test', 'right line'; +is $output->line->[0], 2, 'right number'; +is $output->line->[1], '% die;', 'right line'; +is $output->lines_after->[0][0], 3, 'right number'; +is $output->lines_after->[0][1], '123', 'right line'; like "$output", qr/foo\.mt from DATA section line 2/, 'right result'; # Exception with UTF-8 context @@ -1168,15 +1168,15 @@ $mt = Mojo::Template->new; $file = curfile->sibling('templates', 'utf8_exception.mt'); $output = $mt->render_file($file); isa_ok $output, 'Mojo::Exception', 'right exception'; -is $output->lines_before->[0][1], '☃', 'right line'; -is $output->line->[1], '% die;♥', 'right line'; -is $output->lines_after->[0][1], '☃', 'right line'; +is $output->lines_before->[0][1], '☃', 'right line'; +is $output->line->[1], '% die;♥', 'right line'; +is $output->lines_after->[0][1], '☃', 'right line'; # Exception in first line with bad message $mt = Mojo::Template->new; $output = $mt->render('<% die "Test at template line 99\n"; %>'); isa_ok $output, 'Mojo::Exception', 'right exception'; -is $output->message, "Test at template line 99\n", 'right message'; +is $output->message, "Test at template line 99\n", 'right message'; is $output->lines_before->[0], undef, 'no lines before'; is $output->line->[0], 1, 'right number'; is $output->line->[1], '<% die "Test at template line 99\n"; %>', 'right line'; diff --git a/t/mojo/transactor.t b/t/mojo/transactor.t index 9a797ff855..833dcd6c9a 100644 --- a/t/mojo/transactor.t +++ b/t/mojo/transactor.t @@ -35,113 +35,113 @@ subtest 'Compression' => sub { subtest 'Simple GET' => sub { my $tx = $t->tx(GET => 'mojolicious.org/foo.html?bar=baz'); - is $tx->req->url->to_abs, 'http://mojolicious.org/foo.html?bar=baz', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->accept_encoding, 'gzip', 'right "Accept-Encoding" value'; - is $tx->req->headers->user_agent, 'Mojolicious (Perl)', 'right "User-Agent" value'; + is $tx->req->url->to_abs, 'http://mojolicious.org/foo.html?bar=baz', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->accept_encoding, 'gzip', 'right "Accept-Encoding" value'; + is $tx->req->headers->user_agent, 'Mojolicious (Perl)', 'right "User-Agent" value'; }; subtest 'GET with escaped slash' => sub { my $url = Mojo::URL->new('http://mojolicious.org'); $url->path->parts(['foo/bar']); my $tx = $t->tx(GET => $url); - is $tx->req->url->to_string, $url->to_string, 'URLs are equal'; + is $tx->req->url->to_string, $url->to_string, 'URLs are equal'; is $tx->req->url->path->to_string, $url->path->to_string, 'paths are equal'; - is $tx->req->url->path->to_string, 'foo%2Fbar', 'right path'; - is $tx->req->method, 'GET', 'right method'; + is $tx->req->url->path->to_string, 'foo%2Fbar', 'right path'; + is $tx->req->method, 'GET', 'right method'; }; subtest 'POST with header' => sub { $t->name('MyUA 1.0'); my $tx = $t->tx(POST => 'https://mojolicious.org' => {DNT => 1}); - is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->headers->accept_encoding, 'gzip', 'right "Accept-Encoding" value'; - is $tx->req->headers->user_agent, 'MyUA 1.0', 'right "User-Agent" value'; + is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->headers->accept_encoding, 'gzip', 'right "Accept-Encoding" value'; + is $tx->req->headers->user_agent, 'MyUA 1.0', 'right "User-Agent" value'; }; subtest 'POST with header and content' => sub { my $tx = $t->tx(POST => 'https://mojolicious.org' => {DNT => 1} => 'test'); - is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->body, 'test', 'right content'; + is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->body, 'test', 'right content'; }; subtest 'DELETE with content' => sub { my $tx = $t->tx(DELETE => 'https://mojolicious.org' => 'test'); - is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; - is $tx->req->method, 'DELETE', 'right method'; - is $tx->req->headers->dnt, undef, 'no "DNT" value'; - is $tx->req->body, 'test', 'right content'; + is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; + is $tx->req->method, 'DELETE', 'right method'; + is $tx->req->headers->dnt, undef, 'no "DNT" value'; + is $tx->req->body, 'test', 'right content'; }; subtest 'PUT with custom content generator' => sub { my $tx = $t->tx(PUT => 'mojolicious.org', reverse => 'hello!'); - is $tx->req->url->to_abs, 'http://mojolicious.org', 'right URL'; - is $tx->req->method, 'PUT', 'right method'; - is $tx->req->headers->dnt, undef, 'no "DNT" value'; - is $tx->req->body, '!olleh', 'right content'; + is $tx->req->url->to_abs, 'http://mojolicious.org', 'right URL'; + is $tx->req->method, 'PUT', 'right method'; + is $tx->req->headers->dnt, undef, 'no "DNT" value'; + is $tx->req->body, '!olleh', 'right content'; $tx = $t->tx(PUT => 'mojolicious.org', {DNT => 1}, reverse => 'hello!'); - is $tx->req->url->to_abs, 'http://mojolicious.org', 'right URL'; - is $tx->req->method, 'PUT', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->body, '!olleh', 'right content'; + is $tx->req->url->to_abs, 'http://mojolicious.org', 'right URL'; + is $tx->req->method, 'PUT', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->body, '!olleh', 'right content'; }; subtest 'Simple JSON POST' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => json => {test => 123}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'application/json', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'application/json', 'right "Content-Type" value'; is_deeply $tx->req->json, {test => 123}, 'right content'; $tx = $t->tx(POST => 'http://example.com/foo' => json => [1, 2, 3]); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'application/json', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'application/json', 'right "Content-Type" value'; is_deeply $tx->req->json, [1, 2, 3], 'right content'; }; subtest 'JSON POST with headers' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => {DNT => 1}, json => {test => 123}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->headers->content_type, 'application/json', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->headers->content_type, 'application/json', 'right "Content-Type" value'; is_deeply $tx->req->json, {test => 123}, 'right content'; }; subtest 'JSON POST with custom content type' => sub { my $tx = $t->tx( POST => 'http://example.com/foo' => {DNT => 1, 'content-type' => 'application/something'} => json => [1, 2],); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->headers->content_type, 'application/something', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->headers->content_type, 'application/something', 'right "Content-Type" value'; is_deeply $tx->req->json, [1, 2], 'right content'; }; subtest 'Simple form (POST)' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {test => 123}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; - is $tx->req->body, 'test=123', 'right content'; + is $tx->req->body, 'test=123', 'right content'; }; subtest 'Simple form (GET)' => sub { my $tx = $t->tx(GET => 'http://example.com/foo' => form => {test => 123}); - is $tx->req->url->to_abs, 'http://example.com/foo?test=123', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->url->to_abs, 'http://example.com/foo?test=123', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->body, '', 'no content'; }; subtest 'Simple form with multiple values' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {a => [1, 2, 3], b => 4}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; ok !$tx->is_empty, 'transaction is not empty'; is $tx->req->body, 'a=1&a=2&a=3&b=4', 'right content'; @@ -149,63 +149,63 @@ subtest 'Simple form with multiple values' => sub { subtest 'Existing query string (lowercase HEAD)' => sub { my $tx = $t->tx(head => 'http://example.com?foo=bar' => form => {baz => [1, 2]}); - is $tx->req->url->to_abs, 'http://example.com?foo=bar&baz=1&baz=2', 'right URL'; - is $tx->req->method, 'head', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com?foo=bar&baz=1&baz=2', 'right URL'; + is $tx->req->method, 'head', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; ok $tx->is_empty, 'transaction is empty'; is $tx->req->body, '', 'no content'; }; subtest 'UTF-8 query' => sub { my $tx = $t->tx(GET => 'http://example.com/foo' => form => {a => '☃', b => '♥'}); - is $tx->req->url->to_abs, 'http://example.com/foo?a=%E2%98%83&b=%E2%99%A5', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->url->to_abs, 'http://example.com/foo?a=%E2%98%83&b=%E2%99%A5', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->body, '', 'no content'; }; subtest 'UTF-8 form' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {'♥' => '☃'}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; - is $tx->req->body, '%E2%99%A5=%E2%98%83', 'right content'; - is $tx->req->param('♥'), '☃', 'right value'; + is $tx->req->body, '%E2%99%A5=%E2%98%83', 'right content'; + is $tx->req->param('♥'), '☃', 'right value'; }; subtest 'UTF-8 form with header and custom content type' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => {Accept => '*/*', 'Content-Type' => 'application/mojo-form'} => form => {'♥' => '☃', nothing => undef}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'application/mojo-form', 'right "Content-Type" value'; - is $tx->req->headers->accept, '*/*', 'right "Accept" value'; - is $tx->req->body, '%E2%99%A5=%E2%98%83', 'right content'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'application/mojo-form', 'right "Content-Type" value'; + is $tx->req->headers->accept, '*/*', 'right "Accept" value'; + is $tx->req->body, '%E2%99%A5=%E2%98%83', 'right content'; }; subtest 'Form (shift_jis)' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {'やった' => 'やった'} => charset => 'shift_jis'); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; - is $tx->req->body, '%82%E2%82%C1%82%BD=%82%E2%82%C1%82%BD', 'right content'; - is $tx->req->default_charset('shift_jis')->param('やった'), 'やった', 'right value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'application/x-www-form-urlencoded', 'right "Content-Type" value'; + is $tx->req->body, '%82%E2%82%C1%82%BD=%82%E2%82%C1%82%BD', 'right content'; + is $tx->req->default_charset('shift_jis')->param('やった'), 'やった', 'right value'; }; subtest 'UTF-8 multipart form' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => {'Content-Type' => 'multipart/form-data'} => form => {'♥' => '☃', nothing => undef}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"@{[encode 'UTF-8', '♥']}"/, 'right "Content-Disposition" value'; is $tx->req->content->parts->[0]->asset->slurp, encode('UTF-8', '☃'), 'right part'; ok !$tx->req->content->parts->[0]->asset->is_file, 'stored in memory'; ok !$tx->req->content->parts->[0]->asset->auto_upgrade, 'no upgrade'; is $tx->req->content->parts->[1], undef, 'no more parts'; - is $tx->req->param('♥'), '☃', 'right value'; + is $tx->req->param('♥'), '☃', 'right value'; }; subtest 'Multipart form (shift_jis)' => sub { @@ -213,64 +213,64 @@ subtest 'Multipart form (shift_jis)' => sub { = $t->tx( POST => 'http://example.com/foo' => {'Content-Type' => 'multipart/form-data'} => form => {'やった' => 'やった'} => charset => 'shift_jis'); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"@{[encode 'shift_jis', 'やった']}"/, 'right "Content-Disposition" value'; is $tx->req->content->parts->[0]->asset->slurp, encode('shift_jis', 'やった'), 'right part'; ok !$tx->req->content->parts->[0]->asset->is_file, 'stored in memory'; ok !$tx->req->content->parts->[0]->asset->auto_upgrade, 'no upgrade'; - is $tx->req->content->parts->[1], undef, 'no more parts'; + is $tx->req->content->parts->[1], undef, 'no more parts'; is $tx->req->default_charset('shift_jis')->param('やった'), 'やった', 'right value'; }; subtest 'Multipart form with multiple values' => sub { my $tx = $t->tx( POST => 'http://example.com/foo' => {'Content-Type' => 'multipart/form-data'} => form => {a => [1, 2, 3], b => 4}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"a"/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[0]->asset->slurp, 1, 'right part'; + is $tx->req->content->parts->[0]->asset->slurp, 1, 'right part'; like $tx->req->content->parts->[1]->headers->content_disposition, qr/"a"/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[1]->asset->slurp, 2, 'right part'; + is $tx->req->content->parts->[1]->asset->slurp, 2, 'right part'; like $tx->req->content->parts->[2]->headers->content_disposition, qr/"a"/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[2]->asset->slurp, 3, 'right part'; + is $tx->req->content->parts->[2]->asset->slurp, 3, 'right part'; like $tx->req->content->parts->[3]->headers->content_disposition, qr/"b"/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[3]->asset->slurp, 4, 'right part'; - is $tx->req->content->parts->[4], undef, 'no more parts'; + is $tx->req->content->parts->[3]->asset->slurp, 4, 'right part'; + is $tx->req->content->parts->[4], undef, 'no more parts'; is_deeply $tx->req->every_param('a'), [1, 2, 3], 'right values'; is $tx->req->param('b'), 4, 'right value'; }; subtest 'Multipart form with real file and custom header' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {mytext => {file => __FILE__, DNT => 1}}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"mytext"/, 'right "Content-Disposition" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"transactor.t"/, 'right "Content-Disposition" value'; like $tx->req->content->parts->[0]->asset->slurp, qr/mytext/, 'right part'; - ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file'; + ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file'; ok !$tx->req->content->parts->[0]->headers->header('file'), 'no "file" header'; - is $tx->req->content->parts->[0]->headers->dnt, 1, 'right "DNT" header'; - is $tx->req->content->parts->[1], undef, 'no more parts'; + is $tx->req->content->parts->[0]->headers->dnt, 1, 'right "DNT" header'; + is $tx->req->content->parts->[1], undef, 'no more parts'; }; subtest 'Multipart form with custom Content-Disposition header' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {mytext => {file => __FILE__, 'Content-Disposition' => 'form-data; name="works"'}}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; unlike $tx->req->content->parts->[0]->headers->content_disposition, qr/"transactor.t"/, 'different "Content-Disposition" value'; is $tx->req->content->parts->[0]->headers->content_disposition, 'form-data; name="works"', 'right "Content-Disposition" value'; like $tx->req->content->parts->[0]->asset->slurp, qr/mytext/, 'right part'; - ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file'; + ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file'; ok !$tx->req->content->parts->[0]->headers->header('file'), 'no "file" header'; is $tx->req->content->parts->[1], undef, 'no more parts'; }; @@ -278,9 +278,9 @@ subtest 'Multipart form with custom Content-Disposition header' => sub { subtest 'Multipart form with asset and custom content type' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => {'Content-Type' => 'multipart/mojo-form'} => form => {mytext => {file => Mojo::Asset::File->new(path => __FILE__)}}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/mojo-form', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/mojo-form', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"mytext"/, 'right "Content-Disposition" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/"transactor.t"/, 'right "Content-Disposition" value'; @@ -291,9 +291,9 @@ subtest 'Multipart form with asset and custom content type' => sub { subtest 'Multipart form with in-memory content' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {mytext => {content => 'lalala'}}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/mytext/, 'right "Content-Disposition" value'; ok !$tx->req->content->parts->[0]->headers->header('content'), 'no "content" header'; is $tx->req->content->parts->[0]->asset->slurp, 'lalala', 'right part'; @@ -304,94 +304,94 @@ subtest 'Multipart form with in-memory content' => sub { subtest 'Multipart form with filename ("0")' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {0 => {content => 'whatever', filename => '0'}}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/0/, 'right "Content-Disposition" value'; ok !$tx->req->content->parts->[0]->headers->header('filename'), 'no "filename" header'; is $tx->req->content->parts->[0]->asset->slurp, 'whatever', 'right part'; - is $tx->req->content->parts->[1], undef, 'no more parts'; - is $tx->req->upload('0')->filename, '0', 'right filename'; - is $tx->req->upload('0')->size, 8, 'right size'; - is $tx->req->upload('0')->slurp, 'whatever', 'right content'; + is $tx->req->content->parts->[1], undef, 'no more parts'; + is $tx->req->upload('0')->filename, '0', 'right filename'; + is $tx->req->upload('0')->size, 8, 'right size'; + is $tx->req->upload('0')->slurp, 'whatever', 'right content'; }; subtest 'Multipart form with asset and filename (UTF-8)' => sub { my $snowman = encode 'UTF-8', '☃'; my $tx = $t->tx(POST => 'http://example.com/foo' => form => {'"☃"' => {file => Mojo::Asset::Memory->new->add_chunk('snowman'), filename => '"☃".jpg'}}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/$snowman/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[0]->asset->slurp, 'snowman', 'right part'; - is $tx->req->content->parts->[1], undef, 'no more parts'; - is $tx->req->upload('%22☃%22')->filename, '%22☃%22.jpg', 'right filename'; - is $tx->req->upload('%22☃%22')->size, 7, 'right size'; - is $tx->req->upload('%22☃%22')->slurp, 'snowman', 'right content'; + is $tx->req->content->parts->[0]->asset->slurp, 'snowman', 'right part'; + is $tx->req->content->parts->[1], undef, 'no more parts'; + is $tx->req->upload('%22☃%22')->filename, '%22☃%22.jpg', 'right filename'; + is $tx->req->upload('%22☃%22')->size, 7, 'right size'; + is $tx->req->upload('%22☃%22')->slurp, 'snowman', 'right content'; }; subtest 'Multipart form with multiple uploads sharing the same name' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => form => {mytext => [{content => 'just', filename => 'one.txt'}, {content => 'works', filename => 'two.txt'}]}); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, 'multipart/form-data', 'right "Content-Type" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/mytext/, 'right "Content-Disposition" value'; like $tx->req->content->parts->[0]->headers->content_disposition, qr/one\.txt/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[0]->asset->slurp, 'just', 'right part'; + is $tx->req->content->parts->[0]->asset->slurp, 'just', 'right part'; like $tx->req->content->parts->[1]->headers->content_disposition, qr/mytext/, 'right "Content-Disposition" value'; like $tx->req->content->parts->[1]->headers->content_disposition, qr/two\.txt/, 'right "Content-Disposition" value'; - is $tx->req->content->parts->[1]->asset->slurp, 'works', 'right part'; - is $tx->req->content->parts->[2], undef, 'no more parts'; + is $tx->req->content->parts->[1]->asset->slurp, 'works', 'right part'; + is $tx->req->content->parts->[2], undef, 'no more parts'; }; subtest 'Multipart request (long)' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => multipart => [{content => 'just'}, {content => 'works'}]); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; is $tx->req->content->parts->[0]->headers->content_disposition, undef, 'no "Content-Disposition" value'; is $tx->req->content->parts->[0]->asset->slurp, 'just', 'right part'; is $tx->req->content->parts->[1]->headers->content_disposition, undef, 'no "Content-Disposition" value'; is $tx->req->content->parts->[1]->asset->slurp, 'works', 'right part'; - is $tx->req->content->parts->[2], undef, 'no more parts'; + is $tx->req->content->parts->[2], undef, 'no more parts'; }; subtest 'Multipart request (short)' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => multipart => ['just', 'works']); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; is $tx->req->content->parts->[0]->headers->content_disposition, undef, 'no "Content-Disposition" value'; is $tx->req->content->parts->[0]->asset->slurp, 'just', 'right part'; is $tx->req->content->parts->[1]->headers->content_disposition, undef, 'no "Content-Disposition" value'; is $tx->req->content->parts->[1]->asset->slurp, 'works', 'right part'; - is $tx->req->content->parts->[2], undef, 'no more parts'; + is $tx->req->content->parts->[2], undef, 'no more parts'; }; subtest 'Multipart request with asset' => sub { my $tx = $t->tx( POST => 'http://example.com/foo' => multipart => [{file => Mojo::Asset::Memory->new->add_chunk('snowman')}]); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; is $tx->req->content->parts->[0]->headers->content_disposition, undef, 'no "Content-Disposition" value'; is $tx->req->content->parts->[0]->asset->slurp, 'snowman', 'right part'; - is $tx->req->content->parts->[1], undef, 'no more parts'; + is $tx->req->content->parts->[1], undef, 'no more parts'; }; subtest 'Multipart request with real file and custom header' => sub { my $tx = $t->tx(POST => 'http://example.com/foo' => multipart => [{file => __FILE__, DNT => 1}]); - is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; - is $tx->req->method, 'POST', 'right method'; - is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; + is $tx->req->url->to_abs, 'http://example.com/foo', 'right URL'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; like $tx->req->content->parts->[0]->asset->slurp, qr/mytext/, 'right part'; ok $tx->req->content->parts->[0]->asset->is_file, 'stored in file'; - is $tx->req->content->parts->[0]->headers->header('file'), undef, 'no "file" header'; + is $tx->req->content->parts->[0]->headers->header('file'), undef, 'no "file" header'; is $tx->req->content->parts->[0]->headers->content_disposition, undef, 'no "Content-Disposition" value'; is $tx->req->content->parts->[0]->headers->dnt, 1, 'right "DNT" header'; - is $tx->req->content->parts->[1], undef, 'no more parts'; + is $tx->req->content->parts->[1], undef, 'no more parts'; }; subtest 'Simple endpoint' => sub { @@ -553,14 +553,14 @@ subtest 'TLS WebSocket peer with proxy' => sub { subtest 'WebSocket handshake' => sub { my $tx = $t->websocket('ws://127.0.0.1:3000/echo'); ok !$tx->is_websocket, 'not a WebSocket'; - is $tx->req->url->to_abs, 'http://127.0.0.1:3000/echo', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; + is $tx->req->url->to_abs, 'http://127.0.0.1:3000/echo', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; ok !$tx->req->headers->sec_websocket_protocol, 'no "Sec-WebSocket-Protocol" header'; - ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; + ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; is $tx->req->headers->upgrade, 'websocket', 'right "Upgrade" value'; - is $t->upgrade($tx), undef, 'not upgraded'; + is $t->upgrade($tx), undef, 'not upgraded'; server_handshake $tx; $tx->res->code(101); $tx = $t->upgrade($tx); @@ -569,34 +569,34 @@ subtest 'WebSocket handshake' => sub { subtest 'WebSocket handshake with header' => sub { my $tx = $t->websocket('wss://127.0.0.1:3000/echo' => {DNT => 1}); - is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; + is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; ok !$tx->req->headers->sec_websocket_protocol, 'no "Sec-WebSocket-Protocol" header'; - ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; + ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; is $tx->req->headers->upgrade, 'websocket', 'right "Upgrade" value'; }; subtest 'WebSocket handshake with protocol' => sub { my $tx = $t->websocket('wss://127.0.0.1:3000/echo' => ['foo']); - is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; - is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; - is $tx->req->headers->sec_websocket_protocol, 'foo', 'right "Sec-WebSocket-Protocol" value'; - ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; - is $tx->req->headers->upgrade, 'websocket', 'right "Upgrade" value'; + is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; + is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; + is $tx->req->headers->sec_websocket_protocol, 'foo', 'right "Sec-WebSocket-Protocol" value'; + ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; + is $tx->req->headers->upgrade, 'websocket', 'right "Upgrade" value'; }; subtest 'WebSocket handshake with header and protocols' => sub { my $tx = $t->websocket('wss://127.0.0.1:3000/echo' => {DNT => 1} => ['v1.bar.example.com', 'foo', 'v2.baz.example.com']); - is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; + is $tx->req->url->to_abs, 'https://127.0.0.1:3000/echo', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; is $tx->req->headers->sec_websocket_protocol, 'v1.bar.example.com, foo, v2.baz.example.com', 'right "Sec-WebSocket-Protocol" value'; @@ -606,13 +606,13 @@ subtest 'WebSocket handshake with header and protocols' => sub { subtest 'WebSocket handshake with UNIX domain socket' => sub { my $tx = $t->websocket('ws+unix://%2Ftmp%2Fmyapp.sock/echo' => {DNT => 1}); - is $tx->req->url->to_abs, 'http+unix://%2Ftmp%2Fmyapp.sock/echo', 'right URL'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->headers->dnt, 1, 'right "DNT" value'; - is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; - is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; + is $tx->req->url->to_abs, 'http+unix://%2Ftmp%2Fmyapp.sock/echo', 'right URL'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->headers->dnt, 1, 'right "DNT" value'; + is $tx->req->headers->connection, 'Upgrade', 'right "Connection" value'; + is length(b64_decode $tx->req->headers->sec_websocket_key), 16, '16 byte "Sec-WebSocket-Key" value'; ok !$tx->req->headers->sec_websocket_protocol, 'no "Sec-WebSocket-Protocol" header'; - ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; + ok $tx->req->headers->sec_websocket_version, 'has "Sec-WebSocket-Version" value'; is $tx->req->headers->upgrade, 'websocket', 'right "Upgrade" value'; }; @@ -625,7 +625,7 @@ subtest 'Proxy CONNECT' => sub { is $tx->req->headers->authorization, 'Basic c3JpOnNlY3IzdA==', 'right "Authorization" header'; is $tx->req->headers->proxy_authorization, 'Basic c3JpOnNlY3IzdA==', 'right "Proxy-Authorization" header'; $tx = $t->proxy_connect($tx); - is $tx->req->method, 'CONNECT', 'right method'; + is $tx->req->method, 'CONNECT', 'right method'; is $tx->req->url->to_abs, 'https://mojolicious.org', 'right URL'; is $tx->req->proxy->to_abs, 'http://127.0.0.1:3000', 'right proxy URL'; ok !$tx->req->headers->authorization, 'no "Authorization" header'; @@ -635,7 +635,7 @@ subtest 'Proxy CONNECT' => sub { ok !$tx->req->headers->authorization, 'no "Authorization" header'; is $tx->req->headers->proxy_authorization, 'Basic c3JpOnNlY3IzdA==', 'right "Proxy-Authorization" header'; is $tx->req->headers->host, 'mojolicious.org', 'right "Host" header'; - is $t->proxy_connect($tx), undef, 'already a CONNECT request'; + is $t->proxy_connect($tx), undef, 'already a CONNECT request'; $tx->req->method('Connect'); is $t->proxy_connect($tx), undef, 'already a CONNECT request'; $tx = $t->tx(GET => 'https://mojolicious.org'); @@ -652,48 +652,48 @@ subtest 'Simple 301 redirect' => sub { $tx->res->code(301); $tx->res->headers->location('http://example.com/bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->user_agent, 'MyUA 1.0', 'right "User-Agent" value'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '301 redirect with content' => sub { my $tx = $t->tx(POST => 'http://mojolicious.org/foo' => {Accept => '*/*'} => 'whatever'); $tx->res->code(301); $tx->res->headers->location('http://example.com/bar'); - is $tx->req->headers->accept, '*/*', 'right "Accept" value'; - is $tx->req->body, 'whatever', 'right content'; + is $tx->req->headers->accept, '*/*', 'right "Accept" value'; + is $tx->req->body, 'whatever', 'right content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, '*/*', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '301 redirect with content (DELETE)' => sub { my $tx = $t->tx(DELETE => 'http://mojolicious.org/foo' => {Accept => '*/*'} => 'whatever'); $tx->res->code(301); $tx->res->headers->location('http://example.com/bar'); - is $tx->req->headers->accept, '*/*', 'right "Accept" value'; - is $tx->req->body, 'whatever', 'right content'; + is $tx->req->headers->accept, '*/*', 'right "Accept" value'; + is $tx->req->body, 'whatever', 'right content'; $tx = $t->redirect($tx); - is $tx->req->method, 'DELETE', 'right method'; + is $tx->req->method, 'DELETE', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, '*/*', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest 'Simple 302 redirect' => sub { @@ -701,15 +701,15 @@ subtest 'Simple 302 redirect' => sub { $tx->res->code(302); $tx->res->headers->location('http://example.com/bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '302 redirect (lowercase HEAD)' => sub { @@ -717,13 +717,13 @@ subtest '302 redirect (lowercase HEAD)' => sub { $tx->res->code(302); $tx->res->headers->location('http://example.com/bar'); $tx = $t->redirect($tx); - is $tx->req->method, 'HEAD', 'right method'; + is $tx->req->method, 'HEAD', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, undef, 'no "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '302 redirect (dynamic)' => sub { @@ -732,13 +732,13 @@ subtest '302 redirect (dynamic)' => sub { $tx->res->headers->location('http://example.com/bar'); $tx->req->content->write_chunk('whatever' => sub { shift->finish }); $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, undef, 'no "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '302 redirect with content' => sub { @@ -749,17 +749,17 @@ subtest '302 redirect with content' => sub { is $tx->req->headers->accept, '*/*', 'right "Accept" value'; is $tx->req->headers->content_type, 'text/plain', 'right "Content-Type" value'; is $tx->req->headers->content_length, 8, 'right "Content-Length" value'; - is $tx->req->body, 'whatever', 'right content'; + is $tx->req->body, 'whatever', 'right content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, '*/*', 'right "Accept" value'; is $tx->req->headers->content_type, undef, 'no "Content-Type" value'; is $tx->req->headers->content_length, undef, 'no "Content-Length" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest 'Simple 303 redirect' => sub { @@ -767,15 +767,15 @@ subtest 'Simple 303 redirect' => sub { $tx->res->code(303); $tx->res->headers->location('http://example.com/bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '303 redirect (dynamic)' => sub { @@ -784,13 +784,13 @@ subtest '303 redirect (dynamic)' => sub { $tx->res->headers->location('http://example.com/bar'); $tx->req->content->write_chunk('whatever' => sub { shift->finish }); $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, undef, 'no "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '303 redirect (additional headers)' => sub { @@ -803,9 +803,9 @@ subtest '303 redirect (additional headers)' => sub { is $tx->req->headers->cookie, 'two', 'right "Cookie" value'; is $tx->req->headers->host, 'three', 'right "Host" value'; is $tx->req->headers->referrer, 'four', 'right "Referer" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->authorization, undef, 'no "Authorization" value'; @@ -813,9 +813,9 @@ subtest '303 redirect (additional headers)' => sub { is $tx->req->headers->host, undef, 'no "Host" value'; is $tx->req->headers->location, undef, 'no "Location" value'; is $tx->req->headers->referrer, undef, 'no "Referer" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest 'Simple 307 redirect' => sub { @@ -823,31 +823,31 @@ subtest 'Simple 307 redirect' => sub { $tx->res->code(307); $tx->res->headers->location('http://example.com/bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'POST', 'right method'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '307 redirect with content' => sub { my $tx = $t->tx(POST => 'http://mojolicious.org/foo' => {Accept => '*/*'} => 'whatever'); $tx->res->code(307); $tx->res->headers->location('http://example.com/bar'); - is $tx->req->headers->accept, '*/*', 'right "Accept" value'; - is $tx->req->body, 'whatever', 'right content'; + is $tx->req->headers->accept, '*/*', 'right "Accept" value'; + is $tx->req->body, 'whatever', 'right content'; $tx = $t->redirect($tx); - is $tx->req->method, 'POST', 'right method'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, '*/*', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, 'whatever', 'right content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, 'whatever', 'right content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '307 redirect (dynamic)' => sub { @@ -868,9 +868,9 @@ subtest '307 redirect (additional headers)' => sub { is $tx->req->headers->cookie, 'two', 'right "Cookie" value'; is $tx->req->headers->host, 'three', 'right "Host" value'; is $tx->req->headers->referrer, 'four', 'right "Referer" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'POST', 'right method'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->authorization, undef, 'no "Authorization" value'; @@ -878,9 +878,9 @@ subtest '307 redirect (additional headers)' => sub { is $tx->req->headers->host, undef, 'no "Host" value'; is $tx->req->headers->location, undef, 'no "Location" value'; is $tx->req->headers->referrer, undef, 'no "Referer" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest 'Simple 308 redirect' => sub { @@ -888,31 +888,31 @@ subtest 'Simple 308 redirect' => sub { $tx->res->code(308); $tx->res->headers->location('http://example.com/bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'POST', 'right method'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '308 redirect with content' => sub { my $tx = $t->tx(POST => 'http://mojolicious.org/foo' => {Accept => '*/*'} => 'whatever'); $tx->res->code(308); $tx->res->headers->location('https://example.com/bar'); - is $tx->req->headers->accept, '*/*', 'right "Accept" value'; - is $tx->req->body, 'whatever', 'right content'; + is $tx->req->headers->accept, '*/*', 'right "Accept" value'; + is $tx->req->body, 'whatever', 'right content'; $tx = $t->redirect($tx); - is $tx->req->method, 'POST', 'right method'; + is $tx->req->method, 'POST', 'right method'; is $tx->req->url->to_abs, 'https://example.com/bar', 'right URL'; is $tx->req->headers->accept, '*/*', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, 'whatever', 'right content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, 'whatever', 'right content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '308 redirect (dynamic)' => sub { @@ -928,8 +928,8 @@ subtest '309 redirect (unsupported)' => sub { $tx->res->code(309); $tx->res->headers->location('http://example.com/bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; - is $t->redirect($tx), undef, 'unsupported redirect'; + is $tx->req->body, '', 'no content'; + is $t->redirect($tx), undef, 'unsupported redirect'; }; subtest '302 redirect with bad location' => sub { @@ -949,12 +949,12 @@ subtest '302 redirect with multiple locations' => sub { $tx->res->headers->add(Location => 'http://example.com/1.html'); $tx->res->headers->add(Location => 'http://example.com/2.html'); $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://example.com/1.html', 'right URL'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '302 redirect (relative path and query)' => sub { @@ -962,16 +962,16 @@ subtest '302 redirect (relative path and query)' => sub { $tx->res->code(302); $tx->res->headers->location('baz?f%23oo=bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://mojolicious.org/foo/baz?f%23oo=bar', 'right URL'; is $tx->req->url->query, 'f%23oo=bar', 'right query'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '302 redirect (absolute path and query)' => sub { @@ -979,16 +979,16 @@ subtest '302 redirect (absolute path and query)' => sub { $tx->res->code(302); $tx->res->headers->location('/baz?f%23oo=bar'); is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->body, '', 'no content'; + is $tx->req->body, '', 'no content'; $tx = $t->redirect($tx); - is $tx->req->method, 'GET', 'right method'; + is $tx->req->method, 'GET', 'right method'; is $tx->req->url->to_abs, 'http://mojolicious.org/baz?f%23oo=bar', 'right URL'; is $tx->req->url->query, 'f%23oo=bar', 'right query'; is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest '302 redirect for CONNECT request' => sub { @@ -1005,15 +1005,15 @@ subtest '301 redirect without compression' => sub { $tx->res->headers->location('http://example.com/bar'); is $tx->res->content->auto_decompress, 0, 'right value'; $tx = $t->redirect($tx); - is $tx->res->content->auto_decompress, 0, 'right value'; - is $tx->req->method, 'GET', 'right method'; - is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; - is $tx->req->headers->user_agent, 'Mojolicious (Perl)', 'right "User-Agent" value'; - is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; - is $tx->req->headers->location, undef, 'no "Location" value'; - is $tx->req->body, '', 'no content'; - is $tx->res->code, undef, 'no status'; - is $tx->res->headers->location, undef, 'no "Location" value'; + is $tx->res->content->auto_decompress, 0, 'right value'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->url->to_abs, 'http://example.com/bar', 'right URL'; + is $tx->req->headers->user_agent, 'Mojolicious (Perl)', 'right "User-Agent" value'; + is $tx->req->headers->accept, 'application/json', 'right "Accept" value'; + is $tx->req->headers->location, undef, 'no "Location" value'; + is $tx->req->body, '', 'no content'; + is $tx->res->code, undef, 'no status'; + is $tx->res->headers->location, undef, 'no "Location" value'; }; subtest 'Promisify' => sub { @@ -1024,15 +1024,15 @@ subtest 'Promisify' => sub { $t->promisify($promise, $tx); $promise->wait; is_deeply \@results, [$tx], 'promise resolved'; - is_deeply \@errors, [], 'promise not rejected'; + is_deeply \@errors, [], 'promise not rejected'; $promise = Mojo::Promise->new; (@results, @errors) = (); $promise->then(sub { push @results, @_ }, sub { push @errors, @_ }); $tx = $t->websocket('/'); $t->promisify($promise, $tx); $promise->wait; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, ['WebSocket handshake failed'], 'promise rejected'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, ['WebSocket handshake failed'], 'promise rejected'; $promise = Mojo::Promise->new; (@results, @errors) = (); $promise->then(sub { push @results, @_ }, sub { push @errors, @_ }); @@ -1040,8 +1040,8 @@ subtest 'Promisify' => sub { $tx->res->error({message => 'Premature connection close'}); $t->promisify($promise, $tx); $promise->wait; - is_deeply \@results, [], 'promise not resolved'; - is_deeply \@errors, ['Premature connection close'], 'promise rejected'; + is_deeply \@results, [], 'promise not resolved'; + is_deeply \@errors, ['Premature connection close'], 'promise rejected'; }; subtest 'Abstract methods' => sub { diff --git a/t/mojo/url.t b/t/mojo/url.t index 59b94af43b..c82a68294b 100644 --- a/t/mojo/url.t +++ b/t/mojo/url.t @@ -5,47 +5,47 @@ use Mojo::URL; subtest 'Simple' => sub { my $url = Mojo::URL->new('HtTp://Example.Com'); - is $url->scheme, 'HtTp', 'right scheme'; - is $url->protocol, 'http', 'right protocol'; - is $url->host, 'Example.Com', 'right host'; - is $url->ihost, 'Example.Com', 'right internationalized host'; - is "$url", 'http://Example.Com', 'right format'; + is $url->scheme, 'HtTp', 'right scheme'; + is $url->protocol, 'http', 'right protocol'; + is $url->host, 'Example.Com', 'right host'; + is $url->ihost, 'Example.Com', 'right internationalized host'; + is "$url", 'http://Example.Com', 'right format'; }; subtest 'Advanced' => sub { my $url = Mojo::URL->new('https://sri:foobar@example.com:8080/x/index.html?monkey=biz&foo=1#/!%?@3'); - ok $url->is_abs, 'is absolute'; - is $url->scheme, 'https', 'right scheme'; - is $url->protocol, 'https', 'right protocol'; - is $url->userinfo, 'sri:foobar', 'right userinfo'; - is $url->username, 'sri', 'right username'; - is $url->password, 'foobar', 'right password'; - is $url->host, 'example.com', 'right host'; - is $url->port, '8080', 'right port'; - is $url->path, '/x/index.html', 'right path'; - is $url->query, 'monkey=biz&foo=1', 'right query'; - is $url->path_query, '/x/index.html?monkey=biz&foo=1', 'right path and query'; - is $url->fragment, '/!%?@3', 'right fragment'; - is "$url", 'https://example.com:8080/x/index.html?monkey=biz&foo=1#/!%25?@3', 'right format'; + ok $url->is_abs, 'is absolute'; + is $url->scheme, 'https', 'right scheme'; + is $url->protocol, 'https', 'right protocol'; + is $url->userinfo, 'sri:foobar', 'right userinfo'; + is $url->username, 'sri', 'right username'; + is $url->password, 'foobar', 'right password'; + is $url->host, 'example.com', 'right host'; + is $url->port, '8080', 'right port'; + is $url->path, '/x/index.html', 'right path'; + is $url->query, 'monkey=biz&foo=1', 'right query'; + is $url->path_query, '/x/index.html?monkey=biz&foo=1', 'right path and query'; + is $url->fragment, '/!%?@3', 'right fragment'; + is "$url", 'https://example.com:8080/x/index.html?monkey=biz&foo=1#/!%25?@3', 'right format'; $url->path('/index.xml'); is "$url", 'https://example.com:8080/index.xml?monkey=biz&foo=1#/!%25?@3', 'right format'; }; subtest 'Advanced userinfo and fragment roundtrip' => sub { my $url = Mojo::URL->new('ws://AZaz09-._~!$&\'()*+,;=:@localhost#AZaz09-._~!$&\'()*+,;=:@/?'); - is $url->scheme, 'ws', 'right scheme'; - is $url->userinfo, 'AZaz09-._~!$&\'()*+,;=:', 'right userinfo'; - is $url->username, 'AZaz09-._~!$&\'()*+,;=', 'right username'; - is $url->password, '', 'right password'; - is $url->host, 'localhost', 'right host'; - is $url->fragment, 'AZaz09-._~!$&\'()*+,;=:@/?', 'right fragment'; - is "$url", 'ws://localhost#AZaz09-._~!$&\'()*+,;=:@/?', 'right format'; + is $url->scheme, 'ws', 'right scheme'; + is $url->userinfo, 'AZaz09-._~!$&\'()*+,;=:', 'right userinfo'; + is $url->username, 'AZaz09-._~!$&\'()*+,;=', 'right username'; + is $url->password, '', 'right password'; + is $url->host, 'localhost', 'right host'; + is $url->fragment, 'AZaz09-._~!$&\'()*+,;=:@/?', 'right fragment'; + is "$url", 'ws://localhost#AZaz09-._~!$&\'()*+,;=:@/?', 'right format'; is $url->to_unsafe_string, 'ws://AZaz09-._~!$&\'()*+,;=:@localhost#AZaz09-._~!$&\'()*+,;=:@/?', 'right format'; }; subtest 'Parameters' => sub { my $url = Mojo::URL->new('http://sri:foobar@example.com:8080?_monkey=biz%3B&_monkey=23#23'); - ok $url->is_abs, 'is absolute'; + ok $url->is_abs, 'is absolute'; is $url->scheme, 'http', 'right scheme'; is $url->userinfo, 'sri:foobar', 'right userinfo'; is $url->host, 'example.com', 'right host'; @@ -53,8 +53,8 @@ subtest 'Parameters' => sub { is $url->path, '', 'no path'; is $url->query, '_monkey=biz%3B&_monkey=23', 'right query'; is_deeply $url->query->to_hash, {_monkey => ['biz;', 23]}, 'right structure'; - is $url->fragment, '23', 'right fragment'; - is "$url", 'http://example.com:8080?_monkey=biz%3B&_monkey=23#23', 'right format'; + is $url->fragment, '23', 'right fragment'; + is "$url", 'http://example.com:8080?_monkey=biz%3B&_monkey=23#23', 'right format'; $url->query(monkey => 'foo'); is "$url", 'http://example.com:8080?monkey=foo#23', 'right format'; $url->query({monkey => 'bar'}); @@ -83,7 +83,7 @@ subtest 'Parameters' => sub { subtest 'Query string' => sub { my $url = Mojo::URL->new('wss://sri:foo:bar@example.com:8080?_monkeybiz%3B&_monkey;23#23'); - ok $url->is_abs, 'is absolute'; + ok $url->is_abs, 'is absolute'; is $url->scheme, 'wss', 'right scheme'; is $url->userinfo, 'sri:foo:bar', 'right userinfo'; is $url->username, 'sri', 'right username'; @@ -93,80 +93,80 @@ subtest 'Query string' => sub { is $url->path, '', 'no path'; is $url->query, '_monkeybiz%3B&_monkey;23', 'right query'; is_deeply $url->query->pairs, ['_monkeybiz;', '', '_monkey;23', ''], 'right structure'; - is $url->query, '_monkeybiz%3B=&_monkey%3B23=', 'right query'; - is $url->fragment, '23', 'right fragment'; - is "$url", 'wss://example.com:8080?_monkeybiz%3B=&_monkey%3B23=#23', 'right format'; + is $url->query, '_monkeybiz%3B=&_monkey%3B23=', 'right query'; + is $url->fragment, '23', 'right fragment'; + is "$url", 'wss://example.com:8080?_monkeybiz%3B=&_monkey%3B23=#23', 'right format'; $url = Mojo::URL->new('https://example.com/0?0#0'); - ok $url->is_abs, 'is absolute'; - is $url->scheme, 'https', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->username, undef, 'no username'; - is $url->password, undef, 'no password'; - is $url->host, 'example.com', 'right host'; - is $url->port, undef, 'no port'; - is $url->host_port, 'example.com', 'right host and port'; - is $url->path, '/0', 'no path'; - is $url->query, '0', 'right query'; - is $url->fragment, '0', 'right fragment'; - is "$url", 'https://example.com/0?0#0', 'right format'; + ok $url->is_abs, 'is absolute'; + is $url->scheme, 'https', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->username, undef, 'no username'; + is $url->password, undef, 'no password'; + is $url->host, 'example.com', 'right host'; + is $url->port, undef, 'no port'; + is $url->host_port, 'example.com', 'right host and port'; + is $url->path, '/0', 'no path'; + is $url->query, '0', 'right query'; + is $url->fragment, '0', 'right fragment'; + is "$url", 'https://example.com/0?0#0', 'right format'; }; subtest 'No authority' => sub { my $url = Mojo::URL->new('DATA:image/png;base64,helloworld123'); - is $url->scheme, 'DATA', 'right scheme'; - is $url->protocol, 'data', 'right protocol'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, undef, 'no host'; - is $url->port, undef, 'no port'; - is $url->path, 'image/png;base64,helloworld123', 'right path'; - is $url->query, '', 'no query'; - is $url->fragment, undef, 'no fragment'; - is "$url", 'data:image/png;base64,helloworld123', 'right format'; + is $url->scheme, 'DATA', 'right scheme'; + is $url->protocol, 'data', 'right protocol'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, undef, 'no host'; + is $url->port, undef, 'no port'; + is $url->path, 'image/png;base64,helloworld123', 'right path'; + is $url->query, '', 'no query'; + is $url->fragment, undef, 'no fragment'; + is "$url", 'data:image/png;base64,helloworld123', 'right format'; $url = $url->clone; - is $url->scheme, 'DATA', 'right scheme'; - is $url->protocol, 'data', 'right protocol'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, undef, 'no host'; - is $url->port, undef, 'no port'; - is $url->path, 'image/png;base64,helloworld123', 'right path'; - is $url->query, '', 'no query'; - is $url->fragment, undef, 'no fragment'; - is "$url", 'data:image/png;base64,helloworld123', 'right format'; + is $url->scheme, 'DATA', 'right scheme'; + is $url->protocol, 'data', 'right protocol'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, undef, 'no host'; + is $url->port, undef, 'no port'; + is $url->path, 'image/png;base64,helloworld123', 'right path'; + is $url->query, '', 'no query'; + is $url->fragment, undef, 'no fragment'; + is "$url", 'data:image/png;base64,helloworld123', 'right format'; $url = Mojo::URL->new->parse('mailto:sri@example.com'); - is $url->scheme, 'mailto', 'right scheme'; - is $url->protocol, 'mailto', 'right protocol'; - is $url->path, 'sri@example.com', 'right path'; - is "$url", 'mailto:sri@example.com', 'right format'; + is $url->scheme, 'mailto', 'right scheme'; + is $url->protocol, 'mailto', 'right protocol'; + is $url->path, 'sri@example.com', 'right path'; + is "$url", 'mailto:sri@example.com', 'right format'; $url = Mojo::URL->new->parse('foo:/test/123?foo=bar#baz'); - is $url->scheme, 'foo', 'right scheme'; - is $url->protocol, 'foo', 'right protocol'; - is $url->path, '/test/123', 'right path'; - is $url->query, 'foo=bar', 'right query'; - is $url->fragment, 'baz', 'right fragment'; - is "$url", 'foo:/test/123?foo=bar#baz', 'right format'; + is $url->scheme, 'foo', 'right scheme'; + is $url->protocol, 'foo', 'right protocol'; + is $url->path, '/test/123', 'right path'; + is $url->query, 'foo=bar', 'right query'; + is $url->fragment, 'baz', 'right fragment'; + is "$url", 'foo:/test/123?foo=bar#baz', 'right format'; is $url->scheme('Bar')->to_string, 'bar:/test/123?foo=bar#baz', 'right format'; - is $url->scheme, 'Bar', 'right scheme'; - is $url->protocol, 'bar', 'right protocol'; - is $url->host, undef, 'no host'; - is $url->path, '/test/123', 'right path'; - is $url->query, 'foo=bar', 'right query'; - is $url->fragment, 'baz', 'right fragment'; - is "$url", 'bar:/test/123?foo=bar#baz', 'right format'; + is $url->scheme, 'Bar', 'right scheme'; + is $url->protocol, 'bar', 'right protocol'; + is $url->host, undef, 'no host'; + is $url->path, '/test/123', 'right path'; + is $url->query, 'foo=bar', 'right query'; + is $url->fragment, 'baz', 'right fragment'; + is "$url", 'bar:/test/123?foo=bar#baz', 'right format'; $url = Mojo::URL->new->parse('file:///foo/bar'); - is $url->scheme, 'file', 'right scheme'; - is $url->protocol, 'file', 'right protocol'; - is $url->path, '/foo/bar', 'right path'; - is "$url", 'file:///foo/bar', 'right format'; + is $url->scheme, 'file', 'right scheme'; + is $url->protocol, 'file', 'right protocol'; + is $url->path, '/foo/bar', 'right path'; + is "$url", 'file:///foo/bar', 'right format'; $url = $url->clone; - is $url->scheme, 'file', 'right scheme'; - is $url->protocol, 'file', 'right protocol'; - is $url->path, '/foo/bar', 'right path'; - is "$url", 'file:///foo/bar', 'right format'; + is $url->scheme, 'file', 'right scheme'; + is $url->protocol, 'file', 'right protocol'; + is $url->path, '/foo/bar', 'right path'; + is "$url", 'file:///foo/bar', 'right format'; $url = Mojo::URL->new->parse('foo:0'); - is $url->scheme, 'foo', 'right scheme'; - is $url->protocol, 'foo', 'right protocol'; - is $url->path, '0', 'right path'; - is "$url", 'foo:0', 'right format'; + is $url->scheme, 'foo', 'right scheme'; + is $url->protocol, 'foo', 'right protocol'; + is $url->path, '0', 'right path'; + is "$url", 'foo:0', 'right format'; }; subtest 'Relative' => sub { @@ -184,25 +184,25 @@ subtest 'Relative' => sub { subtest 'Relative without scheme' => sub { my $url = Mojo::URL->new('//localhost/23/'); ok !$url->is_abs, 'is not absolute'; - is $url->scheme, undef, 'no scheme'; - is $url->protocol, '', 'no protocol'; - is $url->host, 'localhost', 'right host'; - is $url->path, '/23/', 'right path'; - is "$url", '//localhost/23/', 'right relative version'; + is $url->scheme, undef, 'no scheme'; + is $url->protocol, '', 'no protocol'; + is $url->host, 'localhost', 'right host'; + is $url->path, '/23/', 'right path'; + is "$url", '//localhost/23/', 'right relative version'; is $url->to_abs(Mojo::URL->new('http://')), 'http://localhost/23/', 'right absolute version'; is $url->to_abs(Mojo::URL->new('https://')), 'https://localhost/23/', 'right absolute version'; is $url->to_abs(Mojo::URL->new('http://mojolicious.org')), 'http://localhost/23/', 'right absolute version'; is $url->to_abs(Mojo::URL->new('http://mojolicious.org:8080')), 'http://localhost/23/', 'right absolute version'; $url = Mojo::URL->new('///bar/23/'); ok !$url->is_abs, 'is not absolute'; - is $url->host, '', 'no host'; - is $url->path, '/bar/23/', 'right path'; - is "$url", '///bar/23/', 'right relative version'; + is $url->host, '', 'no host'; + is $url->path, '/bar/23/', 'right path'; + is "$url", '///bar/23/', 'right relative version'; $url = Mojo::URL->new('////bar//23/'); ok !$url->is_abs, 'is not absolute'; - is $url->host, '', 'no host'; - is $url->path, '//bar//23/', 'right path'; - is "$url", '////bar//23/', 'right relative version'; + is $url->host, '', 'no host'; + is $url->path, '//bar//23/', 'right path'; + is "$url", '////bar//23/', 'right relative version'; }; subtest 'Relative path' => sub { @@ -244,8 +244,8 @@ subtest 'Absolute with path' => sub { my $url = Mojo::URL->new('../foo?foo=bar#23'); $url->base->parse('http://example.com/bar/baz/'); ok !$url->is_abs, 'not absolute'; - is $url->to_abs, 'http://example.com/bar/foo?foo=bar#23', 'right absolute version'; - is $url->to_abs->base, 'http://example.com/bar/baz/', 'right base'; + is $url->to_abs, 'http://example.com/bar/foo?foo=bar#23', 'right absolute version'; + is $url->to_abs->base, 'http://example.com/bar/baz/', 'right base'; }; subtest 'Absolute with query' => sub { @@ -257,15 +257,15 @@ subtest 'Absolute with query' => sub { subtest 'Clone (advanced)' => sub { my $url = Mojo::URL->new('ws://sri:foobar@example.com:8080/test/index.html?monkey=biz&foo=1#23'); my $clone = $url->clone; - ok $clone->is_abs, 'is absolute'; - is $clone->scheme, 'ws', 'right scheme'; - is $clone->userinfo, 'sri:foobar', 'right userinfo'; - is $clone->host, 'example.com', 'right host'; - is $clone->port, '8080', 'right port'; - is $clone->path, '/test/index.html', 'right path'; - is $clone->query, 'monkey=biz&foo=1', 'right query'; - is $clone->fragment, '23', 'right fragment'; - is "$clone", 'ws://example.com:8080/test/index.html?monkey=biz&foo=1#23', 'right format'; + ok $clone->is_abs, 'is absolute'; + is $clone->scheme, 'ws', 'right scheme'; + is $clone->userinfo, 'sri:foobar', 'right userinfo'; + is $clone->host, 'example.com', 'right host'; + is $clone->port, '8080', 'right port'; + is $clone->path, '/test/index.html', 'right path'; + is $clone->query, 'monkey=biz&foo=1', 'right query'; + is $clone->fragment, '23', 'right fragment'; + is "$clone", 'ws://example.com:8080/test/index.html?monkey=biz&foo=1#23', 'right format'; $clone->path('/index.xml'); is "$clone", 'ws://example.com:8080/index.xml?monkey=biz&foo=1#23', 'right format'; }; @@ -277,11 +277,11 @@ subtest 'Clone (with base)' => sub { my $clone = $url->clone; is "$url", '/test/index.html', 'right format'; ok !$clone->is_abs, 'not absolute'; - is $clone->scheme, undef, 'no scheme'; - is $clone->host, undef, 'no host'; - is $clone->base->scheme, 'http', 'right base scheme'; - is $clone->base->host, '127.0.0.1', 'right base host'; - is $clone->path, '/test/index.html', 'right path'; + is $clone->scheme, undef, 'no scheme'; + is $clone->host, undef, 'no host'; + is $clone->base->scheme, 'http', 'right base scheme'; + is $clone->base->host, '127.0.0.1', 'right base host'; + is $clone->path, '/test/index.html', 'right path'; is $clone->to_abs->to_string, 'http://127.0.0.1/test/index.html', 'right absolute version'; }; @@ -292,101 +292,101 @@ subtest 'Clone (with base path)' => sub { my $clone = $url->clone; is "$url", 'test/index.html', 'right format'; ok !$clone->is_abs, 'not absolute'; - is $clone->scheme, undef, 'no scheme'; - is $clone->host, undef, 'no host'; - is $clone->base->scheme, 'http', 'right base scheme'; - is $clone->base->host, '127.0.0.1', 'right base host'; - is $clone->path, 'test/index.html', 'right path'; + is $clone->scheme, undef, 'no scheme'; + is $clone->host, undef, 'no host'; + is $clone->base->scheme, 'http', 'right base scheme'; + is $clone->base->host, '127.0.0.1', 'right base host'; + is $clone->path, 'test/index.html', 'right path'; is $clone->to_abs->to_string, 'http://127.0.0.1/foo/test/index.html', 'right absolute version'; }; subtest 'IPv6' => sub { my $url = Mojo::URL->new('wss://[::1]:3000/'); ok $url->is_abs, 'is absolute'; - is $url->scheme, 'wss', 'right scheme'; - is $url->host, '[::1]', 'right host'; - is $url->port, 3000, 'right port'; - is $url->path, '/', 'right path'; - is "$url", 'wss://[::1]:3000/', 'right format'; + is $url->scheme, 'wss', 'right scheme'; + is $url->host, '[::1]', 'right host'; + is $url->port, 3000, 'right port'; + is $url->path, '/', 'right path'; + is "$url", 'wss://[::1]:3000/', 'right format'; }; subtest 'Escaped host' => sub { my $url = Mojo::URL->new('http+unix://%2FUsers%2Fsri%2Ftest.sock/index.html'); - ok $url->is_abs, 'is absolute'; - is $url->scheme, 'http+unix', 'right scheme'; - is $url->host, '/Users/sri/test.sock', 'right host'; - is $url->port, undef, 'no port'; - is $url->host_port, '/Users/sri/test.sock', 'right host and port'; - is $url->path, '/index.html', 'right path'; - is "$url", 'http+unix://%2FUsers%2Fsri%2Ftest.sock/index.html', 'right format'; + ok $url->is_abs, 'is absolute'; + is $url->scheme, 'http+unix', 'right scheme'; + is $url->host, '/Users/sri/test.sock', 'right host'; + is $url->port, undef, 'no port'; + is $url->host_port, '/Users/sri/test.sock', 'right host and port'; + is $url->path, '/index.html', 'right path'; + is "$url", 'http+unix://%2FUsers%2Fsri%2Ftest.sock/index.html', 'right format'; }; subtest 'IDNA' => sub { my $url = Mojo::URL->new('http://bücher.ch:3000/foo'); - ok $url->is_abs, 'is absolute'; - is $url->scheme, 'http', 'right scheme'; - is $url->host, 'bücher.ch', 'right host'; - is $url->ihost, 'xn--bcher-kva.ch', 'right internationalized host'; - is $url->port, 3000, 'right port'; - is $url->host_port, 'xn--bcher-kva.ch:3000', 'right host and port'; - is $url->path, '/foo', 'right path'; - is $url->path_query, '/foo', 'right path and query'; - is "$url", 'http://xn--bcher-kva.ch:3000/foo', 'right format'; + ok $url->is_abs, 'is absolute'; + is $url->scheme, 'http', 'right scheme'; + is $url->host, 'bücher.ch', 'right host'; + is $url->ihost, 'xn--bcher-kva.ch', 'right internationalized host'; + is $url->port, 3000, 'right port'; + is $url->host_port, 'xn--bcher-kva.ch:3000', 'right host and port'; + is $url->path, '/foo', 'right path'; + is $url->path_query, '/foo', 'right path and query'; + is "$url", 'http://xn--bcher-kva.ch:3000/foo', 'right format'; $url = Mojo::URL->new('http://bücher.bücher.ch:3000/foo'); ok $url->is_abs, 'is absolute'; - is $url->scheme, 'http', 'right scheme'; - is $url->host, 'bücher.bücher.ch', 'right host'; - is $url->ihost, 'xn--bcher-kva.xn--bcher-kva.ch', 'right internationalized host'; - is $url->port, 3000, 'right port'; - is $url->path, '/foo', 'right path'; - is "$url", 'http://xn--bcher-kva.xn--bcher-kva.ch:3000/foo', 'right format'; + is $url->scheme, 'http', 'right scheme'; + is $url->host, 'bücher.bücher.ch', 'right host'; + is $url->ihost, 'xn--bcher-kva.xn--bcher-kva.ch', 'right internationalized host'; + is $url->port, 3000, 'right port'; + is $url->path, '/foo', 'right path'; + is "$url", 'http://xn--bcher-kva.xn--bcher-kva.ch:3000/foo', 'right format'; $url = Mojo::URL->new('http://bücher.bücher.bücher.ch:3000/foo'); ok $url->is_abs, 'is absolute'; - is $url->scheme, 'http', 'right scheme'; - is $url->host, 'bücher.bücher.bücher.ch', 'right host'; - is $url->ihost, 'xn--bcher-kva.xn--bcher-kva.xn--bcher-kva.ch', 'right internationalized host'; - is $url->port, 3000, 'right port'; - is $url->path, '/foo', 'right path'; - is "$url", 'http://xn--bcher-kva.xn--bcher-kva.xn--bcher-kva.ch:3000/foo', 'right format'; + is $url->scheme, 'http', 'right scheme'; + is $url->host, 'bücher.bücher.bücher.ch', 'right host'; + is $url->ihost, 'xn--bcher-kva.xn--bcher-kva.xn--bcher-kva.ch', 'right internationalized host'; + is $url->port, 3000, 'right port'; + is $url->path, '/foo', 'right path'; + is "$url", 'http://xn--bcher-kva.xn--bcher-kva.xn--bcher-kva.ch:3000/foo', 'right format'; $url = Mojo::URL->new->scheme('http')->ihost('xn--n3h.xn--n3h.net'); - is $url->scheme, 'http', 'right scheme'; - is $url->host, '☃.☃.net', 'right host'; - is $url->ihost, 'xn--n3h.xn--n3h.net', 'right internationalized host'; - is "$url", 'http://xn--n3h.xn--n3h.net', 'right format'; + is $url->scheme, 'http', 'right scheme'; + is $url->host, '☃.☃.net', 'right host'; + is $url->ihost, 'xn--n3h.xn--n3h.net', 'right internationalized host'; + is "$url", 'http://xn--n3h.xn--n3h.net', 'right format'; }; subtest 'IDNA (escaped userinfo and host)' => sub { my $url = Mojo::URL->new('https://%E2%99%A5:%E2%99%A5@kr%E4ih.com:3000'); - is $url->userinfo, '♥:♥', 'right userinfo'; - is $url->username, '♥', 'right username'; - is $url->password, '♥', 'right password'; - is $url->host, "kr\xe4ih.com", 'right host'; - is $url->ihost, 'xn--krih-moa.com', 'right internationalized host'; - is $url->port, 3000, 'right port'; - is "$url", 'https://xn--krih-moa.com:3000', 'right format'; + is $url->userinfo, '♥:♥', 'right userinfo'; + is $url->username, '♥', 'right username'; + is $url->password, '♥', 'right password'; + is $url->host, "kr\xe4ih.com", 'right host'; + is $url->ihost, 'xn--krih-moa.com', 'right internationalized host'; + is $url->port, 3000, 'right port'; + is "$url", 'https://xn--krih-moa.com:3000', 'right format'; }; subtest 'IDNA (snowman)' => sub { my $url = Mojo::URL->new('http://☃:☃@☃.☃.de/☃?☃#☃'); - ok $url->is_abs, 'is absolute'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, '☃:☃', 'right userinfo'; - is $url->host, '☃.☃.de', 'right host'; - is $url->ihost, 'xn--n3h.xn--n3h.de', 'right internationalized host'; - is $url->path, '/%E2%98%83', 'right path'; - is $url->query, '%E2%98%83', 'right query'; - is $url->fragment, '☃', 'right fragment'; - is "$url", 'http://xn--n3h.xn--n3h.de/%E2%98%83?%E2%98%83#%E2%98%83', 'right format'; + ok $url->is_abs, 'is absolute'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, '☃:☃', 'right userinfo'; + is $url->host, '☃.☃.de', 'right host'; + is $url->ihost, 'xn--n3h.xn--n3h.de', 'right internationalized host'; + is $url->path, '/%E2%98%83', 'right path'; + is $url->query, '%E2%98%83', 'right query'; + is $url->fragment, '☃', 'right fragment'; + is "$url", 'http://xn--n3h.xn--n3h.de/%E2%98%83?%E2%98%83#%E2%98%83', 'right format'; is $url->to_unsafe_string, 'http://%E2%98%83:%E2%98%83@xn--n3h.xn--n3h.de/%E2%98%83?%E2%98%83#%E2%98%83', 'right format'; }; subtest 'IRI/IDNA' => sub { my $url = Mojo::URL->new('http://☃.net/♥/?q=♥☃'); - is $url->path->parts->[0], '♥', 'right path part'; - is $url->path, '/%E2%99%A5/', 'right path'; - is $url->query, 'q=%E2%99%A5%E2%98%83', 'right query'; - is $url->query->param('q'), '♥☃', 'right query value'; + is $url->path->parts->[0], '♥', 'right path part'; + is $url->path, '/%E2%99%A5/', 'right path'; + is $url->query, 'q=%E2%99%A5%E2%98%83', 'right query'; + is $url->query->param('q'), '♥☃', 'right query value'; $url = Mojo::URL->new('http://☃.Net/♥/♥/?♥=☃'); ok $url->is_abs, 'is absolute'; is $url->scheme, 'http', 'right scheme'; @@ -394,8 +394,8 @@ subtest 'IRI/IDNA' => sub { is $url->ihost, 'xn--n3h.Net', 'right internationalized host'; is $url->path, '/%E2%99%A5/%E2%99%A5/', 'right path'; is_deeply $url->path->parts, ['♥', '♥'], 'right structure'; - is $url->query->param('♥'), '☃', 'right query value'; - is "$url", 'http://xn--n3h.Net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83', 'right format'; + is $url->query->param('♥'), '☃', 'right query value'; + is "$url", 'http://xn--n3h.Net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83', 'right format'; $url = Mojo::URL->new('http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83'); ok $url->is_abs, 'is absolute'; is $url->scheme, 'http', 'right scheme'; @@ -403,8 +403,8 @@ subtest 'IRI/IDNA' => sub { is $url->ihost, 'xn--n3h.net', 'right internationalized host'; is $url->path, '/%E2%99%A5/%E2%99%A5/', 'right path'; is_deeply $url->path->parts, ['♥', '♥'], 'right structure'; - is $url->query->param('♥'), '☃', 'right query value'; - is "$url", 'http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83', 'right format'; + is $url->query->param('♥'), '☃', 'right query value'; + is "$url", 'http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83', 'right format'; }; subtest 'Already absolute' => sub { @@ -414,42 +414,42 @@ subtest 'Already absolute' => sub { subtest '"0"' => sub { my $url = Mojo::URL->new('http://0@foo.com#0'); - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, '0', 'right userinfo'; - is $url->username, '0', 'right username'; - is $url->password, undef, 'no password'; - is $url->host, 'foo.com', 'right host'; - is $url->fragment, '0', 'right fragment'; - is "$url", 'http://foo.com#0', 'right format'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, '0', 'right userinfo'; + is $url->username, '0', 'right username'; + is $url->password, undef, 'no password'; + is $url->host, 'foo.com', 'right host'; + is $url->fragment, '0', 'right fragment'; + is "$url", 'http://foo.com#0', 'right format'; is $url->to_unsafe_string, 'http://0@foo.com#0', 'right format'; }; subtest 'Empty path elements' => sub { my $url = Mojo::URL->new('http://example.com/foo//bar/23/'); ok $url->is_abs, 'is absolute'; - is $url->path, '/foo//bar/23/', 'right path'; - is "$url", 'http://example.com/foo//bar/23/', 'right format'; + is $url->path, '/foo//bar/23/', 'right path'; + is "$url", 'http://example.com/foo//bar/23/', 'right format'; $url = Mojo::URL->new('http://example.com//foo//bar/23/'); ok $url->is_abs, 'is absolute'; - is $url->path, '//foo//bar/23/', 'right path'; - is "$url", 'http://example.com//foo//bar/23/', 'right format'; + is $url->path, '//foo//bar/23/', 'right path'; + is "$url", 'http://example.com//foo//bar/23/', 'right format'; $url = Mojo::URL->new('http://example.com/foo///bar/23/'); ok $url->is_abs, 'is absolute'; - is $url->path, '/foo///bar/23/', 'right path'; - is "$url", 'http://example.com/foo///bar/23/', 'right format'; + is $url->path, '/foo///bar/23/', 'right path'; + is "$url", 'http://example.com/foo///bar/23/', 'right format'; }; subtest 'Merge relative path' => sub { my $url = Mojo::URL->new('http://foo.bar/baz?yada'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/baz?yada', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, undef, 'no fragment'; + is "$url", 'http://foo.bar/baz?yada', 'right absolute URL'; $url = Mojo::URL->new('zzz?Zzz')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz?yada', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -459,20 +459,20 @@ subtest 'Merge relative path' => sub { is $url->path, '/zzz', 'right path'; is $url->query, 'Zzz', 'right query'; is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/zzz?Zzz', 'right absolute URL'; + is "$url", 'http://foo.bar/zzz?Zzz', 'right absolute URL'; }; subtest 'Merge relative path with directory' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, undef, 'no fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada', 'right absolute URL'; $url = Mojo::URL->new('zzz?Zzz')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -482,20 +482,20 @@ subtest 'Merge relative path with directory' => sub { is $url->path, '/baz/zzz', 'right path'; is $url->query, 'Zzz', 'right query'; is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/baz/zzz?Zzz', 'right absolute URL'; + is "$url", 'http://foo.bar/baz/zzz?Zzz', 'right absolute URL'; }; subtest 'Merge absolute path' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, undef, 'no fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada', 'right absolute URL'; $url = Mojo::URL->new('/zzz?Zzz')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -505,20 +505,20 @@ subtest 'Merge absolute path' => sub { is $url->path, '/zzz', 'right path'; is $url->query, 'Zzz', 'right query'; is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/zzz?Zzz', 'right absolute URL'; + is "$url", 'http://foo.bar/zzz?Zzz', 'right absolute URL'; }; subtest 'Merge absolute path without query' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, undef, 'no fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada', 'right absolute URL'; $url = Mojo::URL->new('/zzz')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -528,20 +528,20 @@ subtest 'Merge absolute path without query' => sub { is $url->path, '/zzz', 'right path'; is $url->query, '', 'no query'; is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/zzz', 'right absolute URL'; + is "$url", 'http://foo.bar/zzz', 'right absolute URL'; }; subtest 'Merge absolute path with fragment' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada#test1'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, 'test1', 'right fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, 'test1', 'right fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; $url = Mojo::URL->new('/zzz#test2')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada#test1', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -551,20 +551,20 @@ subtest 'Merge absolute path with fragment' => sub { is $url->path, '/zzz', 'right path'; is $url->query, '', 'no query'; is $url->fragment, 'test2', 'right fragment'; - is "$url", 'http://foo.bar/zzz#test2', 'right absolute URL'; + is "$url", 'http://foo.bar/zzz#test2', 'right absolute URL'; }; subtest 'Merge relative path with fragment' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada#test1'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, 'test1', 'right fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, 'test1', 'right fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; $url = Mojo::URL->new('zzz#test2')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada#test1', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -574,20 +574,20 @@ subtest 'Merge relative path with fragment' => sub { is $url->path, '/baz/zzz', 'right path'; is $url->query, '', 'no query'; is $url->fragment, 'test2', 'right fragment'; - is "$url", 'http://foo.bar/baz/zzz#test2', 'right absolute URL'; + is "$url", 'http://foo.bar/baz/zzz#test2', 'right absolute URL'; }; subtest 'Merge absolute path without fragment' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada#test1'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, 'test1', 'right fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, 'test1', 'right fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; $url = Mojo::URL->new('/zzz')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada#test1', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -597,20 +597,20 @@ subtest 'Merge absolute path without fragment' => sub { is $url->path, '/zzz', 'right path'; is $url->query, '', 'no query'; is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/zzz', 'right absolute URL'; + is "$url", 'http://foo.bar/zzz', 'right absolute URL'; }; subtest 'Merge relative path without fragment' => sub { my $url = Mojo::URL->new('http://foo.bar/baz/index.html?yada#test1'); - is $url->base, '', 'no base'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'foo.bar', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/baz/index.html', 'right path'; - is $url->query, 'yada', 'right query'; - is $url->fragment, 'test1', 'right fragment'; - is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; + is $url->base, '', 'no base'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'foo.bar', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/baz/index.html', 'right path'; + is $url->query, 'yada', 'right query'; + is $url->fragment, 'test1', 'right fragment'; + is "$url", 'http://foo.bar/baz/index.html?yada#test1', 'right absolute URL'; $url = Mojo::URL->new('zzz')->base($url)->to_abs; is $url->base, 'http://foo.bar/baz/index.html?yada#test1', 'right base'; is $url->scheme, 'http', 'right scheme'; @@ -620,7 +620,7 @@ subtest 'Merge relative path without fragment' => sub { is $url->path, '/baz/zzz', 'right path'; is $url->query, '', 'no query'; is $url->fragment, undef, 'no fragment'; - is "$url", 'http://foo.bar/baz/zzz', 'right absolute URL'; + is "$url", 'http://foo.bar/baz/zzz', 'right absolute URL'; }; subtest 'Hosts' => sub { @@ -652,39 +652,39 @@ subtest 'Hosts' => sub { subtest 'Heavily escaped path and empty fragment' => sub { my $url = Mojo::URL->new('http://example.com/mojo%2Fg%2B%2B-4%2E2_4%2E2%2E3-2ubuntu7_i386%2Edeb#'); - ok $url->is_abs, 'is absolute'; - is $url->scheme, 'http', 'right scheme'; - is $url->userinfo, undef, 'no userinfo'; - is $url->host, 'example.com', 'right host'; - is $url->port, undef, 'no port'; - is $url->path, '/mojo%2Fg%2B%2B-4%2E2_4%2E2%2E3-2ubuntu7_i386%2Edeb', 'right path'; - is $url->query, '', 'no query'; - is $url->fragment, '', 'right fragment'; - is "$url", 'http://example.com/mojo%2Fg%2B%2B-4%2E2_4%2E2%2E3-2ubuntu7_i386%2Edeb#', 'right format'; + ok $url->is_abs, 'is absolute'; + is $url->scheme, 'http', 'right scheme'; + is $url->userinfo, undef, 'no userinfo'; + is $url->host, 'example.com', 'right host'; + is $url->port, undef, 'no port'; + is $url->path, '/mojo%2Fg%2B%2B-4%2E2_4%2E2%2E3-2ubuntu7_i386%2Edeb', 'right path'; + is $url->query, '', 'no query'; + is $url->fragment, '', 'right fragment'; + is "$url", 'http://example.com/mojo%2Fg%2B%2B-4%2E2_4%2E2%2E3-2ubuntu7_i386%2Edeb#', 'right format'; $url->path->canonicalize; is "$url", 'http://example.com/mojo/g++-4.2_4.2.3-2ubuntu7_i386.deb#', 'right format'; }; subtest '"%" in path' => sub { my $url = Mojo::URL->new('http://mojolicious.org/100%_fun'); - is $url->path->parts->[0], '100%_fun', 'right part'; - is $url->path, '/100%25_fun', 'right path'; - is "$url", 'http://mojolicious.org/100%25_fun', 'right format'; + is $url->path->parts->[0], '100%_fun', 'right part'; + is $url->path, '/100%25_fun', 'right path'; + is "$url", 'http://mojolicious.org/100%25_fun', 'right format'; $url = Mojo::URL->new('http://mojolicious.org/100%fun'); - is $url->path->parts->[0], '100%fun', 'right part'; - is $url->path, '/100%25fun', 'right path'; - is "$url", 'http://mojolicious.org/100%25fun', 'right format'; + is $url->path->parts->[0], '100%fun', 'right part'; + is $url->path, '/100%25fun', 'right path'; + is "$url", 'http://mojolicious.org/100%25fun', 'right format'; $url = Mojo::URL->new('http://mojolicious.org/100%25_fun'); - is $url->path->parts->[0], '100%_fun', 'right part'; - is $url->path, '/100%25_fun', 'right path'; - is "$url", 'http://mojolicious.org/100%25_fun', 'right format'; + is $url->path->parts->[0], '100%_fun', 'right part'; + is $url->path, '/100%25_fun', 'right path'; + is "$url", 'http://mojolicious.org/100%25_fun', 'right format'; }; subtest 'Trailing dot' => sub { my $url = Mojo::URL->new('http://☃.net./♥'); - is $url->ihost, 'xn--n3h.net.', 'right internationalized host'; - is $url->host, '☃.net.', 'right host'; - is "$url", 'http://xn--n3h.net./%E2%99%A5', 'right format'; + is $url->ihost, 'xn--n3h.net.', 'right internationalized host'; + is $url->host, '☃.net.', 'right host'; + is "$url", 'http://xn--n3h.net./%E2%99%A5', 'right format'; }; subtest 'No charset' => sub { @@ -697,12 +697,12 @@ subtest 'No charset' => sub { is $url->host, 'FOO.BAR', 'right host'; is $url->ihost, 'FOO.BAR', 'right internationalized host'; is $url->path, '/%E4/', 'right path'; - is_deeply $url->path->parts, ["\xe4"], 'right structure'; + is_deeply $url->path->parts, ["\xe4"], 'right structure'; ok $url->path->leading_slash, 'has leading slash'; ok $url->path->trailing_slash, 'has trailing slash'; - is $url->query, '%E5=%E4', 'right query'; - is $url->query->param("\xe5"), "\xe4", 'right value'; - is "$url", 'http://FOO.BAR/%E4/?%E5=%E4', 'right format'; + is $url->query, '%E5=%E4', 'right query'; + is $url->query->param("\xe5"), "\xe4", 'right value'; + is "$url", 'http://FOO.BAR/%E4/?%E5=%E4', 'right format'; }; subtest 'Resolve RFC 1808 examples' => sub { diff --git a/t/mojo/user_agent.t b/t/mojo/user_agent.t index e9945bb889..ec65737d53 100644 --- a/t/mojo/user_agent.t +++ b/t/mojo/user_agent.t @@ -138,8 +138,8 @@ $ua->get( is $ua->get('/')->res->code, 200, 'right status'; Mojo::IOLoop->start; ok $success, 'successful'; -is $code, 200, 'right status'; -is $body, 'works!', 'right content'; +is $code, 200, 'right status'; +is $body, 'works!', 'right content'; # Promises my @results; @@ -221,7 +221,7 @@ is $tx->res->body, 'works!', 'right content'; # Again $tx = $ua->get('/'); -ok !$tx->error, 'no error'; +ok !$tx->error, 'no error'; ok $tx->kept_alive, 'kept connection alive'; is $tx->res->version, '1.1', 'right version'; is $tx->res->code, 200, 'right status'; @@ -254,18 +254,18 @@ is $ua->put('/method')->res->body, 'PUT', 'right method'; $tx = $ua->get('/one?connection=test'); ok !$tx->error, 'no error'; ok !$tx->keep_alive, 'connection will not be kept alive'; -is $tx->res->version, '1.0', 'right version'; -is $tx->res->code, 200, 'right status'; +is $tx->res->version, '1.0', 'right version'; +is $tx->res->code, 200, 'right status'; is $tx->res->headers->connection, 'test', 'right "Connection" value'; -is $tx->res->body, 'One!', 'right content'; +is $tx->res->body, 'One!', 'right content'; $tx = $ua->get('/one?connection=test'); ok !$tx->error, 'no error'; ok !$tx->kept_alive, 'kept connection not alive'; ok !$tx->keep_alive, 'connection will not be kept alive'; -is $tx->res->version, '1.0', 'right version'; -is $tx->res->code, 200, 'right status'; +is $tx->res->version, '1.0', 'right version'; +is $tx->res->code, 200, 'right status'; is $tx->res->headers->connection, 'test', 'right "Connection" value'; -is $tx->res->body, 'One!', 'right content'; +is $tx->res->body, 'One!', 'right content'; $tx = $ua->get('/one'); ok !$tx->error, 'no error'; ok !$tx->kept_alive, 'kept connection not alive'; @@ -307,10 +307,10 @@ is $finished_req, 1, 'finish event has been emitted once'; is $finished_tx, 1, 'finish event has been emitted once'; is $finished_res, 1, 'finish event has been emitted once'; ok $tx->req->is_finished, 'request is finished'; -ok $tx->is_finished, 'transaction is finished'; +ok $tx->is_finished, 'transaction is finished'; ok $tx->res->is_finished, 'response is finished'; -is $tx->res->code, 200, 'right status'; -is $tx->res->body, 'works!', 'right content'; +is $tx->res->code, 200, 'right status'; +is $tx->res->body, 'works!', 'right content'; # Missing Content-Length header ($finished_req, $finished_tx, $finished_res) = (); @@ -330,11 +330,11 @@ is $finished_req, 1, 'finish event has been emitted once'; is $finished_tx, 1, 'finish event has been emitted once'; is $finished_res, 1, 'finish event has been emitted once'; ok $tx->req->is_finished, 'request is finished'; -ok $tx->is_finished, 'transaction is finished'; +ok $tx->is_finished, 'transaction is finished'; ok $tx->res->is_finished, 'response is finished'; -ok !$tx->error, 'no error'; -ok $tx->kept_alive, 'kept connection alive'; -ok !$tx->keep_alive, 'keep connection not alive'; +ok !$tx->error, 'no error'; +ok $tx->kept_alive, 'kept connection alive'; +ok !$tx->keep_alive, 'keep connection not alive'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'works too!', 'right content'; @@ -342,23 +342,23 @@ is $tx->res->body, 'works too!', 'right content'; $tx = $ua->get('/no_content'); ok !$tx->error, 'no error'; ok !$tx->kept_alive, 'kept connection not alive'; -ok $tx->keep_alive, 'keep connection alive'; +ok $tx->keep_alive, 'keep connection alive'; is $tx->res->code, 204, 'right status'; ok $tx->is_empty, 'transaction is empty'; is $tx->res->body, '', 'no content'; # Connection was kept alive $tx = $ua->head('/huge'); -ok !$tx->error, 'no error'; +ok !$tx->error, 'no error'; ok $tx->kept_alive, 'kept connection alive'; -is $tx->res->code, 200, 'right status'; +is $tx->res->code, 200, 'right status'; is $tx->res->headers->content_length, 262144, 'right "Content-Length" value'; ok $tx->is_empty, 'transaction is empty'; is $tx->res->body, '', 'no content'; $tx = $ua->get('/huge'); -ok !$tx->error, 'no error'; +ok !$tx->error, 'no error'; ok $tx->kept_alive, 'kept connection alive'; -is $tx->res->code, 200, 'right status'; +is $tx->res->code, 200, 'right status'; is $tx->res->headers->content_length, 262144, 'right "Content-Length" value'; ok !$tx->is_empty, 'transaction is not empty'; is $tx->res->body, 'x' x 262144, 'right content'; @@ -376,8 +376,8 @@ $ua->post( ); Mojo::IOLoop->start; ok $success, 'successful'; -is $code, 200, 'right status'; -is $body, 'hello=world', 'right content'; +is $code, 200, 'right status'; +is $body, 'hello=world', 'right content'; # Non-blocking JSON ($success, $code, $body) = (); @@ -392,8 +392,8 @@ $ua->post( ); Mojo::IOLoop->start; ok $success, 'successful'; -is $code, 200, 'right status'; -is $body, '{"hello":"world"}', 'right content'; +is $code, 200, 'right status'; +is $body, '{"hello":"world"}', 'right content'; # Built-in web server times out $ua = Mojo::UserAgent->new(ioloop => Mojo::IOLoop->singleton); @@ -402,8 +402,8 @@ my $msg = app->log->on(message => sub { $log .= pop }); $tx = $ua->get('/timeout?timeout=0.25'); app->log->unsubscribe(message => $msg); is $tx->error->{message}, 'Premature connection close', 'right error'; -is $timeout, 1, 'finish event has been emitted'; -like $log, qr/Inactivity timeout/, 'right log message'; +is $timeout, 1, 'finish event has been emitted'; +like $log, qr/Inactivity timeout/, 'right log message'; eval { $tx->result }; like $@, qr/Premature connection close/, 'right error'; @@ -463,7 +463,7 @@ $tx = $ua->get('/does_not_exist'); ok $tx->result, 'has a result'; is $tx->result->code, 404, 'right status'; ok !$tx->kept_alive, 'kept connection not alive'; -ok $tx->keep_alive, 'keep connection alive'; +ok $tx->keep_alive, 'keep connection alive'; is $tx->error->{message}, 'Not Found', 'right error'; is $tx->error->{code}, 404, 'right status'; $tx = $ua->get('/does_not_exist'); @@ -486,17 +486,17 @@ $tx = $ua->build_tx(GET => '/echo' => 'Hello GZip!'); $tx = $ua->start($ua->build_tx(GET => '/echo' => 'Hello GZip!')); ok !$tx->error, 'no error'; ok $tx->result, 'has a result'; -is $tx->result->code, 200, 'right status'; -is $tx->res->code, 200, 'right status'; -is $tx->res->headers->content_encoding, undef, 'no "Content-Encoding" value'; -is $tx->res->body, 'Hello GZip!', 'right content'; +is $tx->result->code, 200, 'right status'; +is $tx->res->code, 200, 'right status'; +is $tx->res->headers->content_encoding, undef, 'no "Content-Encoding" value'; +is $tx->res->body, 'Hello GZip!', 'right content'; $tx = $ua->build_tx(GET => '/echo' => 'Hello GZip!'); $tx->res->content->auto_decompress(0); $tx = $ua->start($tx); ok !$tx->error, 'no error'; -is $tx->res->code, 200, 'right status'; -is $tx->res->headers->content_encoding, 'gzip', 'right "Content-Encoding" value'; -isnt $tx->res->body, 'Hello GZip!', 'different content'; +is $tx->res->code, 200, 'right status'; +is $tx->res->headers->content_encoding, 'gzip', 'right "Content-Encoding" value'; +isnt $tx->res->body, 'Hello GZip!', 'different content'; # Keep-alive timeout in between requests my $daemon = Mojo::Server::Daemon->new( @@ -514,7 +514,7 @@ is $tx->res->body, 'works!', 'right content'; Mojo::Promise->new->ioloop($ua->ioloop)->timer(1)->wait; $tx = $ua->get("http://127.0.0.1:$port"); ok !$tx->kept_alive, 'kept connection not alive'; -ok $tx->keep_alive, 'keep connection alive'; +ok $tx->keep_alive, 'keep connection alive'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'works!', 'right content'; @@ -525,29 +525,29 @@ subtest 'Fork-safety' => sub { my $last = $tx->connection; my $port = $ua->server->url->port; $tx = $ua->get('/'); - is $tx->res->body, 'works!', 'right content'; - is $tx->connection, $last, 'same connection'; - is $ua->server->url->port, $port, 'same port'; + is $tx->res->body, 'works!', 'right content'; + is $tx->connection, $last, 'same connection'; + is $ua->server->url->port, $port, 'same port'; { local $$ = -23; my $tx = $ua->get('/'); ok !$tx->kept_alive, 'kept connection not alive'; - ok $tx->keep_alive, 'keep connection alive'; - is $tx->res->body, 'works!', 'right content'; - isnt $tx->connection, $last, 'new connection'; - isnt $ua->server->url->port, $port, 'new port'; + ok $tx->keep_alive, 'keep connection alive'; + is $tx->res->body, 'works!', 'right content'; + isnt $tx->connection, $last, 'new connection'; + isnt $ua->server->url->port, $port, 'new port'; my $port2 = $ua->server->url->port; my $last2 = $tx->connection; { local $$ = -24; my $tx = $ua->get('/'); ok !$tx->kept_alive, 'kept connection not alive'; - ok $tx->keep_alive, 'keep connection alive'; - is $tx->res->body, 'works!', 'right content'; - isnt $tx->connection, $last, 'new connection'; - isnt $tx->connection, $last2, 'new connection'; - isnt $ua->server->url->port, $port, 'new port'; - isnt $ua->server->url->port, $port2, 'new port'; + ok $tx->keep_alive, 'keep connection alive'; + is $tx->res->body, 'works!', 'right content'; + isnt $tx->connection, $last, 'new connection'; + isnt $tx->connection, $last2, 'new connection'; + isnt $ua->server->url->port, $port, 'new port'; + isnt $ua->server->url->port, $port2, 'new port'; } } }; @@ -588,10 +588,10 @@ my $start = $ua->on( ); $tx = $ua->get('/', 'whatever'); ok !$tx->error, 'no error'; -is $tx->res->code, 200, 'right status'; -is $tx->res->body, 'works!', 'right content'; -is scalar @{Mojo::IOLoop->stream($tx->connection)->subscribers('write')}, 0, 'unsubscribed successfully'; -is scalar @{Mojo::IOLoop->stream($tx->connection)->subscribers('read')}, 1, 'unsubscribed successfully'; +is $tx->res->code, 200, 'right status'; +is $tx->res->body, 'works!', 'right content'; +is scalar @{Mojo::IOLoop->stream($tx->connection)->subscribers('write')}, 0, 'unsubscribed successfully'; +is scalar @{Mojo::IOLoop->stream($tx->connection)->subscribers('read')}, 1, 'unsubscribed successfully'; like $req, qr!^GET / .*whatever$!s, 'right request'; like $res, qr|^HTTP/.*200 OK.*works!$|s, 'right response'; is_deeply \@num, [0, 0, length $res, length $req], 'right structure'; @@ -618,12 +618,12 @@ $drain = sub { }; $tx->req->content->$drain; $ua->start($tx); -ok !$tx->error, 'no error'; +ok !$tx->error, 'no error'; ok $tx->kept_alive, 'kept connection alive'; ok $tx->keep_alive, 'keep connection alive'; is $tx->res->code, 200, 'right status'; is $tx->res->body, '0123456789', 'right content'; -is $stream, 1, 'no leaking subscribers'; +is $stream, 1, 'no leaking subscribers'; # Upload progress $ua = Mojo::UserAgent->new; @@ -651,7 +651,7 @@ $ua = Mojo::UserAgent->new(ioloop => Mojo::IOLoop->singleton); $tx = $ua->get($ua->server->url); ok !$tx->error, 'no error'; ok !$tx->kept_alive, 'kept connection not alive'; -ok $tx->keep_alive, 'keep connection alive'; +ok $tx->keep_alive, 'keep connection alive'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'works!', 'right content'; my @kept_alive; @@ -677,7 +677,7 @@ $ua->get( Mojo::IOLoop->start; is_deeply \@kept_alive, [undef, 1, 1], 'connections kept alive'; $tx = $ua->get($ua->server->url); -ok !$tx->error, 'no error'; +ok !$tx->error, 'no error'; ok $tx->kept_alive, 'kept connection alive'; ok $tx->keep_alive, 'keep connection alive'; is $tx->res->code, 200, 'right status'; @@ -724,9 +724,9 @@ $tx = $ua->build_tx(GET => "http://127.0.0.1:$port/"); my @unexpected; $tx->on(unexpected => sub { push @unexpected, pop }); $tx = $ua->start($tx); -is $unexpected[0]->code, 100, 'right status'; +is $unexpected[0]->code, 100, 'right status'; is $unexpected[0]->headers->header('X-Foo'), 'Bar', 'right "X-Foo" value'; -is $unexpected[1]->code, 101, 'right status'; +is $unexpected[1]->code, 101, 'right status'; ok !$tx->error, 'no error'; is $tx->res->code, 200, 'right status'; is $tx->res->body, 'Hi!', 'right content'; diff --git a/t/mojo/user_agent_online.t b/t/mojo/user_agent_online.t index 507eb978e9..106e2b2258 100644 --- a/t/mojo/user_agent_online.t +++ b/t/mojo/user_agent_online.t @@ -154,7 +154,7 @@ subtest 'One-liner' => sub { is g('http://mojolicious.org')->code, 200, 'right status'; my $res = p('https://metacpan.org/search' => form => {q => 'mojolicious'}); like $res->body, qr/Mojolicious/, 'right content'; - is $res->code, 200, 'right status'; + is $res->code, 200, 'right status'; }; subtest 'Simple request' => sub { @@ -170,7 +170,7 @@ subtest 'Simple keep-alive requests' => sub { is $tx->req->url, 'https://www.wikipedia.org', 'right url'; is $tx->req->body, '', 'no content'; is $tx->res->code, 200, 'right status'; - ok $tx->keep_alive, 'connection will be kept alive'; + ok $tx->keep_alive, 'connection will be kept alive'; ok !$tx->kept_alive, 'connection was not kept alive'; $tx = $ua->get('https://www.wikipedia.org'); is $tx->req->method, 'GET', 'right method'; @@ -197,38 +197,38 @@ $ua = Mojo::UserAgent->new; subtest 'Simple keep-alive form POST' => sub { my $tx = $ua->post('https://metacpan.org/search' => form => {q => 'mojolicious'}); - is $tx->req->method, 'POST', 'right method'; - is $tx->req->url, 'https://metacpan.org/search', 'right url'; - is $tx->req->headers->content_length, 13, 'right content length'; - is $tx->req->body, 'q=mojolicious', 'right content'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->url, 'https://metacpan.org/search', 'right url'; + is $tx->req->headers->content_length, 13, 'right content length'; + is $tx->req->body, 'q=mojolicious', 'right content'; like $tx->res->body, qr/Mojolicious/, 'right content'; - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; ok $tx->keep_alive, 'connection will be kept alive'; $tx = $ua->post('https://metacpan.org/search' => form => {q => 'mojolicious'}); - is $tx->req->method, 'POST', 'right method'; - is $tx->req->url, 'https://metacpan.org/search', 'right url'; - is $tx->req->headers->content_length, 13, 'right content length'; - is $tx->req->body, 'q=mojolicious', 'right content'; + is $tx->req->method, 'POST', 'right method'; + is $tx->req->url, 'https://metacpan.org/search', 'right url'; + is $tx->req->headers->content_length, 13, 'right content length'; + is $tx->req->body, 'q=mojolicious', 'right content'; like $tx->res->body, qr/Mojolicious/, 'right content'; - is $tx->res->code, 200, 'right status'; - ok $tx->kept_alive, 'connection was kept alive'; - ok $tx->local_address, 'has local address'; - ok $tx->local_port > 0, 'has local port'; + is $tx->res->code, 200, 'right status'; + ok $tx->kept_alive, 'connection was kept alive'; + ok $tx->local_address, 'has local address'; + ok $tx->local_port > 0, 'has local port'; ok $tx->original_remote_address, 'has original remote address'; ok $tx->remote_address, 'has remote address'; - ok $tx->remote_port > 0, 'has remote port'; + ok $tx->remote_port > 0, 'has remote port'; }; subtest 'Simple request with redirect' => sub { $ua->max_redirects(3); my $tx = $ua->get('http://wikipedia.org/wiki/Perl'); $ua->max_redirects(0); - is $tx->req->method, 'GET', 'right method'; - is $tx->req->url, 'https://en.wikipedia.org/wiki/Perl', 'right url'; - is $tx->res->code, 200, 'right status'; - is $tx->previous->req->method, 'GET', 'right method'; - is $tx->previous->req->url, 'https://www.wikipedia.org/wiki/Perl', 'right url'; - is $tx->previous->res->code, 301, 'right status'; + is $tx->req->method, 'GET', 'right method'; + is $tx->req->url, 'https://en.wikipedia.org/wiki/Perl', 'right url'; + is $tx->res->code, 200, 'right status'; + is $tx->previous->req->method, 'GET', 'right method'; + is $tx->previous->req->url, 'https://www.wikipedia.org/wiki/Perl', 'right url'; + is $tx->previous->res->code, 301, 'right status'; is $tx->redirects->[-1]->req->method, 'GET', 'right method'; is $tx->redirects->[-1]->req->url, 'https://www.wikipedia.org/wiki/Perl', 'right url'; is $tx->redirects->[-1]->res->code, 301, 'right status'; diff --git a/t/mojo/user_agent_socks.t b/t/mojo/user_agent_socks.t index 3b90c125f3..29e6339228 100644 --- a/t/mojo/user_agent_socks.t +++ b/t/mojo/user_agent_socks.t @@ -112,20 +112,20 @@ subtest 'Simple request with SOCKS proxy' => sub { my $tx = $ua->get('/'); ok !$tx->error, 'no error'; ok !$tx->kept_alive, 'kept connection not alive'; - ok $tx->keep_alive, 'keep connection alive'; - is $tx->res->code, 200, 'right status'; + ok $tx->keep_alive, 'keep connection alive'; + is $tx->res->code, 200, 'right status'; is $tx->req->headers->proxy_authorization, undef, 'no "Proxy-Authorization" value'; - is $tx->res->body, $last, 'right content'; + is $tx->res->body, $last, 'right content'; isnt(Mojo::IOLoop->stream($tx->connection)->handle->sockport, $last, 'different ports'); my $before = $last; $tx = $ua->get('/'); - ok !$tx->error, 'no error'; + ok !$tx->error, 'no error'; ok $tx->kept_alive, 'kept connection alive'; ok $tx->keep_alive, 'keep connection alive'; - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $last, 'right content'; - is $before, $last, 'same port'; + is $before, $last, 'same port'; isnt(Mojo::IOLoop->stream($tx->connection)->handle->sockport, $last, 'different ports'); }; @@ -153,7 +153,7 @@ subtest 'HTTPS request with SOCKS proxy' => sub { my $tx = $ua->get('/secure'); ok !$tx->error, 'no error'; ok !$tx->kept_alive, 'kept connection not alive'; - ok $tx->keep_alive, 'keep connection alive'; + ok $tx->keep_alive, 'keep connection alive'; is $tx->res->code, 200, 'right status'; is $tx->res->body, "https:$last", 'right content'; isnt(Mojo::IOLoop->stream($tx->connection)->handle->sockport, $last, 'different ports'); @@ -167,7 +167,7 @@ subtest 'Disabled SOCKS proxy' => sub { $tx->req->via_proxy(0); $tx = $ua->start($tx); ok !$tx->error, 'no error'; - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->body, $tx->local_port, 'right content'; }; diff --git a/t/mojo/util.t b/t/mojo/util.t index 2afbe72fc5..899600da38 100644 --- a/t/mojo/util.t +++ b/t/mojo/util.t @@ -52,16 +52,16 @@ subtest 'class_to_path' => sub { }; subtest 'split_header' => sub { - is_deeply split_header(''), [], 'right result'; + is_deeply split_header(''), [], 'right result'; is_deeply split_header('foo=b=a=r'), [['foo', 'b=a=r']], 'right result'; is_deeply split_header('a=b ,, , c=d ;; ; e=f g h=i'), [['a', 'b'], ['c', 'd', 'e', 'f', 'g', undef, 'h', 'i']], 'right result'; - is_deeply split_header(',,foo,, ,bar'), [['foo', undef], ['bar', undef]], 'right result'; - is_deeply split_header(';;foo; ; ;bar'), [['foo', undef, 'bar', undef]], 'right result'; - is_deeply split_header('foo=;bar=""'), [['foo', '', 'bar', '']], 'right result'; - is_deeply split_header('foo=bar baz=yada'), [['foo', 'bar', 'baz', 'yada']], 'right result'; + is_deeply split_header(',,foo,, ,bar'), [['foo', undef], ['bar', undef]], 'right result'; + is_deeply split_header(';;foo; ; ;bar'), [['foo', undef, 'bar', undef]], 'right result'; + is_deeply split_header('foo=;bar=""'), [['foo', '', 'bar', '']], 'right result'; + is_deeply split_header('foo=bar baz=yada'), [['foo', 'bar', 'baz', 'yada']], 'right result'; is_deeply split_header('foo,bar,baz'), [['foo', undef], ['bar', undef], ['baz', undef]], 'right result'; - is_deeply split_header('f "o" o , ba r'), [['f', undef, '"o"', undef, 'o', undef], ['ba', undef, 'r', undef]], + is_deeply split_header('f "o" o , ba r'), [['f', undef, '"o"', undef, 'o', undef], ['ba', undef, 'r', undef]], 'right result'; is_deeply split_header('foo="b,; a\" r\"\\\\"'), [['foo', 'b,; a" r"\\']], 'right result'; is_deeply split_header('foo = "b a\" r\"\\\\"; bar="ba z"'), [['foo', 'b a" r"\\', 'bar', 'ba z']], 'right result'; @@ -95,7 +95,7 @@ subtest 'split_cookie_header' => sub { }; subtest 'extract_usage' => sub { - is extract_usage, "extract_usage test!\n", 'right result'; + is extract_usage, "extract_usage test!\n", 'right result'; is extract_usage(curfile->sibling('lib', 'myapp.pl')), "USAGE: myapp.pl daemon\n\n test\n123\n", 'right result'; }; @@ -109,12 +109,12 @@ subtest 'getopt' => sub { getopt ['--charset', 'UTF-8'], 'c|charset=s' => \my $charset; is $charset, 'UTF-8', 'right string'; my $array = ['-t', 'test', '-h', '--whatever', 'Whatever!', 'stuff']; - getopt $array, ['pass_through'], 't|test=s' => \my $test; - is $test, 'test', 'right string'; + getopt $array, ['pass_through'], 't|test=s' => \my $test; + is $test, 'test', 'right string'; is_deeply $array, ['-h', '--whatever', 'Whatever!', 'stuff'], 'right structure'; - getopt $array, 'h' => \my $flag, 'w|whatever=s' => \my $whatever; - ok $flag, 'flag has been set'; - is $whatever, 'Whatever!', 'right string'; + getopt $array, 'h' => \my $flag, 'w|whatever=s' => \my $whatever; + ok $flag, 'flag has been set'; + is $whatever, 'Whatever!', 'right string'; is_deeply $array, ['stuff'], 'right structure'; { local @ARGV = ('--charset', 'UTF-16', 'test'); @@ -265,8 +265,8 @@ subtest 'xml_escape (nothing to escape)' => sub { }; subtest 'xml_escape (XSS)' => sub { - is xml_escape('

    '), '<p>', 'right XSS escaped result'; - is xml_escape(b('

    ')), '

    ', 'right XSS escaped result'; + is xml_escape('

    '), '<p>', 'right XSS escaped result'; + is xml_escape(b('

    ')), '

    ', 'right XSS escaped result'; }; subtest 'punycode_encode' => sub { @@ -554,7 +554,7 @@ subtest 'network_contains' => sub { subtest 'tablify' => sub { is tablify([["f\r\no o\r\n", 'bar']]), "fo o bar\n", 'right result'; is tablify([[" foo", ' b a r']]), " foo b a r\n", 'right result'; - is tablify([['foo']]), "foo\n", 'right result'; + is tablify([['foo']]), "foo\n", 'right result'; is tablify([['foo', 'yada'], ['yada', 'yada']]), "foo yada\nyada yada\n", 'right result'; is tablify([[undef, 'yada'], ['yada', undef]]), " yada\nyada \n", 'right result'; is tablify([['foo', 'bar', 'baz'], ['yada', 'yada', 'yada']]), "foo bar baz\nyada yada yada\n", 'right result'; @@ -574,7 +574,7 @@ subtest 'deprecated' => sub { ($warn, $die) = (); local $ENV{MOJO_FATAL_DEPRECATIONS} = 1; ok !eval { Mojo::DeprecationTest::foo() }, 'no result'; - ok !$warn, 'no warning'; + ok !$warn, 'no warning'; like $die, qr/foo is DEPRECATED at .*util\.t line \d+/, 'right exception'; }; @@ -597,12 +597,12 @@ subtest 'slugify' => sub { is slugify("Un \x{e9}l\x{e9}phant \x{e0} l'or\x{e9}e du bois"), 'un-elephant-a-loree-du-bois', 'right result'; is slugify("Un \x{e9}l\x{e9}phant \x{e0} l'or\x{e9}e du bois", 1), "un-\x{e9}l\x{e9}phant-\x{e0}-lor\x{e9}e-du-bois", 'right result'; - is slugify('Hello, World!'), 'hello-world', 'right result'; - is slugify('spam & eggs'), 'spam-eggs', 'right result'; - is slugify('spam & ıçüş', 1), 'spam-ıçüş', 'right result'; - is slugify('foo ıç bar', 1), 'foo-ıç-bar', 'right result'; - is slugify(' foo ıç bar', 1), 'foo-ıç-bar', 'right result'; - is slugify('你好', 1), '你好', 'right result'; + is slugify('Hello, World!'), 'hello-world', 'right result'; + is slugify('spam & eggs'), 'spam-eggs', 'right result'; + is slugify('spam & ıçüş', 1), 'spam-ıçüş', 'right result'; + is slugify('foo ıç bar', 1), 'foo-ıç-bar', 'right result'; + is slugify(' foo ıç bar', 1), 'foo-ıç-bar', 'right result'; + is slugify('你好', 1), '你好', 'right result'; }; subtest 'gzip/gunzip' => sub { @@ -625,23 +625,23 @@ subtest 'scope_guard' => sub { }; subtest 'humanize_bytes' => sub { - is humanize_bytes(0), '0B', 'zero Bytes'; - is humanize_bytes(1), '1B', 'one Byte'; - is humanize_bytes(-1023), '-1023B', 'negative Bytes'; - is humanize_bytes(1024), '1KiB', 'one KiB'; - is humanize_bytes(1025), '1KiB', 'one KiB'; - is humanize_bytes(1024 * 1024), '1MiB', 'one MiB'; - is humanize_bytes(1024 * 1024 * 1024), '1GiB', 'one GiB'; - is humanize_bytes(1024 * 1024 * 1024 * 1024), '1TiB', 'one TiB'; - is humanize_bytes(3000), '2.9KiB', 'almost 3KiB'; - is humanize_bytes(-3000), '-2.9KiB', 'almost -3KiB'; - is humanize_bytes(13443399680), '13GiB', 'two digits GiB'; - is humanize_bytes(8007188480), '7.5GiB', 'smaller GiB'; - is humanize_bytes(-8007188480), '-7.5GiB', 'negative smaller GiB'; - is humanize_bytes(-1099511627776), '-1TiB', 'negative smaller TiB'; - is humanize_bytes(717946880), '685MiB', 'large MiB'; - is humanize_bytes(-717946880), '-685MiB', 'large negative MiB'; - is humanize_bytes(245760), '240KiB', 'less than a MiB'; + is humanize_bytes(0), '0B', 'zero Bytes'; + is humanize_bytes(1), '1B', 'one Byte'; + is humanize_bytes(-1023), '-1023B', 'negative Bytes'; + is humanize_bytes(1024), '1KiB', 'one KiB'; + is humanize_bytes(1025), '1KiB', 'one KiB'; + is humanize_bytes(1024 * 1024), '1MiB', 'one MiB'; + is humanize_bytes(1024 * 1024 * 1024), '1GiB', 'one GiB'; + is humanize_bytes(1024 * 1024 * 1024 * 1024), '1TiB', 'one TiB'; + is humanize_bytes(3000), '2.9KiB', 'almost 3KiB'; + is humanize_bytes(-3000), '-2.9KiB', 'almost -3KiB'; + is humanize_bytes(13443399680), '13GiB', 'two digits GiB'; + is humanize_bytes(8007188480), '7.5GiB', 'smaller GiB'; + is humanize_bytes(-8007188480), '-7.5GiB', 'negative smaller GiB'; + is humanize_bytes(-1099511627776), '-1TiB', 'negative smaller TiB'; + is humanize_bytes(717946880), '685MiB', 'large MiB'; + is humanize_bytes(-717946880), '-685MiB', 'large negative MiB'; + is humanize_bytes(245760), '240KiB', 'less than a MiB'; }; subtest 'Hide DATA usage from error messages' => sub { diff --git a/t/mojo/websocket.t b/t/mojo/websocket.t index 4c69cbbad7..083db05e46 100644 --- a/t/mojo/websocket.t +++ b/t/mojo/websocket.t @@ -121,12 +121,12 @@ websocket '/timeout' => sub { # URL for WebSocket my $ua = app->ua; my $res = $ua->get('/link')->result; -is $res->code, 200, 'right status'; +is $res->code, 200, 'right status'; like $res->body, qr!ws://127\.0\.0\.1:\d+/!, 'right content'; # Plain HTTP request $res = $ua->get('/early_start')->res; -is $res->code, 404, 'right status'; +is $res->code, 404, 'right status'; like $res->body, qr/Page Not Found/, 'right content'; # Plain WebSocket @@ -186,9 +186,9 @@ $ua->websocket( ); Mojo::IOLoop->start; ok $established, 'connection established'; -is $status, 1000, 'right status'; -is $msg, 'I ♥ Mojolicious!', 'right message'; -is $result, 'test0test2test1', 'right result'; +is $status, 1000, 'right status'; +is $msg, 'I ♥ Mojolicious!', 'right message'; +is $result, 'test0test2test1', 'right result'; # WebSocket connection gets closed very fast $status = undef; @@ -233,9 +233,9 @@ $ua->websocket( ); Mojo::IOLoop->start; Mojo::IOLoop->one_tick until $stash->{finished}; -is $stash->{finished}, 1, 'finish event has been emitted once'; -is $code, 101, 'right status'; -is $result, 'test0test1', 'right result'; +is $stash->{finished}, 1, 'finish event has been emitted once'; +is $code, 101, 'right status'; +is $result, 'test0test1', 'right result'; # Concurrent subrequests ($code, $result) = (); @@ -363,7 +363,7 @@ $ua->websocket( ); Mojo::IOLoop->start; ok $finished, 'transaction is finished'; -ok !$ws, 'not a websocket'; +ok !$ws, 'not a websocket'; is $code, 500, 'right status'; is $msg, 'Internal Server Error', 'right message'; diff --git a/t/mojo/websocket_frames.t b/t/mojo/websocket_frames.t index acd1872281..527d964738 100644 --- a/t/mojo/websocket_frames.t +++ b/t/mojo/websocket_frames.t @@ -8,109 +8,109 @@ use Mojo::WebSocket qw(WS_BINARY WS_CLOSE WS_CONTINUATION WS_PING WS_PONG WS_TEX my $bytes = build_frame 0, 1, 0, 0, 0, WS_TEXT, 'whatever'; is $bytes, "\x81\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; my $frame = parse_frame \(my $dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 0, 0, 0, 1, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 0, 0, 0, 1, 'whatever'), $bytes, 'frames are equal'; # Simple ping frame roundtrip $bytes = build_frame 0, 1, 0, 0, 0, WS_PING, 'whatever'; is $bytes, "\x89\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 9, 'ping frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 0, 0, 0, 9, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 9, 'ping frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 0, 0, 0, 9, 'whatever'), $bytes, 'frames are equal'; # Simple pong frame roundtrip $bytes = build_frame 0, 1, 0, 0, 0, WS_PONG, 'whatever'; is $bytes, "\x8a\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 10, 'pong frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 0, 0, 0, 10, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 10, 'pong frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 0, 0, 0, 10, 'whatever'), $bytes, 'frames are equal'; # Simple text frame roundtrip with all flags set $bytes = build_frame 0, 1, 1, 1, 1, 1, 'whatever'; is $bytes, "\xf1\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 1, 'rsv1 flag is set'; -is $frame->[2], 1, 'rsv2 flag is set'; -is $frame->[3], 1, 'rsv3 flag is set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 1, 1, 1, 1, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 1, 'rsv1 flag is set'; +is $frame->[2], 1, 'rsv2 flag is set'; +is $frame->[3], 1, 'rsv3 flag is set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 1, 1, 1, 1, 'whatever'), $bytes, 'frames are equal'; # Simple text frame roundtrip without FIN bit $bytes = build_frame 0, 0, 0, 0, 0, 1, 'whatever'; is $bytes, "\x01\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 0, 'fin flag is not set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 0, 0, 0, 0, 1, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 0, 'fin flag is not set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 0, 0, 0, 0, 1, 'whatever'), $bytes, 'frames are equal'; # Simple text frame roundtrip with RSV1 flags set $bytes = build_frame(0, 1, 1, 0, 0, 1, 'whatever'); is $bytes, "\xc1\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 1, 'rsv1 flag is set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 1, 0, 0, 1, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 1, 'rsv1 flag is set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 1, 0, 0, 1, 'whatever'), $bytes, 'frames are equal'; # Simple continuation frame roundtrip with RSV2 flags set $bytes = build_frame(0, 1, 0, 1, 0, WS_CONTINUATION, 'whatever'); is $bytes, "\xa0\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 1, 'rsv2 flag is set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 0, 'continuation frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 0, 1, 0, 0, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 1, 'rsv2 flag is set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 0, 'continuation frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 0, 1, 0, 0, 'whatever'), $bytes, 'frames are equal'; # Simple text frame roundtrip with RSV3 flags set $bytes = build_frame(0, 1, 0, 0, 1, 1, 'whatever'); is $bytes, "\x91\x08\x77\x68\x61\x74\x65\x76\x65\x72", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 1, 'rsv3 flag is set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'whatever', 'right payload'; -is build_frame(0, 1, 0, 0, 1, 1, 'whatever'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 1, 'rsv3 flag is set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'whatever', 'right payload'; +is build_frame(0, 1, 0, 0, 1, 1, 'whatever'), $bytes, 'frames are equal'; # Simple binary frame roundtrip $bytes = build_frame(0, 1, 0, 0, 0, WS_BINARY, 'works'); is $bytes, "\x82\x05\x77\x6f\x72\x6b\x73", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 2, 'binary frame'; -is $frame->[5], 'works', 'right payload'; -is $bytes = build_frame(0, 1, 0, 0, 0, 2, 'works'), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 2, 'binary frame'; +is $frame->[5], 'works', 'right payload'; +is $bytes = build_frame(0, 1, 0, 0, 0, 2, 'works'), $bytes, 'frames are equal'; # Masked text frame roundtrip $bytes = build_frame 1, 1, 0, 0, 0, 1, 'also works'; @@ -138,72 +138,72 @@ isnt(build_frame(0, 1, 0, 0, 0, 2, 'just works'), $bytes, 'frames are not equal' $bytes = build_frame(0, 1, 0, 0, 0, 1, 'a'); is $bytes, "\x81\x01\x61", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'a', 'right payload'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'a', 'right payload'; is build_frame(0, 1, 0, 0, 0, 1, 'a'), $bytes, 'frames are equal'; # One-byte binary frame roundtrip $bytes = build_frame(0, 1, 0, 0, 0, 2, 'a'); is $bytes, "\x82\x01\x61", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 2, 'binary frame'; -is $frame->[5], 'a', 'right payload'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 2, 'binary frame'; +is $frame->[5], 'a', 'right payload'; is $bytes = build_frame(0, 1, 0, 0, 0, 2, 'a'), $bytes, 'frames are equal'; # 16-bit text frame roundtrip $bytes = build_frame(0, 1, 0, 0, 0, 1, 'hi' x 10000); is $bytes, "\x81\x7e\x4e\x20" . ("\x68\x69" x 10000), 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'hi' x 10000, 'right payload'; -is build_frame(0, 1, 0, 0, 0, 1, 'hi' x 10000), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'hi' x 10000, 'right payload'; +is build_frame(0, 1, 0, 0, 0, 1, 'hi' x 10000), $bytes, 'frames are equal'; # 64-bit text frame roundtrip $bytes = build_frame(0, 1, 0, 0, 0, 1, 'hi' x 200000); is $bytes, "\x81\x7f\x00\x00\x00\x00\x00\x06\x1a\x80" . ("\x68\x69" x 200000), 'right frame'; $frame = parse_frame \($dummy = $bytes), 500000; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], 'hi' x 200000, 'right payload'; -is build_frame(0, 1, 0, 0, 0, 1, 'hi' x 200000), $bytes, 'frames are equal'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], 'hi' x 200000, 'right payload'; +is build_frame(0, 1, 0, 0, 0, 1, 'hi' x 200000), $bytes, 'frames are equal'; # Empty text frame roundtrip $bytes = build_frame(0, 1, 0, 0, 0, 1, ''); is $bytes, "\x81\x00", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 1, 'text frame'; -is $frame->[5], '', 'no payload'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 1, 'text frame'; +is $frame->[5], '', 'no payload'; is build_frame(0, 1, 0, 0, 0, 1, ''), $bytes, 'frames are equal'; # Empty close frame roundtrip $bytes = build_frame(0, 1, 0, 0, 0, WS_CLOSE, ''); is $bytes, "\x88\x00", 'right frame'; $frame = parse_frame \($dummy = $bytes), 262144; -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 0, 'rsv1 flag is not set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; -is $frame->[4], 8, 'close frame'; -is $frame->[5], '', 'no payload'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 0, 'rsv1 flag is not set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[4], 8, 'close frame'; +is $frame->[5], '', 'no payload'; is build_frame(0, 1, 0, 0, 0, 8, ''), $bytes, 'frames are equal'; # Masked empty binary frame roundtrip @@ -221,7 +221,7 @@ isnt(build_frame(0, 1, 0, 0, 0, 2, ''), $bytes, 'frames are not equal'); $bytes = build_frame(0, 1, 0, 0, 0, WS_BINARY, 'works'); is $bytes, "\x82\x05\x77\x6f\x72\x6b\x73", 'right frame'; $frame = parse_frame \($dummy = $bytes), 4; -ok $frame, 'true'; +ok $frame, 'true'; ok !ref $frame, 'not a reference'; # Incomplete frame @@ -241,10 +241,10 @@ is $text, 'works!', 'right payload'; # Compressed binary message my $compressed = Mojo::Transaction::WebSocket->new({compressed => 1}); $frame = $compressed->build_message({binary => 'just works'}); -is $frame->[0], 1, 'fin flag is set'; -is $frame->[1], 1, 'rsv1 flag is set'; -is $frame->[2], 0, 'rsv2 flag is not set'; -is $frame->[3], 0, 'rsv3 flag is not set'; +is $frame->[0], 1, 'fin flag is set'; +is $frame->[1], 1, 'rsv1 flag is set'; +is $frame->[2], 0, 'rsv2 flag is not set'; +is $frame->[3], 0, 'rsv3 flag is not set'; is $frame->[4], WS_BINARY, 'binary frame'; ok $frame->[5], 'has payload'; my $payload = $compressed->build_message({binary => 'just works'})->[5]; @@ -252,13 +252,13 @@ isnt $frame->[5], $payload, 'different payload'; ok length $frame->[5] > length $payload, 'payload is smaller'; my $uncompressed = Mojo::Transaction::WebSocket->new; my $frame2 = $uncompressed->build_message({binary => 'just works'}); -is $frame2->[0], 1, 'fin flag is set'; -is $frame2->[1], 0, 'rsv1 flag is not set'; -is $frame2->[2], 0, 'rsv2 flag is not set'; -is $frame2->[3], 0, 'rsv3 flag is not set'; -is $frame2->[4], WS_BINARY, 'binary frame'; -ok $frame2->[5], 'has payload'; -isnt $frame->[5], $frame2->[5], 'different payload'; +is $frame2->[0], 1, 'fin flag is set'; +is $frame2->[1], 0, 'rsv1 flag is not set'; +is $frame2->[2], 0, 'rsv2 flag is not set'; +is $frame2->[3], 0, 'rsv3 flag is not set'; +is $frame2->[4], WS_BINARY, 'binary frame'; +ok $frame2->[5], 'has payload'; +isnt $frame->[5], $frame2->[5], 'different payload'; is $frame2->[5], $uncompressed->build_message({binary => 'just works'})->[5], 'same payload'; # Compressed fragmented message diff --git a/t/mojo/websocket_proxy_tls.t b/t/mojo/websocket_proxy_tls.t index 909a897756..ca2c8effdb 100644 --- a/t/mojo/websocket_proxy_tls.t +++ b/t/mojo/websocket_proxy_tls.t @@ -158,16 +158,16 @@ is $result, 'test1test2', 'right result'; # Blocking proxy requests $ua->proxy->https("http://sri:secr3t\@127.0.0.1:$proxy"); my $tx = $ua->max_connections(0)->get("https://127.0.0.1:$port/proxy"); -is $tx->res->code, 200, 'right status'; -is $tx->res->body, "https://127.0.0.1:$port/proxy", 'right content'; -is $tx->req->method, 'GET', 'right method'; -is $tx->previous->req->method, 'CONNECT', 'right method'; +is $tx->res->code, 200, 'right status'; +is $tx->res->body, "https://127.0.0.1:$port/proxy", 'right content'; +is $tx->req->method, 'GET', 'right method'; +is $tx->previous->req->method, 'CONNECT', 'right method'; $tx = $ua->max_connections(5)->get("https://127.0.0.1:$port/proxy"); ok !$tx->kept_alive, 'connection was not kept alive'; -is $tx->res->code, 200, 'right status'; -is $tx->res->body, "https://127.0.0.1:$port/proxy", 'right content'; -is $tx->req->method, 'GET', 'right method'; -is $tx->previous->req->method, 'CONNECT', 'right method'; +is $tx->res->code, 200, 'right status'; +is $tx->res->body, "https://127.0.0.1:$port/proxy", 'right content'; +is $tx->req->method, 'GET', 'right method'; +is $tx->previous->req->method, 'CONNECT', 'right method'; # Proxy WebSocket with bad target $ua->proxy->https("http://127.0.0.1:$proxy"); diff --git a/t/mojolicious/app.t b/t/mojolicious/app.t index 376b37d839..3d056d8143 100644 --- a/t/mojolicious/app.t +++ b/t/mojolicious/app.t @@ -79,24 +79,24 @@ subtest 'Preload namespaces' => sub { }; # Application is already available -is $t->app->routes->find('something')->to_string, '/test4/:something', 'right pattern'; +is $t->app->routes->find('something')->to_string, '/test4/:something', 'right pattern'; is $t->app->routes->find('test3')->pattern->defaults->{namespace}, 'MojoliciousTest2::Foo', 'right namespace'; is $t->app->routes->find('withblock')->pattern->defaults->{controller}, 'foo', 'right controller'; -is ref $t->app->routes->find('something'), 'Mojolicious::Routes::Route', 'right class'; -is ref $t->app->routes->find('something')->root, 'Mojolicious::Routes', 'right class'; -is $t->app->sessions->cookie_domain, '.example.com', 'right domain'; -is $t->app->sessions->cookie_path, '/bar', 'right path'; +is ref $t->app->routes->find('something'), 'Mojolicious::Routes::Route', 'right class'; +is ref $t->app->routes->find('something')->root, 'Mojolicious::Routes', 'right class'; +is $t->app->sessions->cookie_domain, '.example.com', 'right domain'; +is $t->app->sessions->cookie_path, '/bar', 'right path'; is_deeply $t->app->commands->namespaces, ['Mojolicious::Command::Author', 'Mojolicious::Command', 'MojoliciousTest::Command'], 'right namespaces'; -is $t->app, $t->app->commands->app, 'applications are equal'; +is $t->app, $t->app->commands->app, 'applications are equal'; is $t->app->static->file('hello.txt')->slurp, "Hello Mojo from a development static file!\n", 'right content'; -is $t->app->static->file('does_not_exist.html'), undef, 'no file'; -is $t->app->moniker, 'mojolicious_test', 'right moniker'; -is $t->app->secrets->[0], $t->app->moniker, 'secret defaults to moniker'; -is $t->app->renderer->template_handler({template => 'foo/bar/index', format => 'html'}), 'epl', 'right handler'; -is $t->app->build_controller->req->url, '', 'no URL'; -is $t->app->build_controller->render_to_string('does_not_exist'), undef, 'no result'; -is $t->app->build_controller->render_to_string(inline => '%= $c', c => 'foo'), "foo\n", 'right result'; +is $t->app->static->file('does_not_exist.html'), undef, 'no file'; +is $t->app->moniker, 'mojolicious_test', 'right moniker'; +is $t->app->secrets->[0], $t->app->moniker, 'secret defaults to moniker'; +is $t->app->renderer->template_handler({template => 'foo/bar/index', format => 'html'}), 'epl', 'right handler'; +is $t->app->build_controller->req->url, '', 'no URL'; +is $t->app->build_controller->render_to_string('does_not_exist'), undef, 'no result'; +is $t->app->build_controller->render_to_string(inline => '%= $c', c => 'foo'), "foo\n", 'right result'; # Missing methods and functions (AUTOLOAD) eval { $t->app->missing }; @@ -114,7 +114,7 @@ eval { Mojolicious::Route::missing() }; like $@, qr/^Undefined subroutine &Mojolicious::Route::missing called/, 'right error'; subtest 'Reserved stash value' => sub { - ok !$t->app->routes->is_reserved('foo'), 'not reserved'; + ok !$t->app->routes->is_reserved('foo'), 'not reserved'; ok $t->app->routes->is_reserved('action'), 'is reserved'; ok $t->app->routes->is_reserved('app'), 'is reserved'; ok $t->app->routes->is_reserved('cb'), 'is reserved'; @@ -446,15 +446,15 @@ is(MojoliciousTest->new({mode => 'test'})->mode, 'test', 'right mode'); $app = MojoliciousTest->new; my $tx = $t->ua->build_tx(GET => '/foo'); $app->handler($tx); -is $tx->res->code, 200, 'right status'; +is $tx->res->code, 200, 'right status'; like $tx->res->body, qr|Hello Mojo from the template /foo! Hello World!|, 'right content'; $tx = $t->ua->build_tx(GET => '/foo/willdie'); $app->handler($tx); -is $tx->res->code, 500, 'right status'; +is $tx->res->code, 500, 'right status'; like $tx->res->body, qr/Foo\.pm/, 'right content'; $tx = $t->ua->build_tx(GET => '/foo'); $app->handler($tx); -is $tx->res->code, 200, 'right status'; +is $tx->res->code, 200, 'right status'; like $tx->res->body, qr|Hello Mojo from the template /foo! Hello World!|, 'right content'; $t = Test::Mojo->new('SingleFileTestApp'); diff --git a/t/mojolicious/commands.t b/t/mojolicious/commands.t index 3cd26ae0fb..bc72f09aab 100644 --- a/t/mojolicious/commands.t +++ b/t/mojolicious/commands.t @@ -106,14 +106,14 @@ subtest 'Commands starting with a dash are not allowed' => sub { local $ENV{PLACK_ENV} = 'testing'; local @ARGV = qw(psgi -m production); is ref Mojolicious::Commands->start_app('MojoliciousTest'), 'CODE', 'right reference'; - is $ENV{MOJO_MODE}, undef, 'no mode'; + is $ENV{MOJO_MODE}, undef, 'no mode'; } # mojo is_deeply $commands->namespaces, ['Mojolicious::Command::Author', 'Mojolicious::Command'], 'right namespaces'; -ok $commands->description, 'has a description'; -like $commands->message, qr/COMMAND/, 'has a message'; -like $commands->hint, qr/help/, 'has a hint'; +ok $commands->description, 'has a description'; +like $commands->message, qr/COMMAND/, 'has a message'; +like $commands->hint, qr/help/, 'has a hint'; $buffer = ''; { open my $handle, '>', \$buffer; @@ -347,9 +347,9 @@ like $buffer, qr/Unknown option: unknown/, 'right output'; require Mojolicious::Command::Author::generate; my $generator = Mojolicious::Command::Author::generate->new; is_deeply $generator->namespaces, ['Mojolicious::Command::Author::generate'], 'right namespaces'; -ok $generator->description, 'has a description'; -like $generator->message, qr/generate/, 'has a message'; -like $generator->hint, qr/help/, 'has a hint'; +ok $generator->description, 'has a description'; +like $generator->message, qr/generate/, 'has a message'; +like $generator->hint, qr/help/, 'has a hint'; $buffer = ''; { open my $handle, '>', \$buffer; diff --git a/t/mojolicious/dispatch.t b/t/mojolicious/dispatch.t index f4c1edb54c..9ef7e8f8b6 100644 --- a/t/mojolicious/dispatch.t +++ b/t/mojolicious/dispatch.t @@ -33,8 +33,8 @@ is $c->stash('foo'), 'bar', 'set and return a stash value'; # Ref value my $stash = $c->stash; -is ref $stash, 'HASH', 'return a hash reference'; -is $stash->{foo}, 'bar', 'right value'; +is ref $stash, 'HASH', 'return a hash reference'; +is $stash->{foo}, 'bar', 'right value'; # Replace $c->stash(foo => 'baz'); @@ -72,14 +72,14 @@ is $c->stash->{b}, 2, 'right value'; # Override captures is $c->param('foo'), undef, 'no value'; -is $c->param(foo => 'works')->param('foo'), 'works', 'right value'; -is $c->param(foo => 'too')->param('foo'), 'too', 'right value'; +is $c->param(foo => 'works')->param('foo'), 'works', 'right value'; +is $c->param(foo => 'too')->param('foo'), 'too', 'right value'; is $c->param(foo => qw(just works))->param('foo'), 'works', 'right value'; is_deeply $c->every_param('foo'), [qw(just works)], 'right values'; -is_deeply $c->every_param('bar'), [], 'no values'; -is $c->param(foo => undef)->param('foo'), undef, 'no value'; +is_deeply $c->every_param('bar'), [], 'no values'; +is $c->param(foo => undef)->param('foo'), undef, 'no value'; is $c->param(foo => Mojo::Upload->new(name => 'bar'))->param('foo')->name, 'bar', 'right value'; -is $c->param(foo => ['ba;r', 'baz'])->param('foo'), 'baz', 'right value'; +is $c->param(foo => ['ba;r', 'baz'])->param('foo'), 'baz', 'right value'; is_deeply $c->every_param('foo'), ['ba;r', 'baz'], 'right values'; # Reserved stash values are hidden @@ -115,8 +115,8 @@ $c = $app->build_controller; $c->req->method('GET'); $c->req->url->parse('/'); ok $d->dispatch($c), 'dispatched'; -is $c->stash->{controller}, 'foo', 'right value'; -is $c->stash->{action}, 'home', 'right value'; +is $c->stash->{controller}, 'foo', 'right value'; +is $c->stash->{action}, 'home', 'right value'; is $c->match->stack->[0]{controller}, 'foo', 'right value'; is $c->match->stack->[0]{action}, 'home', 'right value'; ok $c->render_called, 'rendered'; @@ -126,8 +126,8 @@ $c = $app->build_controller; $c->req->method('GET'); $c->req->url->parse('/'); $d->match($c); -is $c->stash->{controller}, undef, 'no value'; -is $c->stash->{action}, undef, 'no value'; +is $c->stash->{controller}, undef, 'no value'; +is $c->stash->{action}, undef, 'no value'; is $c->match->stack->[0]{controller}, 'foo', 'right value'; is $c->match->stack->[0]{action}, 'home', 'right value'; ok !$c->render_called, 'not rendered'; @@ -135,8 +135,8 @@ $c = $app->build_controller; $c->req->method('GET'); $c->req->url->parse('/'); ok $d->dispatch($c), 'dispatched'; -is $c->stash->{controller}, 'foo', 'right value'; -is $c->stash->{action}, 'home', 'right value'; +is $c->stash->{controller}, 'foo', 'right value'; +is $c->stash->{action}, 'home', 'right value'; is $c->match->stack->[0]{controller}, 'foo', 'right value'; is $c->match->stack->[0]{action}, 'home', 'right value'; ok $c->render_called, 'rendered'; @@ -146,7 +146,7 @@ is_deeply $d->cache->get('GET:/:0'), $cache, 'cached route has been reused'; $c = $app->build_controller; $c->req->method('GET'); $c->req->url->parse('/not_found'); -ok !$d->dispatch($c), 'not dispatched'; +ok !$d->dispatch($c), 'not dispatched'; ok !$c->render_called, 'nothing rendered'; # No escaping diff --git a/t/mojolicious/embedded_lite_app.t b/t/mojolicious/embedded_lite_app.t index 6765816d0d..e39dd38a21 100644 --- a/t/mojolicious/embedded_lite_app.t +++ b/t/mojolicious/embedded_lite_app.t @@ -78,8 +78,8 @@ app->routes->namespaces(['MyTestApp']); my $external = curfile->sibling('external', 'myapp.pl'); plugin Mount => {'/x/1' => $external}; my $route = plugin(Mount => ('/x/♥' => $external))->to(message => 'works 2!'); -is $route->to->{message}, 'works 2!', 'right message'; -is $route->pattern->defaults->{app}->same_name, 'myapp', 'right name'; +is $route->to->{message}, 'works 2!', 'right message'; +is $route->pattern->defaults->{app}->same_name, 'myapp', 'right name'; plugin Mount => {'/y/1' => curfile->sibling('external', 'myapp2.pl')}; plugin Mount => {'mojolicious.org' => $external}; plugin(Mount => ('/y/♥' => curfile->sibling('external', 'myapp2.pl')))->to(message => 'works 3!'); diff --git a/t/mojolicious/exception_lite_app.t b/t/mojolicious/exception_lite_app.t index 5037d93ade..9adcdeb0ba 100644 --- a/t/mojolicious/exception_lite_app.t +++ b/t/mojolicious/exception_lite_app.t @@ -283,8 +283,8 @@ subtest 'Reuse exception' => sub { ok !$exception, 'no exception'; ok !$snapshot, 'no snapshot'; $t->get_ok('/reuse/exception')->status_is(500)->content_like(qr/Reusable exception/); - isa_ok $exception, 'Mojo::Exception', 'right exception'; - like $exception, qr/Reusable exception/, 'right message'; + isa_ok $exception, 'Mojo::Exception', 'right exception'; + like $exception, qr/Reusable exception/, 'right message'; is $snapshot->{foo}, 'bar', 'right snapshot value'; ok !$snapshot->{exception}, 'no exception in snapshot'; }; diff --git a/t/mojolicious/json_config_lite_app.t b/t/mojolicious/json_config_lite_app.t index 4daec051f0..ae6cdc0146 100644 --- a/t/mojolicious/json_config_lite_app.t +++ b/t/mojolicious/json_config_lite_app.t @@ -27,24 +27,24 @@ subtest 'Load plugins' => sub { my $config = plugin j_s_o_n_config => {default => {foo => 'baz', hello => 'there'}}; my $path = curfile->sibling('json_config_lite_app_abs.json'); plugin JSONConfig => {file => $path}; - is $config->{foo}, 'bar', 'right value'; - is $config->{hello}, 'there', 'right value'; - is $config->{utf}, 'утф', 'right value'; - is $config->{absolute}, 'works too!', 'right value'; - is $config->{absolute_dev}, 'dev works too!', 'right value'; - is app->config->{foo}, 'bar', 'right value'; - is app->config->{hello}, 'there', 'right value'; - is app->config->{utf}, 'утф', 'right value'; - is app->config->{absolute}, 'works too!', 'right value'; - is app->config->{absolute_dev}, 'dev works too!', 'right value'; - is app->config('foo'), 'bar', 'right value'; - is app->config('hello'), 'there', 'right value'; - is app->config('utf'), 'утф', 'right value'; - is app->config('absolute'), 'works too!', 'right value'; - is app->config('absolute_dev'), 'dev works too!', 'right value'; - is app->config('it'), 'works', 'right value'; - is app->deployment_helper, 'deployment plugins work!', 'right value'; - is app->another_helper, 'works too!', 'right value'; + is $config->{foo}, 'bar', 'right value'; + is $config->{hello}, 'there', 'right value'; + is $config->{utf}, 'утф', 'right value'; + is $config->{absolute}, 'works too!', 'right value'; + is $config->{absolute_dev}, 'dev works too!', 'right value'; + is app->config->{foo}, 'bar', 'right value'; + is app->config->{hello}, 'there', 'right value'; + is app->config->{utf}, 'утф', 'right value'; + is app->config->{absolute}, 'works too!', 'right value'; + is app->config->{absolute_dev}, 'dev works too!', 'right value'; + is app->config('foo'), 'bar', 'right value'; + is app->config('hello'), 'there', 'right value'; + is app->config('utf'), 'утф', 'right value'; + is app->config('absolute'), 'works too!', 'right value'; + is app->config('absolute_dev'), 'dev works too!', 'right value'; + is app->config('it'), 'works', 'right value'; + is app->deployment_helper, 'deployment plugins work!', 'right value'; + is app->another_helper, 'works too!', 'right value'; }; get '/' => 'index'; @@ -55,8 +55,8 @@ $t->get_ok('/')->status_is(200)->content_is("barbar\n"); subtest 'No config file, default only' => sub { my $config = plugin JSONConfig => {file => 'nonexistent', default => {foo => 'qux'}}; - is $config->{foo}, 'qux', 'right value'; - is app->config->{foo}, 'qux', 'right value'; + is $config->{foo}, 'qux', 'right value'; + is app->config->{foo}, 'qux', 'right value'; is app->config('foo'), 'qux', 'right value'; is app->config('it'), 'works', 'right value'; }; diff --git a/t/mojolicious/lite_app.t b/t/mojolicious/lite_app.t index 073f17c62d..72ed8c0b38 100644 --- a/t/mojolicious/lite_app.t +++ b/t/mojolicious/lite_app.t @@ -33,14 +33,14 @@ helper test_helper => sub { shift->param(@_) }; helper test_helper2 => sub { shift->app->controller_class }; helper test_helper3 => sub { state $cache = {} }; helper dead => sub { die $_[1] || 'works!' }; -is app->test_helper('foo'), undef, 'no value yet'; -is app->test_helper2, 'Mojolicious::Controller', 'right value'; +is app->test_helper('foo'), undef, 'no value yet'; +is app->test_helper2, 'Mojolicious::Controller', 'right value'; app->test_helper3->{foo} = 'bar'; is app->test_helper3->{foo}, 'bar', 'right result'; # Nested helpers helper 'test.helper' => sub { shift->app->controller_class }; -is app->test->helper, 'Mojolicious::Controller', 'right value'; +is app->test->helper, 'Mojolicious::Controller', 'right value'; is app->build_controller->test->helper, 'Mojolicious::Controller', 'right value'; # Test renderer @@ -469,15 +469,15 @@ get '/timing' => sub { my $t = Test::Mojo->new; # Application is already available -is $t->app->test_helper2, 'Mojolicious::Controller', 'right class'; -is $t->app->moniker, 'lite_app', 'right moniker'; -is $t->app->stash->{default}, 23, 'right value'; -is $t->app, app->build_controller->app->commands->app, 'applications are equal'; -is $t->app->build_controller->req->url, '', 'no URL'; -is $t->app->build_controller->stash->{default}, 23, 'right value'; -is $t->app->build_controller($t->app->ua->build_tx(GET => '/foo'))->req->url, '/foo', 'right URL'; -is $t->app->build_controller->render_to_string('index', handler => 'epl'), 'Just works!', 'right result'; -is $t->app->build_controller->render_to_string(inline => '0'), "0\n", 'right result'; +is $t->app->test_helper2, 'Mojolicious::Controller', 'right class'; +is $t->app->moniker, 'lite_app', 'right moniker'; +is $t->app->stash->{default}, 23, 'right value'; +is $t->app, app->build_controller->app->commands->app, 'applications are equal'; +is $t->app->build_controller->req->url, '', 'no URL'; +is $t->app->build_controller->stash->{default}, 23, 'right value'; +is $t->app->build_controller($t->app->ua->build_tx(GET => '/foo'))->req->url, '/foo', 'right URL'; +is $t->app->build_controller->render_to_string('index', handler => 'epl'), 'Just works!', 'right result'; +is $t->app->build_controller->render_to_string(inline => '0'), "0\n", 'right result'; # Empty template $t->get_ok('/empty')->status_is(200)->content_is(''); @@ -936,7 +936,7 @@ $t->ua->max_redirects(3); $t->get_ok('/redirect_twice')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') ->text_is('div#☃' => 'Redirect works!'); my $redirects = $t->tx->redirects; -is scalar @$redirects, 2, 'two redirects'; +is scalar @$redirects, 2, 'two redirects'; is $redirects->[0]->req->url->path, '/redirect_twice', 'right path'; is $redirects->[1]->req->url->path, '/redirect_named', 'right path'; $t->ua->max_redirects(0); diff --git a/t/mojolicious/longpolling_lite_app.t b/t/mojolicious/longpolling_lite_app.t index aaec480142..4c25b83dfb 100644 --- a/t/mojolicious/longpolling_lite_app.t +++ b/t/mojolicious/longpolling_lite_app.t @@ -180,14 +180,14 @@ subtest 'Stream without delay and content length' => sub { $t->get_ok('/write/length')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_type_is('text/plain') ->content_is('this was short and plain.'); ok !$t->tx->kept_alive, 'connection was not kept alive'; - ok $t->tx->keep_alive, 'connection will be kept alive'; + ok $t->tx->keep_alive, 'connection will be kept alive'; }; subtest 'Stream without delay and empty write' => sub { $t->get_ok('/write/nolength')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') ->header_is('Content-Length' => undef)->content_type_is('text/plain') ->content_is('this was short and had no length.'); - ok $t->tx->kept_alive, 'connection was kept alive'; + ok $t->tx->kept_alive, 'connection was kept alive'; ok !$t->tx->keep_alive, 'connection will not be kept alive'; }; @@ -198,7 +198,7 @@ subtest 'Chunked response with delay' => sub { ->content_type_is('text/plain')->content_is('hi there, whats up?'); Mojo::IOLoop->one_tick until $stash->{finished}; ok !$t->tx->kept_alive, 'connection was not kept alive'; - ok $t->tx->keep_alive, 'connection will be kept alive'; + ok $t->tx->keep_alive, 'connection will be kept alive'; is $stash->{finished}, 1, 'finish event has been emitted once'; ok $stash->{destroyed}, 'controller has been destroyed'; }; @@ -230,9 +230,9 @@ subtest 'Interrupted by raising an error' => sub { } ); $t->ua->start($tx); - is $tx->res->code, 200, 'right status'; + is $tx->res->code, 200, 'right status'; is $tx->res->error->{message}, 'Interrupted', 'right error'; - is $buffer, 'hi ', 'right content'; + is $buffer, 'hi ', 'right content'; }; subtest 'Stream with delay and content length' => sub { @@ -285,7 +285,7 @@ subtest 'Rendering of template' => sub { $t->app->plugins->once(before_dispatch => sub { $stash = shift->stash }); $t->get_ok('/render')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('Finish!'); Mojo::IOLoop->one_tick until $stash->{destroyed}; - ok !$stash->{writing}, 'finish event timing is right'; + ok !$stash->{writing}, 'finish event timing is right'; ok $stash->{destroyed}, 'controller has been destroyed'; }; diff --git a/t/mojolicious/ojo.t b/t/mojolicious/ojo.t index 673a848bc8..7895b19394 100644 --- a/t/mojolicious/ojo.t +++ b/t/mojolicious/ojo.t @@ -16,13 +16,13 @@ subtest 'Application' => sub { }; subtest 'Requests' => sub { - is g('/')->body, 'GET', 'right content'; - is h('/')->body, '', 'no content'; - is o('/')->body, 'OPTIONS', 'right content'; - is t('/')->body, 'PATCH', 'right content'; - is p('/')->body, 'POST', 'right content'; - is u('/')->body, 'PUT', 'right content'; - is d('/')->body, 'DELETE', 'right content'; + is g('/')->body, 'GET', 'right content'; + is h('/')->body, '', 'no content'; + is o('/')->body, 'OPTIONS', 'right content'; + is t('/')->body, 'PATCH', 'right content'; + is p('/')->body, 'POST', 'right content'; + is u('/')->body, 'PUT', 'right content'; + is d('/')->body, 'DELETE', 'right content'; is p('/' => form => {foo => 'bar'})->body, 'POSTfoo=bar', 'right content'; is p('/' => json => {foo => 'bar'})->body, 'POST{"foo":"bar"}', 'right content'; }; @@ -65,10 +65,10 @@ subtest 'Benchmark' => sub { local *STDERR = $handle; my $i = 0; n { ++$i }; - is $i, 1, 'block has been executed once'; + is $i, 1, 'block has been executed once'; like $buffer, qr/wallclock/, 'right output'; n { $i++ } 10; - is $i, 11, 'block has been executed ten times'; + is $i, 11, 'block has been executed ten times'; like $buffer, qr/wallclock.*wallclock/s, 'right output'; }; diff --git a/t/mojolicious/pattern.t b/t/mojolicious/pattern.t index e63e1506ce..d6ceb5b6be 100644 --- a/t/mojolicious/pattern.t +++ b/t/mojolicious/pattern.t @@ -25,7 +25,7 @@ $pattern->defaults({name => 'foo'}); is_deeply $pattern->match('/test123', 1), {name => 'foo'}, 'right structure'; is_deeply $pattern->match('/testbar123', 1), {name => 'bar'}, 'right structure'; ok !$pattern->match('/test/123'), 'no result'; -is $pattern->render, '/testfoo123', 'right result'; +is $pattern->render, '/testfoo123', 'right result'; is $pattern->render({name => 'bar'}), '/testbar123', 'right result'; $pattern->defaults({name => ''}); is_deeply $pattern->match('/test123', 1), {name => ''}, 'right structure'; @@ -35,7 +35,7 @@ $pattern->defaults({name => 'foo'}); is_deeply $pattern->match('/test/123', 1), {name => 'foo'}, 'right structure'; is_deeply $pattern->match('/test/bar/123', 1), {name => 'bar'}, 'right structure'; ok !$pattern->match('/test'), 'no result'; -is $pattern->render, '/test/foo/123', 'right result'; +is $pattern->render, '/test/foo/123', 'right result'; is $pattern->render({name => 'bar'}), '/test/bar/123', 'right result'; # Multiple optional placeholders in the middle @@ -46,8 +46,8 @@ is_deeply $pattern->match('/test/c/123/456', 1), {a => 'c', b => 'b'}, 'right is_deeply $pattern->match('/test/123/c/456', 1), {a => 'a', b => 'c'}, 'right structure'; is_deeply $pattern->match('/test/c/123/d/456', 1), {a => 'c', b => 'd'}, 'right structure'; is $pattern->render, '/test/a/123/b/456', 'right result'; -is $pattern->render({a => 'c'}), '/test/c/123/b/456', 'right result'; -is $pattern->render({b => 'c'}), '/test/a/123/c/456', 'right result'; +is $pattern->render({a => 'c'}), '/test/c/123/b/456', 'right result'; +is $pattern->render({b => 'c'}), '/test/a/123/c/456', 'right result'; is $pattern->render({a => 'c', b => 'd'}), '/test/c/123/d/456', 'right result'; # Root @@ -56,7 +56,7 @@ is $pattern->unparsed, undef, 'slash has been optimized away'; $pattern->defaults({action => 'index'}); ok !$pattern->match('/test/foo/bar'), 'no result'; is_deeply $pattern->match('/'), {action => 'index'}, 'right structure'; -is $pattern->render, '', 'right result'; +is $pattern->render, '', 'right result'; is $pattern->render({format => 'txt'}, 1), '.txt', 'right result'; # Regex in pattern @@ -65,7 +65,7 @@ $pattern->defaults({action => 'index', id => 1}); is_deeply $pattern->match('/test/foo/bar/203'), {controller => 'foo', action => 'bar', id => 203}, 'right structure'; ok !$pattern->match('/test/foo/bar/baz'), 'no result'; is $pattern->render({controller => 'zzz', action => 'index', id => 13}), '/test/zzz/index/13', 'right result'; -is $pattern->render({controller => 'zzz'}), '/test/zzz', 'right result'; +is $pattern->render({controller => 'zzz'}), '/test/zzz', 'right result'; # Quoted placeholders $pattern = Mojolicious::Routes::Pattern->new('/<:controller>test/'); @@ -80,7 +80,7 @@ is_deeply $pattern->match('/test/foo.bar/baz'), {controller => 'foo.bar', action is $pattern->render({controller => 'foo.bar', action => 'baz'}), '/test/foo.bar/baz', 'right result'; $pattern = Mojolicious::Routes::Pattern->new('/test/<#groovy>'); is_deeply $pattern->match('/test/foo.bar'), {groovy => 'foo.bar'}, 'right structure'; -is $pattern->defaults->{format}, undef, 'no value'; +is $pattern->defaults->{format}, undef, 'no value'; is $pattern->render({groovy => 'foo.bar'}), '/test/foo.bar', 'right result'; # Wildcard @@ -142,9 +142,9 @@ ok !$pattern->match('/test'), 'no result'; # Formats without detection $pattern = Mojolicious::Routes::Pattern->new('/test'); $pattern->defaults({action => 'index'}); -ok !$pattern->regex, 'no regex'; +ok !$pattern->regex, 'no regex'; ok !$pattern->match('/test.xml'), 'no result'; -ok $pattern->regex, 'regex has been compiled on demand'; +ok $pattern->regex, 'regex has been compiled on demand'; is_deeply $pattern->match('/test'), {action => 'index'}, 'right structure'; # Format detection disabled @@ -152,7 +152,7 @@ $pattern = Mojolicious::Routes::Pattern->new('/test', format => 0); $pattern->defaults({action => 'index'}); ok !$pattern->regex, 'no regex'; is_deeply $pattern->match('/test', 1), {action => 'index'}, 'right structure'; -ok $pattern->regex, 'regex has been compiled on demand'; +ok $pattern->regex, 'regex has been compiled on demand'; ok !$pattern->match('/test.xml', 1), 'no result'; # Special pattern for disabling format detection @@ -177,7 +177,7 @@ $pattern->defaults({action => 'index', format => 'html'}); $pattern->constraints({format => ['txt']}); $result = $pattern->match('/foo/v1.0.txt', 1); is_deeply $result, {test => 'foo', action => 'index', format => 'txt'}, 'right structure'; -is $pattern->render($result), '/foo/v1.0', 'right result'; +is $pattern->render($result), '/foo/v1.0', 'right result'; is $pattern->render($result, 1), '/foo/v1.0.txt', 'right result'; ok !$pattern->match('/foo/v2.0', 1), 'no result'; diff --git a/t/mojolicious/production_app.t b/t/mojolicious/production_app.t index 22efc8b8a1..e295d8aaaf 100644 --- a/t/mojolicious/production_app.t +++ b/t/mojolicious/production_app.t @@ -14,19 +14,19 @@ use lib curfile->sibling('lib')->to_string; my $t = Test::Mojo->new('MojoliciousTest'); # Application is already available -is $t->app->routes->find('something')->to_string, '/test4/:something', 'right pattern'; +is $t->app->routes->find('something')->to_string, '/test4/:something', 'right pattern'; is $t->app->routes->find('test3')->pattern->defaults->{namespace}, 'MojoliciousTest2::Foo', 'right namespace'; is $t->app->routes->find('withblock')->pattern->defaults->{controller}, 'foo', 'right controller'; -is ref $t->app->routes->find('something'), 'Mojolicious::Routes::Route', 'right class'; -is ref $t->app->routes->find('something')->root, 'Mojolicious::Routes', 'right class'; -is $t->app->sessions->cookie_domain, '.example.com', 'right domain'; -is $t->app->sessions->cookie_path, '/bar', 'right path'; +is ref $t->app->routes->find('something'), 'Mojolicious::Routes::Route', 'right class'; +is ref $t->app->routes->find('something')->root, 'Mojolicious::Routes', 'right class'; +is $t->app->sessions->cookie_domain, '.example.com', 'right domain'; +is $t->app->sessions->cookie_path, '/bar', 'right path'; is_deeply $t->app->commands->namespaces, ['Mojolicious::Command::Author', 'Mojolicious::Command', 'MojoliciousTest::Command'], 'right namespaces'; -is $t->app, $t->app->commands->app, 'applications are equal'; -is $t->app->static->file('hello.txt')->slurp, "Hello Mojo from a static file!\n", 'right content'; -is $t->app->static->file('does_not_exist.html'), undef, 'no file'; -is $t->app->moniker, 'mojolicious_test', 'right moniker'; +is $t->app, $t->app->commands->app, 'applications are equal'; +is $t->app->static->file('hello.txt')->slurp, "Hello Mojo from a static file!\n", 'right content'; +is $t->app->static->file('does_not_exist.html'), undef, 'no file'; +is $t->app->moniker, 'mojolicious_test', 'right moniker'; # Remove extra files isnt $t->app->static->file('mojo/jquery/jquery.js'), undef, 'found jQuery'; diff --git a/t/mojolicious/renderer.t b/t/mojolicious/renderer.t index f1b0c1526e..f19266a16f 100644 --- a/t/mojolicious/renderer.t +++ b/t/mojolicious/renderer.t @@ -67,14 +67,14 @@ $first->app->helper('myapp.multi_level.test' => sub {'works!'}); ok $first->app->renderer->get_helper('myapp'), 'found helper'; ok $first->app->renderer->get_helper('myapp.multi_level'), 'found helper'; ok $first->app->renderer->get_helper('myapp.multi_level.test'), 'found helper'; -is $first->myapp->multi_level->test, 'works!', 'right result'; +is $first->myapp->multi_level->test, 'works!', 'right result'; is $first->helpers->myapp->multi_level->test, 'works!', 'right result'; $first->app->helper('myapp.defaults' => sub { shift->app->defaults(@_) }); ok $first->app->renderer->get_helper('myapp.defaults'), 'found helper'; -is $first->app->renderer->get_helper('myap.'), undef, 'no helper'; -is $first->app->renderer->get_helper('yapp'), undef, 'no helper'; +is $first->app->renderer->get_helper('myap.'), undef, 'no helper'; +is $first->app->renderer->get_helper('yapp'), undef, 'no helper'; $first->myapp->defaults(foo => 'bar'); -is $first->myapp->defaults('foo'), 'bar', 'right result'; +is $first->myapp->defaults('foo'), 'bar', 'right result'; is $first->helpers->myapp->defaults('foo'), 'bar', 'right result'; is $first->app->myapp->defaults('foo'), 'bar', 'right result'; my $app2 = Mojolicious->new(secrets => ['works']); @@ -84,11 +84,11 @@ is $second->app->renderer->get_helper('myapp'), undef, 'no helper'; is $second->app->renderer->get_helper('myapp.defaults'), undef, 'no helper'; $second->app->helper('myapp.defaults' => sub {'nothing'}); my $myapp = $first->myapp; -is $first->myapp->defaults('foo'), 'bar', 'right result'; -is $second->myapp->defaults('foo'), 'nothing', 'right result'; +is $first->myapp->defaults('foo'), 'bar', 'right result'; +is $second->myapp->defaults('foo'), 'nothing', 'right result'; is $second->helpers->myapp->defaults('foo'), 'nothing', 'right result'; -is $first->myapp->defaults('foo'), 'bar', 'right result'; -is $first->helpers->myapp->defaults('foo'), 'bar', 'right result'; +is $first->myapp->defaults('foo'), 'bar', 'right result'; +is $first->helpers->myapp->defaults('foo'), 'bar', 'right result'; # Reuse proxy objects my $helpers = $first->helpers; @@ -112,13 +112,13 @@ $renderer->respond($c, $output, 'html'); is $c->res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; is $c->res->headers->vary, 'Accept-Encoding', 'right "Vary" value'; is $c->res->headers->content_encoding, 'gzip', 'right "Content-Encoding" value'; -isnt $c->res->body, $output, 'different string'; -is gunzip($c->res->body), $output, 'same string'; +isnt $c->res->body, $output, 'different string'; +is gunzip($c->res->body), $output, 'same string'; # Compression (not requested) $c = $app->build_controller; $renderer->respond($c, $output, 'html'); -is $c->res->code, 200, 'right status'; +is $c->res->code, 200, 'right status'; is $c->res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; is $c->res->headers->vary, 'Accept-Encoding', 'right "Vary" value'; ok !$c->res->headers->content_encoding, 'no "Content-Encoding" value'; @@ -128,11 +128,11 @@ is $c->res->body, $output, 'same string'; $c = $app->build_controller; $c->res->headers->content_encoding('whatever'); $renderer->respond($c, $output, 'html', 500); -is $c->res->code, 500, 'right status'; +is $c->res->code, 500, 'right status'; is $c->res->headers->content_type, 'text/html;charset=UTF-8', 'right "Content-Type" value'; is $c->res->headers->vary, 'Accept-Encoding', 'right "Vary" value'; is $c->res->headers->content_encoding, 'whatever', 'right "Content-Encoding" value'; -is $c->res->body, $output, 'same string'; +is $c->res->body, $output, 'same string'; # Compression (below minimum length) $output = 'a' x 850; diff --git a/t/mojolicious/routes.t b/t/mojolicious/routes.t index f347e35f2d..1ff43ef2bf 100644 --- a/t/mojolicious/routes.t +++ b/t/mojolicious/routes.t @@ -242,11 +242,11 @@ subtest 'Make sure stash stays clean' => sub { my $c = Mojolicious::Controller->new; my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/clean'}); - is $m->root, $r, 'right root'; + is $m->root, $r, 'right root'; is $m->endpoint->name, 'very_clean', 'right name'; is_deeply $m->stack, [{clean => 1}], 'right strucutre'; - is $m->path_for->{path}, '/clean', 'right path'; - is $m->endpoint->suggested_method, 'GET', 'right method'; + is $m->path_for->{path}, '/clean', 'right path'; + is $m->endpoint->suggested_method, 'GET', 'right method'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/clean/too'}); is_deeply $m->stack, [{something => 1}], 'right strucutre'; @@ -257,8 +257,8 @@ subtest 'No match' => sub { my $c = Mojolicious::Controller->new; my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/does_not_exist'}); - is $m->root, $r, 'right root'; - is $m->endpoint, undef, 'no endpoint'; + is $m->root, $r, 'right root'; + is $m->endpoint, undef, 'no endpoint'; is_deeply $m->stack, [], 'empty stack'; }; @@ -285,8 +285,8 @@ subtest 'Alternatives with default' => sub { $m->find($c => {method => 'GET', path => '/alternatives'}); is_deeply $m->stack, [{foo => 11}], 'right strucutre'; is $m->path_for->{path}, '/alternatives', 'right path'; - is $m->path_for(format => 'txt')->{path}, '/alternatives/11.txt', 'right path'; - is $m->path_for(foo => 12, format => 'txt')->{path}, '/alternatives/12.txt', 'right path'; + is $m->path_for(format => 'txt')->{path}, '/alternatives/11.txt', 'right path'; + is $m->path_for(foo => 12, format => 'txt')->{path}, '/alternatives/12.txt', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/alternatives/0'}); is_deeply $m->stack, [{foo => 0}], 'right strucutre'; @@ -308,8 +308,8 @@ subtest 'Alternatives with default' => sub { $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/alternatives/00'}); is_deeply $m->stack, [], 'empty stack'; - is $m->path_for('alternativesfoo')->{path}, '/alternatives', 'right path'; - is $m->path_for('alternativesfoo', format => 'txt')->{path}, '/alternatives/11.txt', 'right path'; + is $m->path_for('alternativesfoo')->{path}, '/alternatives', 'right path'; + is $m->path_for('alternativesfoo', format => 'txt')->{path}, '/alternatives/11.txt', 'right path'; is $m->path_for('alternativesfoo', foo => 12, format => 'txt')->{path}, '/alternatives/12.txt', 'right path'; }; @@ -339,7 +339,7 @@ subtest 'Alternatives without default' => sub { $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/alternatives2/00'}); is_deeply $m->stack, [], 'empty stack'; - is $m->path_for('alternatives2foo')->{path}, '/alternatives2/', 'right path'; + is $m->path_for('alternatives2foo')->{path}, '/alternatives2/', 'right path'; is $m->path_for('alternatives2foo', foo => 0)->{path}, '/alternatives2/0', 'right path'; }; @@ -381,17 +381,17 @@ subtest 'Optional placeholder' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/optional/23'}); is_deeply $m->stack, [{foo => 23, bar => 'test'}], 'right structure'; - is $m->path_for->{path}, '/optional/23', 'right path'; - is $m->path_for(format => 'txt')->{path}, '/optional/23/test.txt', 'right path'; - is $m->path_for(foo => 12, format => 'txt')->{path}, '/optional/12/test.txt', 'right path'; + is $m->path_for->{path}, '/optional/23', 'right path'; + is $m->path_for(format => 'txt')->{path}, '/optional/23/test.txt', 'right path'; + is $m->path_for(foo => 12, format => 'txt')->{path}, '/optional/12/test.txt', 'right path'; is $m->path_for('optionalfoobar', format => 'txt')->{path}, '/optional/23/test.txt', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/optional/23/24'}); is_deeply $m->stack, [{foo => 23, bar => 24}], 'right structure'; - is $m->path_for->{path}, '/optional/23/24', 'right path'; - is $m->path_for(format => 'txt')->{path}, '/optional/23/24.txt', 'right path'; - is $m->path_for('optionalfoobar')->{path}, '/optional/23/24', 'right path'; - is $m->path_for('optionalfoobar', foo => 0)->{path}, '/optional/0/24', 'right path'; + is $m->path_for->{path}, '/optional/23/24', 'right path'; + is $m->path_for(format => 'txt')->{path}, '/optional/23/24.txt', 'right path'; + is $m->path_for('optionalfoobar')->{path}, '/optional/23/24', 'right path'; + is $m->path_for('optionalfoobar', foo => 0)->{path}, '/optional/0/24', 'right path'; }; subtest 'Optional placeholders in nested routes' => sub { @@ -427,11 +427,11 @@ subtest 'Real world example using most features at once' => sub { {testcase => 'articles', action => 'edit', id => 1, format => 'html'} ); is_deeply $m->stack, \@stack, 'right structure'; - is $m->path_for->{path}, '/articles/1/edit', 'right path'; - is $m->path_for(format => 'html')->{path}, '/articles/1/edit.html', 'right path'; - is $m->path_for('articles_delete', format => undef)->{path}, '/articles/1/delete', 'right path'; - is $m->path_for('articles_delete')->{path}, '/articles/1/delete', 'right path'; - is $m->path_for('articles_delete', id => 12)->{path}, '/articles/12/delete', 'right path'; + is $m->path_for->{path}, '/articles/1/edit', 'right path'; + is $m->path_for(format => 'html')->{path}, '/articles/1/edit.html', 'right path'; + is $m->path_for('articles_delete', format => undef)->{path}, '/articles/1/delete', 'right path'; + is $m->path_for('articles_delete')->{path}, '/articles/1/delete', 'right path'; + is $m->path_for('articles_delete', id => 12)->{path}, '/articles/12/delete', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/articles/1/delete'}); @stack = ( @@ -467,8 +467,8 @@ subtest 'Path and captures' => sub { $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/foo/testedit'}); is_deeply $m->stack, [{testcase => 'foo', action => 'testedit'}], 'right structure'; - is $m->path_for->{path}, '/foo/testedit', 'right path'; - is $m->endpoint->suggested_method, 'GET', 'right method'; + is $m->path_for->{path}, '/foo/testedit', 'right path'; + is $m->endpoint->suggested_method, 'GET', 'right method'; }; subtest 'Optional captures in sub route with requirement' => sub { @@ -514,7 +514,7 @@ subtest 'Named path_for' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/alternatives/test'}); is $m->path_for->{path}, '/alternatives/test', 'right path'; - is $m->path_for('test_edit', testcase => 'foo')->{path}, '/foo/test/edit', 'right path'; + is $m->path_for('test_edit', testcase => 'foo')->{path}, '/foo/test/edit', 'right path'; is $m->path_for('test_edit', {testcase => 'foo'})->{path}, '/foo/test/edit', 'right path'; }; @@ -523,8 +523,8 @@ subtest 'Wildcards' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/wildcards/1/hello/there'}); is_deeply $m->stack, [{testcase => 'wild', action => 'card', wildcard => 'hello/there'}], 'right structure'; - is $m->path_for->{path}, '/wildcards/1/hello/there', 'right path'; - is $m->path_for(wildcard => '')->{path}, '/wildcards/1/', 'right path'; + is $m->path_for->{path}, '/wildcards/1/hello/there', 'right path'; + is $m->path_for(wildcard => '')->{path}, '/wildcards/1/', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/wildcards/2/hello/there'}); is_deeply $m->stack, [{testcase => 'card', action => 'wild', wildcard => 'hello/there'}], 'right structure'; @@ -688,8 +688,8 @@ subtest 'Format inheritance' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/inherit/first.html'}); is_deeply $m->stack, [{controller => 'inherit', action => 'first', format => 'html'}], 'right structure'; - is $m->path_for->{path}, '/inherit/first.html', 'right path'; - is $m->path_for(format => undef)->{path}, '/inherit/first', 'right path'; + is $m->path_for->{path}, '/inherit/first.html', 'right path'; + is $m->path_for(format => undef)->{path}, '/inherit/first', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/inherit/first.json'}); is_deeply $m->stack, [{controller => 'inherit', action => 'first', format => 'json'}], 'right structure'; @@ -704,8 +704,8 @@ subtest 'Format inheritance' => sub { $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/inherit/second.html'}); is_deeply $m->stack, [{controller => 'inherit', action => 'second', format => 'html'}], 'right structure'; - is $m->path_for->{path}, '/inherit/second.html', 'right path'; - is $m->path_for(format => undef)->{path}, '/inherit/second', 'right path'; + is $m->path_for->{path}, '/inherit/second.html', 'right path'; + is $m->path_for(format => undef)->{path}, '/inherit/second', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/inherit/second.json'}); is_deeply $m->stack, [{controller => 'inherit', action => 'second', format => 'json'}], 'right structure'; @@ -753,13 +753,13 @@ subtest 'Request methods' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/method/get.html'}); is_deeply $m->stack, [{testcase => 'method', action => 'get', format => 'html'}], 'right structure'; - is $m->path_for->{path}, '/method/get.html', 'right path'; - is $m->endpoint->suggested_method, 'GET', 'right method'; + is $m->path_for->{path}, '/method/get.html', 'right path'; + is $m->endpoint->suggested_method, 'GET', 'right method'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'POST', path => '/method/post'}); is_deeply $m->stack, [{testcase => 'method', action => 'post'}], 'right structure'; - is $m->path_for->{path}, '/method/post', 'right path'; - is $m->endpoint->suggested_method, 'POST', 'right method'; + is $m->path_for->{path}, '/method/post', 'right path'; + is $m->endpoint->suggested_method, 'POST', 'right method'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/method/post_get'}); is_deeply $m->stack, [{testcase => 'method', action => 'post_get'}], 'right structure'; @@ -767,8 +767,8 @@ subtest 'Request methods' => sub { $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'POST', path => '/method/post_get'}); is_deeply $m->stack, [{testcase => 'method', action => 'post_get'}], 'right structure'; - is $m->path_for->{path}, '/method/post_get', 'right path'; - is $m->endpoint->suggested_method, 'GET', 'right method'; + is $m->path_for->{path}, '/method/post_get', 'right path'; + is $m->endpoint->suggested_method, 'GET', 'right method'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'DELETE', path => '/method/post_get'}); is_deeply $m->stack, [], 'empty stack'; @@ -788,7 +788,7 @@ subtest 'Simplified form' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/simple/form'}); is_deeply $m->stack, [{controller => 'test-test', action => 'test'}], 'right structure'; - is $m->path_for->{path}, '/simple/form', 'right path'; + is $m->path_for->{path}, '/simple/form', 'right path'; is $m->path_for('current')->{path}, '/simple/form', 'right path'; }; @@ -954,17 +954,17 @@ subtest 'Nameless placeholder' => sub { my $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/missing/foo/name'}); is_deeply $m->stack, [{controller => 'missing', action => 'placeholder', '' => 'foo'}], 'right structure'; - is $m->path_for->{path}, '/missing/foo/name', 'right path'; + is $m->path_for->{path}, '/missing/foo/name', 'right path'; is $m->path_for('' => 'bar')->{path}, '/missing/bar/name', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/missing/foo/bar/name'}); is_deeply $m->stack, [{controller => 'missing', action => 'wildcard', '' => 'foo/bar'}], 'right structure'; - is $m->path_for->{path}, '/missing/foo/bar/name', 'right path'; + is $m->path_for->{path}, '/missing/foo/bar/name', 'right path'; is $m->path_for('' => 'bar/baz')->{path}, '/missing/bar/baz/name', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/missing/too/test'}); is_deeply $m->stack, [{controller => 'missing', action => 'too', '' => 'test'}], 'right structure'; - is $m->path_for->{path}, '/missing/too/test', 'right path'; + is $m->path_for->{path}, '/missing/too/test', 'right path'; is $m->path_for('' => 'bar/baz')->{path}, '/missing/too/bar/baz', 'right path'; $m = Mojolicious::Routes::Match->new(root => $r); $m->find($c => {method => 'GET', path => '/missing/too/tset'}); diff --git a/t/mojolicious/tls_lite_app.t b/t/mojolicious/tls_lite_app.t index b9bf1f98d9..01dd438867 100644 --- a/t/mojolicious/tls_lite_app.t +++ b/t/mojolicious/tls_lite_app.t @@ -76,7 +76,7 @@ app->sessions->default_expiration(0); # Login again $t->get_ok('/login?name=sri' => {'X-Forwarded-Proto' => 'https'})->status_is(200)->content_is('Welcome sri!'); ok !$t->tx->res->cookie('mojolicious')->expires, 'session cookie does not expire'; -ok $t->tx->res->cookie('mojolicious')->secure, 'session cookie is secure'; +ok $t->tx->res->cookie('mojolicious')->secure, 'session cookie is secure'; # Return $t->get_ok('/again' => {'X-Forwarded-Proto' => 'https'})->status_is(200)->content_is('Welcome back sri!'); diff --git a/t/mojolicious/twinkle_lite_app.t b/t/mojolicious/twinkle_lite_app.t index cb66ad0e59..73a8e47eda 100644 --- a/t/mojolicious/twinkle_lite_app.t +++ b/t/mojolicious/twinkle_lite_app.t @@ -42,9 +42,9 @@ subtest 'Configuration' => sub { template => {%$twinkle, append => '$app->defaults(foo_test => 24)', prepend => 'my $foo = app->defaults("foo_test");'} }; - is $config->{foo}, 'bar', 'right value'; - is $config->{test}, 23, 'right value'; - is app->defaults('foo_test'), 24, 'right value'; + is $config->{foo}, 'bar', 'right value'; + is $config->{test}, 23, 'right value'; + is app->defaults('foo_test'), 24, 'right value'; }; get '/' => {name => ''} => 'index'; diff --git a/t/mojolicious/types.t b/t/mojolicious/types.t index 8d79ea96bb..5facc966b7 100644 --- a/t/mojolicious/types.t +++ b/t/mojolicious/types.t @@ -16,40 +16,40 @@ subtest 'Basic functionality' => sub { }; subtest 'Detect common MIME types' => sub { - is_deeply $t->detect('text/cache-manifest'), ['appcache'], 'right formats'; - is_deeply $t->detect('application/atom+xml'), ['atom'], 'right formats'; - is_deeply $t->detect('application/octet-stream'), ['bin'], 'right formats'; - is_deeply $t->detect('text/css'), ['css'], 'right formats'; - is_deeply $t->detect('image/gif'), ['gif'], 'right formats'; - is_deeply $t->detect('application/x-gzip'), ['gz'], 'right formats'; + is_deeply $t->detect('text/cache-manifest'), ['appcache'], 'right formats'; + is_deeply $t->detect('application/atom+xml'), ['atom'], 'right formats'; + is_deeply $t->detect('application/octet-stream'), ['bin'], 'right formats'; + is_deeply $t->detect('text/css'), ['css'], 'right formats'; + is_deeply $t->detect('image/gif'), ['gif'], 'right formats'; + is_deeply $t->detect('application/x-gzip'), ['gz'], 'right formats'; is_deeply $t->detect('text/html'), ['htm', 'html'], 'right formats'; - is_deeply $t->detect('image/x-icon'), ['ico'], 'right formats'; + is_deeply $t->detect('image/x-icon'), ['ico'], 'right formats'; is_deeply $t->detect('image/jpeg'), ['jpeg', 'jpg'], 'right formats'; - is_deeply $t->detect('application/javascript'), ['js'], 'right formats'; - is_deeply $t->detect('application/json'), ['json'], 'right formats'; - is_deeply $t->detect('audio/mpeg'), ['mp3'], 'right formats'; - is_deeply $t->detect('video/mp4'), ['mp4'], 'right formats'; - is_deeply $t->detect('audio/ogg'), ['ogg'], 'right formats'; - is_deeply $t->detect('video/ogg'), ['ogv'], 'right formats'; - is_deeply $t->detect('application/pdf'), ['pdf'], 'right formats'; - is_deeply $t->detect('image/png'), ['png'], 'right formats'; - is_deeply $t->detect('application/rss+xml'), ['rss'], 'right formats'; - is_deeply $t->detect('image/svg+xml'), ['svg'], 'right formats'; - is_deeply $t->detect('font/ttf'), ['ttf'], 'right formats'; - is_deeply $t->detect('text/plain'), ['txt'], 'right formats'; - is_deeply $t->detect('video/webm'), ['webm'], 'right formats'; - is_deeply $t->detect('font/woff'), ['woff'], 'right formats'; - is_deeply $t->detect('font/woff2'), ['woff2'], 'right formats'; - is_deeply $t->detect('application/xml'), ['xml'], 'right formats'; - is_deeply $t->detect('text/xml'), ['xml'], 'right formats'; - is_deeply $t->detect('application/zip'), ['zip'], 'right format'; + is_deeply $t->detect('application/javascript'), ['js'], 'right formats'; + is_deeply $t->detect('application/json'), ['json'], 'right formats'; + is_deeply $t->detect('audio/mpeg'), ['mp3'], 'right formats'; + is_deeply $t->detect('video/mp4'), ['mp4'], 'right formats'; + is_deeply $t->detect('audio/ogg'), ['ogg'], 'right formats'; + is_deeply $t->detect('video/ogg'), ['ogv'], 'right formats'; + is_deeply $t->detect('application/pdf'), ['pdf'], 'right formats'; + is_deeply $t->detect('image/png'), ['png'], 'right formats'; + is_deeply $t->detect('application/rss+xml'), ['rss'], 'right formats'; + is_deeply $t->detect('image/svg+xml'), ['svg'], 'right formats'; + is_deeply $t->detect('font/ttf'), ['ttf'], 'right formats'; + is_deeply $t->detect('text/plain'), ['txt'], 'right formats'; + is_deeply $t->detect('video/webm'), ['webm'], 'right formats'; + is_deeply $t->detect('font/woff'), ['woff'], 'right formats'; + is_deeply $t->detect('font/woff2'), ['woff2'], 'right formats'; + is_deeply $t->detect('application/xml'), ['xml'], 'right formats'; + is_deeply $t->detect('text/xml'), ['xml'], 'right formats'; + is_deeply $t->detect('application/zip'), ['zip'], 'right format'; }; subtest 'Detect special cases' => sub { - is_deeply $t->detect('Application/Xml'), ['xml'], 'right formats'; - is_deeply $t->detect(' Text/Xml '), ['xml'], 'right formats'; - is_deeply $t->detect('APPLICATION/XML'), ['xml'], 'right formats'; - is_deeply $t->detect('TEXT/XML'), ['xml'], 'right formats'; + is_deeply $t->detect('Application/Xml'), ['xml'], 'right formats'; + is_deeply $t->detect(' Text/Xml '), ['xml'], 'right formats'; + is_deeply $t->detect('APPLICATION/XML'), ['xml'], 'right formats'; + is_deeply $t->detect('TEXT/XML'), ['xml'], 'right formats'; is_deeply $t->detect('text/html;q=0.9'), ['htm', 'html'], 'right formats'; is_deeply $t->detect('TEXT/HTML;Q=0.9'), ['htm', 'html'], 'right formats'; }; @@ -59,27 +59,27 @@ subtest 'Alternatives' => sub { is $t->mapping->{json}[0], 'application/json', 'right type'; is $t->mapping->{json}[1], 'text/x-json', 'right type'; ok !$t->mapping->{json}[2], 'no type'; - is_deeply $t->mapping->{htm}, ['text/html'], 'right type'; - is_deeply $t->mapping->{html}, ['text/html;charset=UTF-8'], 'right type'; - is_deeply $t->detect('application/json'), ['json'], 'right formats'; - is_deeply $t->detect('text/x-json'), ['json'], 'right formats'; - is_deeply $t->detect('TEXT/X-JSON;q=0.1'), ['json'], 'right formats'; - is_deeply $t->detect('APPLICATION/JsoN'), ['json'], 'right formats'; - is_deeply $t->detect('text/html'), ['htm', 'html'], 'right formats'; - is $t->type('json'), 'application/json', 'right type'; - is $t->type('htm'), 'text/html', 'right type'; - is $t->type('html'), 'text/html;charset=UTF-8', 'right type'; + is_deeply $t->mapping->{htm}, ['text/html'], 'right type'; + is_deeply $t->mapping->{html}, ['text/html;charset=UTF-8'], 'right type'; + is_deeply $t->detect('application/json'), ['json'], 'right formats'; + is_deeply $t->detect('text/x-json'), ['json'], 'right formats'; + is_deeply $t->detect('TEXT/X-JSON;q=0.1'), ['json'], 'right formats'; + is_deeply $t->detect('APPLICATION/JsoN'), ['json'], 'right formats'; + is_deeply $t->detect('text/html'), ['htm', 'html'], 'right formats'; + is $t->type('json'), 'application/json', 'right type'; + is $t->type('htm'), 'text/html', 'right type'; + is $t->type('html'), 'text/html;charset=UTF-8', 'right type'; }; subtest 'Prioritize' => sub { - is_deeply $t->detect('text/plain'), ['txt'], 'right formats'; + is_deeply $t->detect('text/plain'), ['txt'], 'right formats'; is_deeply $t->detect('text/plain,text/html'), ['htm', 'html', 'txt'], 'right formats'; - is_deeply $t->detect('TEXT/HTML; q=0.8 '), ['htm', 'html'], 'right formats'; - is_deeply $t->detect('TEXT/HTML ; q = 0.8 '), ['htm', 'html'], 'right formats'; + is_deeply $t->detect('TEXT/HTML; q=0.8 '), ['htm', 'html'], 'right formats'; + is_deeply $t->detect('TEXT/HTML ; q = 0.8 '), ['htm', 'html'], 'right formats'; is_deeply $t->detect('TEXT/HTML;Q=0.8,text/plain;Q=0.9'), ['txt', 'htm', 'html'], 'right formats'; is_deeply $t->detect(' TEXT/HTML , text/plain;Q=0.9'), ['htm', 'html', 'txt'], 'right formats'; is_deeply $t->detect('text/plain;q=0.5, text/xml, application/xml;q=0.1'), ['xml', 'txt', 'xml'], 'right formats'; - is_deeply $t->detect('application/json, text/javascript, */*; q=0.01'), ['json'], 'right formats'; + is_deeply $t->detect('application/json, text/javascript, */*; q=0.01'), ['json'], 'right formats'; }; subtest 'File types' => sub { diff --git a/t/mojolicious/validation_lite_app.t b/t/mojolicious/validation_lite_app.t index 52ae526674..47462a79cf 100644 --- a/t/mojolicious/validation_lite_app.t +++ b/t/mojolicious/validation_lite_app.t @@ -47,20 +47,20 @@ subtest 'Required and optional values' => sub { is_deeply $v->every_param('foo'), [], 'no values'; ok $v->required('foo')->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; - is $v->param, 'bar', 'right value'; + is $v->param, 'bar', 'right value'; is $v->param('foo'), 'bar', 'right value'; - is_deeply $v->every_param, ['bar'], 'right values'; + is_deeply $v->every_param, ['bar'], 'right values'; is_deeply $v->every_param('foo'), ['bar'], 'right values'; - is_deeply $v->passed, ['foo'], 'right names'; - ok !$v->has_error, 'no error'; + is_deeply $v->passed, ['foo'], 'right names'; + ok !$v->has_error, 'no error'; ok $v->optional('baz')->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar', baz => 'yada'}, 'right result'; is $v->param('baz'), 'yada', 'right value'; is_deeply $v->passed, [qw(baz foo)], 'right names'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->optional('does_not_exist')->is_valid, 'not valid'; is_deeply $v->output, {foo => 'bar', baz => 'yada'}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->required('does_not_exist')->is_valid, 'not valid'; is_deeply $v->output, {foo => 'bar', baz => 'yada'}, 'right result'; ok $v->has_error, 'has error'; @@ -68,13 +68,13 @@ subtest 'Required and optional values' => sub { $v = $t->app->validation->input({foo => [], bar => ['a'], baz => undef, yada => [undef]}); ok !$v->optional('foo')->is_valid, 'not valid'; is_deeply $v->output, {}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->optional('baz')->is_valid, 'not valid'; is_deeply $v->output, {}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->optional('yada')->is_valid, 'not valid'; is_deeply $v->output, {}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok $v->optional('bar')->is_valid, 'valid'; is_deeply $v->output, {bar => 'a'}, 'right result'; ok !$v->in('c')->is_valid, 'not valid'; @@ -92,7 +92,7 @@ subtest 'Equal to' => sub { my $v = $t->app->validation->input({foo => 'bar', baz => 'bar', yada => 'yada'}); ok $v->optional('foo')->equal_to('baz')->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->optional('baz')->equal_to('does_not_exist')->is_valid, 'not valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; ok $v->has_error, 'has error'; @@ -101,7 +101,7 @@ subtest 'Equal to' => sub { is_deeply $v->output, {foo => 'bar'}, 'right result'; ok $v->has_error, 'has error'; is_deeply $v->error('yada'), [qw(equal_to 1 foo)], 'right error'; - is_deeply $v->failed, [qw(baz yada)], 'right names'; + is_deeply $v->failed, [qw(baz yada)], 'right names'; }; subtest 'In' => sub { @@ -110,12 +110,12 @@ subtest 'In' => sub { is_deeply $v->every_param('foo'), [qw(bar whatever)], 'right results'; is $v->param('foo'), 'whatever', 'right result'; is_deeply $v->output, {foo => [qw(bar whatever)]}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->required('baz')->in(qw(yada whatever))->is_valid, 'not valid'; is_deeply $v->output, {foo => [qw(bar whatever)]}, 'right result'; ok $v->has_error, 'has error'; is_deeply $v->error('baz'), [qw(in 1 yada whatever)], 'right error'; - is_deeply $v->failed, ['baz'], 'right names'; + is_deeply $v->failed, ['baz'], 'right names'; }; subtest 'Like' => sub { @@ -136,10 +136,10 @@ subtest 'Num' => sub { is_deeply $v->output, {foo => 23}, 'right result'; ok $v->required('bar')->num->is_valid, 'valid'; is_deeply $v->output, {foo => 23, bar => 0}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->required('baz')->num->is_valid, 'not valid'; is_deeply $v->error('baz'), [qw(num 1)], 'right error'; - is_deeply $v->failed, ['baz'], 'right names'; + is_deeply $v->failed, ['baz'], 'right names'; $v = $t->app->validation->input({foo => 23}); ok $v->required('foo')->num(22, 24)->is_valid, 'valid'; $v = $t->app->validation->input({foo => 23}); @@ -148,7 +148,7 @@ subtest 'Num' => sub { ok $v->required('foo')->num(22, 23)->is_valid, 'valid'; $v = $t->app->validation->input({foo => 23}); ok !$v->required('foo')->num(24, 25)->is_valid, 'not valid'; - ok $v->has_error, 'has error'; + ok $v->has_error, 'has error'; is_deeply $v->error('foo'), [qw(num 1 24 25)], 'right error'; $v = $t->app->validation->input({foo => 23}); ok $v->required('foo')->num(22, undef)->is_valid, 'valid'; @@ -156,7 +156,7 @@ subtest 'Num' => sub { ok $v->required('foo')->num(23, undef)->is_valid, 'valid'; $v = $t->app->validation->input({foo => 23}); ok !$v->required('foo')->num(24, undef)->is_valid, 'not valid'; - ok $v->has_error, 'has error'; + ok $v->has_error, 'has error'; is_deeply $v->error('foo'), ['num', 1, 24, undef], 'right error'; $v = $t->app->validation->input({foo => 23}); ok $v->required('foo')->num(undef, 24)->is_valid, 'valid'; @@ -164,7 +164,7 @@ subtest 'Num' => sub { ok $v->required('foo')->num(undef, 23)->is_valid, 'valid'; $v = $t->app->validation->input({foo => 23}); ok !$v->required('foo')->num(undef, 22)->is_valid, 'not valid'; - ok $v->has_error, 'has error'; + ok $v->has_error, 'has error'; is_deeply $v->error('foo'), ['num', 1, undef, 22], 'right error'; $v = $t->app->validation->input({foo => -5}); ok $v->required('foo')->num->is_valid, 'valid'; @@ -177,7 +177,7 @@ subtest 'Size' => sub { my $v = $t->app->validation->input({foo => 'bar', baz => 'yada', yada => 'yada'}); ok $v->required('foo')->size(1, 3)->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok !$v->required('baz')->size(1, 3)->is_valid, 'not valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; ok $v->has_error, 'has error'; @@ -203,12 +203,12 @@ subtest 'Upload' => sub { }); ok $v->required('foo')->upload->is_valid, 'valid'; ok $v->required('bar')->upload->is_valid, 'valid'; - ok $v->required('baz')->is_valid, 'valid'; - ok !$v->has_error, 'no error'; - ok !$v->upload->is_valid, 'not valid'; - ok $v->has_error, 'has error'; + ok $v->required('baz')->is_valid, 'valid'; + ok !$v->has_error, 'no error'; + ok !$v->upload->is_valid, 'not valid'; + ok $v->has_error, 'has error'; is_deeply $v->error('baz'), [qw(upload 1)], 'right error'; - is_deeply $v->failed, ['baz'], 'right names'; + is_deeply $v->failed, ['baz'], 'right names'; }; subtest 'Upload size' => sub { @@ -216,20 +216,20 @@ subtest 'Upload size' => sub { foo => [Mojo::Upload->new(asset => Mojo::Asset::Memory->new->add_chunk('valid'))], bar => [Mojo::Upload->new(asset => Mojo::Asset::Memory->new->add_chunk('not valid'))] }); - ok $v->required('foo')->upload->size(1, 6)->is_valid, 'valid'; - ok !$v->has_error, 'no error'; + ok $v->required('foo')->upload->size(1, 6)->is_valid, 'valid'; + ok !$v->has_error, 'no error'; ok !$v->required('bar')->upload->size(1, 6)->is_valid, 'not valid'; - ok $v->has_error, 'has error'; + ok $v->has_error, 'has error'; is_deeply $v->error('bar'), [qw(size 1 1 6)], 'right error'; - is_deeply $v->failed, ['bar'], 'right names'; + is_deeply $v->failed, ['bar'], 'right names'; }; subtest 'Trim' => sub { my $v = $t->app->validation->input({foo => ' bar', baz => [' 0 ', 1]}); ok $v->required('foo', 'trim')->in('bar')->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; - ok !$v->optional('missing', 'trim')->is_valid, 'not valid'; - ok $v->optional('baz', 'trim')->like(qr/^\d$/)->is_valid, 'valid'; + ok !$v->optional('missing', 'trim')->is_valid, 'not valid'; + ok $v->optional('baz', 'trim')->like(qr/^\d$/)->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar', baz => [0, 1]}, 'right result'; $v = $t->app->validation->input({nothing => ' ', more => [undef]}); @@ -243,14 +243,14 @@ subtest 'Trim' => sub { subtest 'Not empty' => sub { my $v = $t->app->validation->input({foo => 'bar', baz => ''}); - ok $v->required('foo', 'not_empty')->in('bar')->is_valid, 'valid'; - ok !$v->required('baz', 'not_empty')->is_valid, 'not valid'; + ok $v->required('foo', 'not_empty')->in('bar')->is_valid, 'valid'; + ok !$v->required('baz', 'not_empty')->is_valid, 'not valid'; ok $v->has_error, 'has error'; is_deeply $v->error('baz'), ['required'], 'right error'; is_deeply $v->output, {foo => 'bar'}, 'right result'; $v = $t->app->validation->input({foo => [' bar'], baz => ['', ' ', undef]}); - ok $v->optional('foo', 'trim', 'not_empty')->is_valid, 'valid'; + ok $v->optional('foo', 'trim', 'not_empty')->is_valid, 'valid'; ok !$v->optional('baz', 'trim', 'not_empty')->is_valid, 'not valid'; ok !$v->has_error, 'no error'; is_deeply $v->output, {foo => 'bar'}, 'right result'; @@ -283,8 +283,8 @@ subtest 'Multiple empty values' => sub { my $v = $t->app->validation; ok !$v->has_data, 'no data'; $v->input({foo => ['', 'bar', ''], bar => ['', 'baz', undef]}); - ok $v->has_data, 'has data'; - ok $v->required('foo')->is_valid, 'valid'; + ok $v->has_data, 'has data'; + ok $v->required('foo')->is_valid, 'valid'; ok !$v->required('bar')->is_valid, 'not valid'; is_deeply $v->output, {foo => ['', 'bar', '']}, 'right result'; ok $v->has_error, 'has error'; @@ -293,7 +293,7 @@ subtest 'Multiple empty values' => sub { subtest '0' => sub { my $v = $t->app->validation->input({0 => 0}); - ok $v->has_data, 'has data'; + ok $v->has_data, 'has data'; ok $v->required(0)->size(1, 1)->is_valid, 'valid'; is_deeply $v->output, {0 => 0}, 'right result'; is $v->param(0), 0, 'right value'; @@ -314,15 +314,15 @@ subtest 'CSRF protection' => sub { ok $v->has_error, 'has error'; is_deeply $v->error('csrf_token'), ['csrf_protect'], 'right error'; $v = $t->app->validation->input({csrf_token => 'abc'}); - ok $v->has_data, 'has data'; + ok $v->has_data, 'has data'; ok $v->csrf_protect->has_error, 'has error'; - ok $v->has_data, 'has data'; + ok $v->has_data, 'has data'; is_deeply $v->error('csrf_token'), ['csrf_protect'], 'right error'; $v = $t->app->validation->input({csrf_token => 'abc', foo => 'bar'})->csrf_token('cba')->csrf_protect; ok $v->has_error, 'has error'; is_deeply $v->error('csrf_token'), ['csrf_protect'], 'right error'; $v = $t->app->validation->input({csrf_token => 'abc', foo => 'bar'})->csrf_token('abc')->csrf_protect; - ok !$v->has_error, 'no error'; + ok !$v->has_error, 'no error'; ok $v->required('foo')->is_valid, 'valid'; is_deeply $v->output, {foo => 'bar'}, 'right result'; $v = $t->app->validation->input({csrf_token => ['abc', 'abc']})->csrf_token('abc')->csrf_protect; diff --git a/t/mojolicious/websocket_lite_app.t b/t/mojolicious/websocket_lite_app.t index 8323aca40e..06f8732fbe 100644 --- a/t/mojolicious/websocket_lite_app.t +++ b/t/mojolicious/websocket_lite_app.t @@ -247,14 +247,14 @@ subtest "Huge message that doesn't compress very well" => sub { subtest 'Protocol negotiation' => sub { $t->websocket_ok('/protocols' => ['bar'])->message_ok->message_is('bar')->message_ok->message_is('bar')->finish_ok; - is $t->tx->protocol, 'bar', 'right protocol'; + is $t->tx->protocol, 'bar', 'right protocol'; is $t->tx->res->headers->sec_websocket_protocol, 'bar', 'right "Sec-WebSocket-Protocol" value'; $t->websocket_ok('/protocols' => ['baz', 'bar', 'foo'])->message_ok->message_is('foo')->message_ok->message_is('foo') ->finish_ok; - is $t->tx->protocol, 'foo', 'right protocol'; + is $t->tx->protocol, 'foo', 'right protocol'; is $t->tx->res->headers->sec_websocket_protocol, 'foo', 'right "Sec-WebSocket-Protocol" value'; $t->websocket_ok('/protocols' => ['0'])->message_ok->message_is('0')->message_ok->message_is('0')->finish_ok; - is $t->tx->protocol, '0', 'right protocol'; + is $t->tx->protocol, '0', 'right protocol'; is $t->tx->res->headers->sec_websocket_protocol, '0', 'right "Sec-WebSocket-Protocol" value'; $t->websocket_ok('/protocols' => [''])->message_ok->message_is('none')->message_ok->message_is('none')->finish_ok; is $t->tx->protocol, undef, 'no protocol'; diff --git a/t/mojolicious/yaml_config_lite_app.t b/t/mojolicious/yaml_config_lite_app.t index cbf2b7af0f..9cdd83604c 100644 --- a/t/mojolicious/yaml_config_lite_app.t +++ b/t/mojolicious/yaml_config_lite_app.t @@ -27,11 +27,11 @@ subtest 'Load plugins' => sub { my $config = plugin NotYAMLConfig => {default => {foo => 'baz', hello => 'there'}}; my $path = curfile->sibling('yaml_config_lite_app_abs.yml'); plugin NotYAMLConfig => {file => $path}; - is $config->{foo}, 'barbaz', 'right value'; - is $config->{hello}, 'there', 'right value'; - is $config->{utf}, 'утф', 'right value'; - is $config->{absolute}, 'works too!!!', 'right value'; - is $config->{absolute_dev}, 'dev works too yaml_config_lite_app!!!', 'right value'; + is $config->{foo}, 'barbaz', 'right value'; + is $config->{hello}, 'there', 'right value'; + is $config->{utf}, 'утф', 'right value'; + is $config->{absolute}, 'works too!!!', 'right value'; + is $config->{absolute_dev}, 'dev works too yaml_config_lite_app!!!', 'right value'; is app->config->{foo}, 'barbaz', 'right value'; is app->config->{hello}, 'there', 'right value'; is app->config->{utf}, 'утф', 'right value'; @@ -43,8 +43,8 @@ subtest 'Load plugins' => sub { is app->config('absolute'), 'works too!!!', 'right value'; is app->config('absolute_dev'), 'dev works too yaml_config_lite_app!!!', 'right value'; is app->config('it'), 'works', 'right value'; - is app->deployment_helper, 'deployment plugins work!', 'right value'; - is app->another_helper, 'works too!', 'right value'; + is app->deployment_helper, 'deployment plugins work!', 'right value'; + is app->another_helper, 'works too!', 'right value'; }; get '/' => 'index'; @@ -55,8 +55,8 @@ $t->get_ok('/')->status_is(200)->content_is("barbazbarbaz\n"); subtest 'No config file, default only' => sub { my $config = plugin NotYAMLConfig => {file => 'nonexistent', default => {foo => 'qux'}}; - is $config->{foo}, 'qux', 'right value'; - is app->config->{foo}, 'qux', 'right value'; + is $config->{foo}, 'qux', 'right value'; + is app->config->{foo}, 'qux', 'right value'; is app->config('foo'), 'qux', 'right value'; is app->config('it'), 'works', 'right value'; }; @@ -71,9 +71,9 @@ subtest 'YAML::XS' => sub { plan skip_all => 'YAML::XS required!' unless eval "use YAML::XS; 1"; my $config = plugin NotYAMLConfig => {module => 'YAML::XS', ext => 'yaml', default => {foo => 'baz', hello => 'there'}}; - is $config->{foo}, 'yada', 'right value'; - is $config->{hello}, 'there', 'right value'; - is $config->{utf8}, 'утф', 'right value'; + is $config->{foo}, 'yada', 'right value'; + is $config->{hello}, 'there', 'right value'; + is $config->{utf8}, 'утф', 'right value'; is app->config->{foo}, 'yada', 'right value'; is app->config->{hello}, 'there', 'right value'; is app->config->{utf8}, 'утф', 'right value';