use_ok stinks; just load the library
[gitmo/Moose-Autobox.git] / t / 005_string.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 22;
7 use Test::Exception;
8
9 use Moose::Autobox;
10
11 my $VAR1; # for eval of dumps
12
13 is('Hello World'->lc, 'hello world', '... $str->lc');
14 is('Hello World'->uc, 'HELLO WORLD', '... $str->uc');
15
16 is('foo'->ucfirst, 'Foo', '... $str->ucfirst');
17 is('Foo'->lcfirst, 'foo', '... $str->lcfirst');
18
19 dies_ok { ('Hello')->chop } '... cannot modify a read-only';
20 {
21     my $greeting = 'Hello';
22     is($greeting->chop, 'o', '... got the chopped off portion of the string');
23     is($greeting, 'Hell', '... and are left with the rest of the string');
24 }
25
26 dies_ok { "Hello\n"->chomp } '... cannot modify a read-only';
27 {
28     my $greeting = "Hello\n";
29     is($greeting->chomp, '1', '... got the chopped off portion of the string');
30     is($greeting, 'Hello', '... and are left with the rest of the string');
31 }
32
33 is('reverse'->reverse, 'esrever', '... got the string reversal');
34 is('length'->length, 6, '... got the string length');
35
36 is('Hello World'->index('World'), 6, '... got the correct index');
37
38 is('Hello World, Hello'->index('Hello'), 0, '... got the correct index');
39
40 is('Hello World, Hello'->index('Hello', 6), 13, '... got the correct index');
41
42 is('Hello World, Hello'->rindex('Hello'), 13, '... got the correct right index');
43
44 is('Hello World, Hello'->rindex('Hello', 6), 0, '... got the correct right index');
45
46 is_deeply('/foo/bar/baz'->split('/'), ['', 'foo', 'bar', 'baz'], '... got the correct fragments');
47 is_deeply('Hello World'->words, ['Hello', 'World'], '... got the correct words');
48 is_deeply("Hello\nWor\n\nld\n"->lines, ['Hello', 'Wor', '', 'ld'], '... got the correct lines');
49
50 eval 'Hello World, Hello'->dump;
51 is($VAR1, 'Hello World, Hello' , '... eval of &dump works');
52
53 eval 'Hello World, Hello'->perl;
54 is($VAR1, 'Hello World, Hello' , '... eval of &perl works');
55