Test-More / test-more

Test2, Test::More, Test::Simple and Test::Builder Perl modules for writing tests
Other
140 stars 87 forks source link

FR: Provide a way to test arrays in reverse #947

Open FGasper opened 3 years ago

FGasper commented 3 years ago

It’d be nice if this could work:

> perl -MTest2::V0 -e'my @foo = (1, 2); is( \@foo, array { item -1 => 2 } )'
# Seeded srand with seed '20210224' from local date.
not ok 1
# Failed test at -e line 1.
# +------+------------------+---------+------------------+------+
# | PATH | GOT              | OP      | CHECK            | LNs  |
# +------+------------------+---------+------------------+------+
# |      | ARRAY(0x1468438) |         | <ARRAY>          | 1, 1 |
# | [-1] | <UNDEF>          |         | 2                | 1    |
# | [0]  | 1                | !exists | <DOES NOT EXIST> |      |
# | [1]  | 2                | !exists | <DOES NOT EXIST> |      |
# +------+------------------+---------+------------------+------+
# Tests were run but no plan was declared and done_testing() was not seen.

Alternatively I guess the thing tested could just be [reverse @$thearray].

rabbiveesh commented 3 years ago

You can use filter_items to modify the array you're testing. So what you're looking for is

filter_items { reverse @_ }

On Thu, Feb 25, 2021, 02:20 Felipe Gasper notifications@github.com wrote:

It’d be nice if this could work:

perl -MTest2::V0 -e'my @foo = (1, 2); is( \@foo, array { item -1 => 2 } )'

Seeded srand with seed '20210224' from local date.

not ok 1

Failed test at -e line 1.

+------+------------------+---------+------------------+------+

| PATH | GOT | OP | CHECK | LNs |

+------+------------------+---------+------------------+------+

| | ARRAY(0x1468438) | | | 1, 1 |

| [-1] | | | 2 | 1 |

| [0] | 1 | !exists | | |

| [1] | 2 | !exists | | |

+------+------------------+---------+------------------+------+

Tests were run but no plan was declared and done_testing() was not seen.

Alternatively I guess the thing tested could just be [reverse @$thearray].

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Test-More/test-more/issues/947, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFURPKTVINHSDRKCBT7MLZLTAWJWDANCNFSM4YFP7KVQ .