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