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", '
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, 'lalalala
bartest
test
', 'right result'; $dom = Mojo::DOM->new('lalala
barlalala
barlalala
barlalala
barlalala
barlalala
bar♥
')->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, '♥
')->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
whateverbar
', '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
whateverbar
', '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('ACDEFG
lalala
barbar
', 'right result'; - is "$dom", 'bar
barbar
', 'right result'; + is "$dom", 'bar
bartext
bar♥
lalala
barlalala
barlalala
barlalala
barlalala
barlalala
barlalala
barlalala
bartrololololo>\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 ?>
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
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, 'OneA1
23B
@@ -1389,7 +1389,7 @@ EOFA1
23B
@@ -1408,7 +1408,7 @@ EOF EOF $dom->at('li')->prepend_content('A3A2
')->prepend_content('A4'); is $dom->at('li')->text, 'A4A3A', 'right text'; - is "$dom", <A2
AA1
23B
@@ -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", <A2
AA1
23B
@@ -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 {