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