| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use sigtrap qw(die normal-signals error-signals); |
| 6 |
|
| 7 |
use Config; |
| 8 |
use Test::More tests => 8; |
| 9 |
|
| 10 |
use POSIX::2008; |
| 11 |
|
| 12 |
SKIP: { |
| 13 |
if (! defined &POSIX::2008::strptime) { |
| 14 |
skip 'strptime() UNAVAILABLE', 8; |
| 15 |
} |
| 16 |
|
| 17 |
my $ts = '2037-04-30 12:34:56'; |
| 18 |
my $fmt = '%Y-%m-%d %H:%M:%S'; |
| 19 |
my $lts = length $ts; |
| 20 |
my $expected = [56, 34, 12, 30, 3, 137]; |
| 21 |
|
| 22 |
{ |
| 23 |
my $ts = 'foobar'; |
| 24 |
my $rv = POSIX::2008::strptime($ts, $fmt); |
| 25 |
is($rv, undef, "strptime($ts, $fmt) is undef"); |
| 26 |
} |
| 27 |
|
| 28 |
{ |
| 29 |
my $n = POSIX::2008::strptime($ts, $fmt); |
| 30 |
cmp_ok($n, '==', $lts, "strptime($ts, $fmt) == $lts"); |
| 31 |
} |
| 32 |
|
| 33 |
{ |
| 34 |
my @tm_arg; |
| 35 |
my $n = POSIX::2008::strptime($ts, $fmt, \@tm_arg); |
| 36 |
cmp_ok($n, '==', $lts, "strptime($ts, $fmt, \@tm_arg) == $lts"); |
| 37 |
splice @tm_arg, scalar @$expected; |
| 38 |
is_deeply(\@tm_arg, $expected, |
| 39 |
"strptime($ts, $fmt, \@tm_arg) == $lts: check \@tm_arg"); |
| 40 |
} |
| 41 |
|
| 42 |
{ |
| 43 |
my @tm_ret = POSIX::2008::strptime($ts, $fmt); |
| 44 |
splice @tm_ret, scalar @$expected; |
| 45 |
is_deeply(\@tm_ret, $expected, "\@tm_ret = strptime($ts, $fmt)"); |
| 46 |
} |
| 47 |
|
| 48 |
{ |
| 49 |
my @tm_arg; |
| 50 |
POSIX::2008::strptime($ts, $fmt, \@tm_arg); |
| 51 |
splice @tm_arg, scalar @$expected; |
| 52 |
is_deeply(\@tm_arg, $expected, "strptime($ts, $fmt, \@tm_arg)"); |
| 53 |
} |
| 54 |
|
| 55 |
{ |
| 56 |
my @tm_arg; |
| 57 |
my @tm_ret = POSIX::2008::strptime($ts, $fmt, \@tm_arg); |
| 58 |
splice @tm_arg, scalar @$expected; |
| 59 |
splice @tm_ret, scalar @$expected; |
| 60 |
is_deeply(\@tm_ret, $expected, |
| 61 |
"\@tm_ret = strptime($ts, $fmt, \@tm_arg): check \@tm_ret"); |
| 62 |
is_deeply(\@tm_arg, $expected, |
| 63 |
"\@tm_ret = strptime($ts, $fmt, \@tm_arg): check \@tm_arg"); |
| 64 |
} |
| 65 |
} |