From 7e0432d6af889d0343f129dec7060ae0c782d2bc Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 10 Jun 2016 15:59:20 +0100 Subject: move Test2::* tests to subdir --- t/tests/compare-bag.t | 146 ------------------------------------------- t/tests/morecompare.t | 74 ---------------------- t/tests/test2/compare-bag.t | 147 ++++++++++++++++++++++++++++++++++++++++++++ t/tests/test2/morecompare.t | 75 ++++++++++++++++++++++ 4 files changed, 222 insertions(+), 220 deletions(-) delete mode 100644 t/tests/compare-bag.t delete mode 100644 t/tests/morecompare.t create mode 100644 t/tests/test2/compare-bag.t create mode 100644 t/tests/test2/morecompare.t (limited to 't') diff --git a/t/tests/compare-bag.t b/t/tests/compare-bag.t deleted file mode 100644 index 7c71639..0000000 --- a/t/tests/compare-bag.t +++ /dev/null @@ -1,146 +0,0 @@ -#!perl -use strict; -use warnings; -use 5.020; -use Test2::Bundle::Extended -target => 'Test2::Compare::Bag'; - -isa_ok($CLASS, 'Test2::Compare::Base'); -is($CLASS->name, '', "got name"); - -subtest construction => sub { - my $one = $CLASS->new(); - isa_ok($one, $CLASS); - is($one->items, [], "created items as an array"); -}; - -subtest verify => sub { - my $one = $CLASS->new; - - is($one->verify(exists => 0), 0, "did not get anything"); - is($one->verify(exists => 1, got => undef), 0, "undef is not an array"); - is($one->verify(exists => 1, got => 0), 0, "0 is not an array"); - is($one->verify(exists => 1, got => 1), 0, "1 is not an array"); - is($one->verify(exists => 1, got => 'string'), 0, "'string' is not an array"); - is($one->verify(exists => 1, got => {}), 0, "a hash is not an array"); - is($one->verify(exists => 1, got => []), 1, "an array is an array"); -}; - -subtest add_item => sub { - my $one = $CLASS->new(); - - $one->add_item('a'); - $one->add_item(1 => 'b'); - $one->add_item(3 => 'd'); - - ok( - lives { $one->add_item(2 => 'c') }, - "Indexes are ignored", - ); - - $one->add_item(8 => 'x'); - $one->add_item('y'); - - is( - $one->items, - [ 'a', 'b', 'd', 'c', 'x', 'y' ], - "Expected items", - ); -}; - -subtest deltas => sub { - my $conv = Test2::Compare->can('strict_convert'); - - my %params = (exists => 1, convert => $conv, seen => {}); - - my $items = ['a', 'b']; - my $one = $CLASS->new(items => $items); - - like( - [$one->deltas(%params, got => ['a', 'b'])], - [], - "No delta, no diff" - ); - - like( - [$one->deltas(%params, got => ['b', 'a'])], - [], - "No delta, no diff, order is ignored" - ); - - like( - [$one->deltas(%params, got => ['a'])], - [ - { - dne => 'got', - id => [ARRAY => '*'], - got => undef,, - chk => {input => 'b'}, - children => [ - { - dne => DNE, - id => [ARRAY => 0], - got => 'a', - chk => {input => 'b'}, - }, - ], - } - ], - "Got the delta for the missing value" - ); - - like( - [$one->deltas(%params, got => ['a', 'a'])], - [ - { - dne => 'got', - id => [ARRAY => '*'], - got => undef, - chk => {input => 'b'}, - children => [ - { - dne => DNE, - id => [ARRAY => 0], - got => 'a', - chk => {input => 'b'}, - }, - { - dne => DNE, - id => [ARRAY => 1], - got => 'a', - chk => {input => 'b'}, - }, - ], - } - ], - "Got the delta for the incorrect value" - ); - - like( - [$one->deltas(%params, got => ['a', 'b', 'a', 'a'])], - [], - "No delta, not checking ending" - ); - - $one->set_ending(1); - like( - [$one->deltas(%params, got => ['a', 'b', 'a', 'x'])], - array { - item 0 => { - dne => 'check', - id => [ARRAY => 2], - got => 'a', - check => DNE, - }; - item 1 => { - dne => 'check', - id => [ARRAY => 3], - got => 'x', - check => DNE, - }; - end(), - }, - "Got 2 deltas for extra items" - ); -}; - -done_testing; diff --git a/t/tests/morecompare.t b/t/tests/morecompare.t deleted file mode 100644 index 1755fa9..0000000 --- a/t/tests/morecompare.t +++ /dev/null @@ -1,74 +0,0 @@ -#!perl -use strict; -use warnings; -use 5.020; -use Test2::Bundle::Extended; -use Test2::Tools::MoreCompare qw(bag call_list); -use Test2::API qw(intercept); - -subtest simple => sub { - imported_ok qw{bag call_list}; -}; - -subtest bag => sub { - my $empty = bag { }; - - my $simple = bag { - item 'a'; - item 'b'; - item 'c'; - }; - - my $closed = array { - item 0 => 'a'; - item 1 => 'b'; - item 2 => 'c'; - end; - }; - - is([], $empty, "empty array"); - is(['a'], $empty, "any array matches empty"); - - is([qw/a b c/], $simple, "simple exact match"); - is([qw/b c a/], $simple, "simple out of order"); - is([qw/a b c d e/], $simple, "simple with extra"); - is([qw/b a d e c/], $simple, "simple with extra, out of order"); - - is([qw/a b c/], $closed, "closed array"); - - my $events = intercept { - is({}, $empty); - is(undef, $empty); - is(1, $empty); - is('ARRAY', $empty); - - is([qw/x y z/], $simple); - is([qw/a b x/], $simple); - is([qw/x b c/], $simple); - - is([qw/a b c d/], $closed); - }; - - @$events = grep {$_->isa('Test2::Event::Ok')} @$events; - is(@$events, 8, "8 events"); - is($_->pass, 0, "event failed") for @$events; -}; - -subtest call_list => sub { - my $obj = mock 'My::Class' => ( - add => [ - many => sub { return (1,2,3) }, - one => sub { 4 }, - ], - ); - - my $calls = object { - call one => 4; - call_list many => [1,2,3]; - call_list one => [4]; - }; - - is(bless({},'My::Class'), $calls, 'call_list matches'); -}; - -done_testing; diff --git a/t/tests/test2/compare-bag.t b/t/tests/test2/compare-bag.t new file mode 100644 index 0000000..80a7bc3 --- /dev/null +++ b/t/tests/test2/compare-bag.t @@ -0,0 +1,147 @@ +#!perl +use strict; +use warnings; +use 5.020; +use lib 't/lib'; +use Test2::Bundle::Extended -target => 'Test2::Compare::Bag'; + +isa_ok($CLASS, 'Test2::Compare::Base'); +is($CLASS->name, '', "got name"); + +subtest construction => sub { + my $one = $CLASS->new(); + isa_ok($one, $CLASS); + is($one->items, [], "created items as an array"); +}; + +subtest verify => sub { + my $one = $CLASS->new; + + is($one->verify(exists => 0), 0, "did not get anything"); + is($one->verify(exists => 1, got => undef), 0, "undef is not an array"); + is($one->verify(exists => 1, got => 0), 0, "0 is not an array"); + is($one->verify(exists => 1, got => 1), 0, "1 is not an array"); + is($one->verify(exists => 1, got => 'string'), 0, "'string' is not an array"); + is($one->verify(exists => 1, got => {}), 0, "a hash is not an array"); + is($one->verify(exists => 1, got => []), 1, "an array is an array"); +}; + +subtest add_item => sub { + my $one = $CLASS->new(); + + $one->add_item('a'); + $one->add_item(1 => 'b'); + $one->add_item(3 => 'd'); + + ok( + lives { $one->add_item(2 => 'c') }, + "Indexes are ignored", + ); + + $one->add_item(8 => 'x'); + $one->add_item('y'); + + is( + $one->items, + [ 'a', 'b', 'd', 'c', 'x', 'y' ], + "Expected items", + ); +}; + +subtest deltas => sub { + my $conv = Test2::Compare->can('strict_convert'); + + my %params = (exists => 1, convert => $conv, seen => {}); + + my $items = ['a', 'b']; + my $one = $CLASS->new(items => $items); + + like( + [$one->deltas(%params, got => ['a', 'b'])], + [], + "No delta, no diff" + ); + + like( + [$one->deltas(%params, got => ['b', 'a'])], + [], + "No delta, no diff, order is ignored" + ); + + like( + [$one->deltas(%params, got => ['a'])], + [ + { + dne => 'got', + id => [ARRAY => '*'], + got => undef,, + chk => {input => 'b'}, + children => [ + { + dne => DNE, + id => [ARRAY => 0], + got => 'a', + chk => {input => 'b'}, + }, + ], + } + ], + "Got the delta for the missing value" + ); + + like( + [$one->deltas(%params, got => ['a', 'a'])], + [ + { + dne => 'got', + id => [ARRAY => '*'], + got => undef, + chk => {input => 'b'}, + children => [ + { + dne => DNE, + id => [ARRAY => 0], + got => 'a', + chk => {input => 'b'}, + }, + { + dne => DNE, + id => [ARRAY => 1], + got => 'a', + chk => {input => 'b'}, + }, + ], + } + ], + "Got the delta for the incorrect value" + ); + + like( + [$one->deltas(%params, got => ['a', 'b', 'a', 'a'])], + [], + "No delta, not checking ending" + ); + + $one->set_ending(1); + like( + [$one->deltas(%params, got => ['a', 'b', 'a', 'x'])], + array { + item 0 => { + dne => 'check', + id => [ARRAY => 2], + got => 'a', + check => DNE, + }; + item 1 => { + dne => 'check', + id => [ARRAY => 3], + got => 'x', + check => DNE, + }; + end(), + }, + "Got 2 deltas for extra items" + ); +}; + +done_testing; diff --git a/t/tests/test2/morecompare.t b/t/tests/test2/morecompare.t new file mode 100644 index 0000000..ea85a18 --- /dev/null +++ b/t/tests/test2/morecompare.t @@ -0,0 +1,75 @@ +#!perl +use strict; +use warnings; +use 5.020; +use Test2::Bundle::Extended; +use lib 't/lib'; +use Test2::Tools::MoreCompare qw(bag call_list); +use Test2::API qw(intercept); + +subtest simple => sub { + imported_ok qw{bag call_list}; +}; + +subtest bag => sub { + my $empty = bag { }; + + my $simple = bag { + item 'a'; + item 'b'; + item 'c'; + }; + + my $closed = array { + item 0 => 'a'; + item 1 => 'b'; + item 2 => 'c'; + end; + }; + + is([], $empty, "empty array"); + is(['a'], $empty, "any array matches empty"); + + is([qw/a b c/], $simple, "simple exact match"); + is([qw/b c a/], $simple, "simple out of order"); + is([qw/a b c d e/], $simple, "simple with extra"); + is([qw/b a d e c/], $simple, "simple with extra, out of order"); + + is([qw/a b c/], $closed, "closed array"); + + my $events = intercept { + is({}, $empty); + is(undef, $empty); + is(1, $empty); + is('ARRAY', $empty); + + is([qw/x y z/], $simple); + is([qw/a b x/], $simple); + is([qw/x b c/], $simple); + + is([qw/a b c d/], $closed); + }; + + @$events = grep {$_->isa('Test2::Event::Ok')} @$events; + is(@$events, 8, "8 events"); + is($_->pass, 0, "event failed") for @$events; +}; + +subtest call_list => sub { + my $obj = mock 'My::Class' => ( + add => [ + many => sub { return (1,2,3) }, + one => sub { 4 }, + ], + ); + + my $calls = object { + call one => 4; + call_list many => [1,2,3]; + call_list one => [4]; + }; + + is(bless({},'My::Class'), $calls, 'call_list matches'); +}; + +done_testing; -- cgit v1.2.3