TEST2::COMPARE::ARRAY(3perl)
π Test2::Compare::Array π
okay so bestie, welcome to Test2::Compare::Array β it's the internal representation of an array comparison for the Test2 suite. Like, this is not the module you reach for directly, it's the backstage crew making your array checks happen. β¨
πΈ NAME πΈ
Test2::Compare::Array β the internal representation of an array comparison. yep that's it, that's the name, slay π
π¦ DESCRIPTION π¦
So this module is literally an internal representation of an array for comparison purposes. It's the little data structure that holds onto everything Test2 needs to know about how an array should look when it gets checked. Internal! Meaning it's doing its job behind the scenes while you live your main character life. π
β¨ METHODS β¨
okay here's where it gets juicy, gather round π«Ά
$ref = $arr->inref()β if this instance was built from an actual, real, flesh-and-blood array, this hands you back the reference to that array. no vibes, just the ref. π$bool = $arr->endingβ returns the current ending setting, and get this:$arr->set_ending($bool)β set this one to true if you want it to fail when the array being validated has more items than the check does. Like, picture it: you check indexes 0-3 but the array has values for indexes 0-4? Boom, it fails and lists that last item as unexpected. π If you set it to false, then the assumption is you simply do not care about extra items. live and let live, periodt.$hashref = $arr->items()β returns the hashref of"key => val"pairs that are gonna be checked in the array. π$arr->set_items($hashref)β accepts a hashref, which lets you skip indexes if that's the mood you're in.
ngl, there's no validation when you useset_items, so it's genuinely better to go through theadd_iteminterface instead. protect yourself bestie π
$arrayref = $arr->order()β gives you back an arrayref of all the indexes that will be checked, in order. organized queen. π$arr->set_order($arrayref)β sets the order in which indexes get checked.
same warning, fr fr: there's no validation when usingset_ordereither.add_itemis the safer route. π
$name = $arr->name()β always, always returns the string"<ARRAY>". it never changes its mind, it's loyal like that. π$bool = $arr->verify(got => $got, exists => $bool)β checks whether$gotis an array reference or not. that's the whole gig. π$idx = $arr->top_index()β returns the topmost index that's being checked. it'll give you backundefif there are, like, no items at all, or0if there's only 1 item. yes bestie, 1 item means index zero. math is math. β¨$arr->add_item($item)β pushes an item onto the list of values to be checked. simple, iconic. π$arr->add_item($idx => $item)β adds an item to the list of values to be checked at the specified index. now you're placing things precisely, we love precision. π$arr->add_filter(sub { ... })β adds a filter sub. here's how it works: the filter receives all remaining values of the array being checked, and it should return the values that should still be checked. and the timing? the filter runs between the last item added and the next item added. it's giving middle child energy and honestly? same. π@deltas = $arr->deltas(got => $got, convert => \&convert, seen => \%seen)β finds all the differences between the expected array values and the ones sitting in the$gotarrayref. this is the detective work. π
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. go star it or whatever, support the ecosystem bestie π«Ά
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>
π AUTHORS π
- Chad Granum
<exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's a wrap bestie π this whole vibe check came from perl v5.44.0, dated 2026-10-17, and it's the Test2::Compare::Array(3perl) page β no cap, every flag and every fact survived the glow-up, fr fr. bye queen πβ¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms