foo
[gitmo/Moose-Autobox.git] / t / 003_p6_example.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7
8 BEGIN {
9     use_ok('Moose::Autobox');
10 }
11
12 use autobox;
13
14 SCALAR->meta->add_method('bytes' => sub {
15  $_[0];
16 });
17
18 SCALAR->meta->add_method('byte' => SCALAR->meta->get_method('bytes'));
19
20 SCALAR->meta->add_method('kilobytes' => sub {
21     $_[0] * 1024;
22 });
23
24 SCALAR->meta->add_method('kilobyte' => SCALAR->meta->get_method('kilobytes'));
25
26 SCALAR->meta->add_method('megabytes' => sub {
27     $_[0] * 1024->kilobytes;
28 });
29
30 SCALAR->meta->add_method('metabyte' => SCALAR->meta->get_method('megabytes'));
31
32 SCALAR->meta->add_method('gigabytes' => sub {
33     $_[0] * 1024->megabytes;
34 });
35
36 SCALAR->meta->add_method('gigabyte' => SCALAR->meta->get_method('gigabytes'));
37
38 SCALAR->meta->add_method('terabytes' => sub {
39     $_[0] * 1024->gigabytes;
40 });
41
42 SCALAR->meta->add_method('terabyte' => SCALAR->meta->get_method('terabytes'));
43
44 is(5->bytes,     5,             '... got 5 bytes');
45 is(5->kilobytes, 5120,          '... got 5 kilobytes');
46 is(2->megabytes, 2097152,       '... got 2 megabytes');
47 is(1->gigabyte,  1073741824,    '... got 1 gigabyte');
48 is(2->terabytes, 2199023255552, '... got 2 terabyte');
49