-
Notifications
You must be signed in to change notification settings - Fork 135
/
instants-and-durations.t
40 lines (29 loc) · 1.06 KB
/
instants-and-durations.t
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
use v6;
use Test;
plan 12;
# L<S02/Immutable types/'term now'>
{
my $i = now;
isa-ok $i, Instant, 'now returns an Instant';
isa-ok 5 + $i, Instant, 'Int + Instant ~~ Instant';
isa-ok $i - 1/3, Instant, 'Instant - Rat ~~ Instant';
}
isa-ok EVAL('now +300'), Instant, 'now is a term, not a function';
# L<S02/Immutable types/'you may not add two instants'>
{
my $t0 = Instant.from-posix(1295002122);
my $t1 = Instant.from-posix(1303059935);
my $d = $t1 - $t0;
ok $t0 < $t1, 'later Instants are greater';
throws-like { $t0 + $t1 },
X::Multi::Ambiguous,
'Instant + Instant is illegal';
isa-ok $d, Duration, 'Instant - Instant ~~ Duration';
ok $d ~~ Real, 'Durations are Real';
isa-ok $d + $t0, Instant, 'Instant + Duration ~~ Instant';
isa-ok $d + $t0, Instant, 'Duration + Instant ~~ Instant';
isa-ok $t0 - $d, Instant, 'Instant - Duration ~~ Instant';
is $t0 + ($t1 - $t0), $t1, 'Instant A + (Instant B - Instant A) == Instant B';
}
# See S32-temporal/DateTime-Instant-Duration.t for more.
# vim: ft=perl6