Skip to content

Commit

Permalink
Merge pull request #1878 from mojolicious/tidy
Browse files Browse the repository at this point in the history
use the new perltidy
  • Loading branch information
mergify[bot] authored Nov 11, 2021
2 parents dbcd24b + 7d13a5b commit 4e8cff6
Show file tree
Hide file tree
Showing 66 changed files with 3,279 additions and 3,279 deletions.
120 changes: 60 additions & 60 deletions t/mojo/asset.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
};
Expand All @@ -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"';
};
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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';
};

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -190,29 +190,29 @@ 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 {
my $asset = Mojo::Asset::Memory->new(max_memory_size => 5, auto_upgrade => 1);
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';
ok $asset->is_file, 'stored in file';
$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');
Expand All @@ -232,17 +232,17 @@ 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 {
local $ENV{MOJO_TMPDIR} = my $tmpdir = tempdir;
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 {
Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions t/mojo/base.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};

Expand All @@ -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 {
Expand Down Expand Up @@ -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';
};
Expand Down
18 changes: 9 additions & 9 deletions t/mojo/bytestream.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/cache.t
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 4e8cff6

Please sign in to comment.