File: 02_main.t

package info (click to toggle)
libtime-tiny-perl 1.08-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 269; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,607 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl

# Main testing for Time::Tiny

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 15;
use Time::Tiny ();





#####################################################################
# Basic test

SCOPE: {
	my $tiny = Time::Tiny->new(
		hour   => 1,
		minute => 2,
		second => 3,
	);
	isa_ok( $tiny, 'Time::Tiny' );
	is( $tiny->hour,  '1', '->hour ok'   );
	is( $tiny->minute, 2,  '->minute ok' );
	is( $tiny->second, 3,  '->second ok' );
	is( $tiny->as_string, '01:02:03', '->as_string ok' );
	is( "$tiny", '01:02:03', 'Stringification ok' );
	is_deeply(
		Time::Tiny->from_string( $tiny->as_string ),
		$tiny, '->from_string ok',
	);

	my $now = Time::Tiny->now;
	isa_ok( $now, 'Time::Tiny' );
}





#####################################################################
# DateTime Testing

SKIP: {
	# Do we have DateTime
	eval { require DateTime };
	skip( "Skipping DateTime tests (not installed)", 7 ) if $@;

	# Create a normal date
	my $date = Time::Tiny->new(
		hour   => 1,
		minute => 2,
		second => 3,
	);
	isa_ok( $date, 'Time::Tiny' );

	# Expand to a DateTime
	my $dt = $date->DateTime;
	isa_ok( $dt, 'DateTime' );
	# DateTime::Locale version 1.00 changes "C" to "en-US-POSIX".
	my $expected = eval { DateTime::Locale->VERSION(1) } ? "en-US-POSIX" : "C";
	is( $dt->locale->id,      $expected,  '->locale ok'   );
	is( $dt->time_zone->name, 'floating', '->timezone ok' );

	# Compare accessor results
	is( $date->hour,   $dt->hour,   '->year matches'  );
	is( $date->minute, $dt->minute, '->month matches' );
	is( $date->second, $dt->second, '->day matches'   );
}