Make rindex work.
[gitmo/Moose-Autobox.git] / t / 005_string.t
CommitLineData
6cf5bcf2 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
dae37220 6use Test::More tests => 18;
6cf5bcf2 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose::Autobox');
11}
12
7dad2765 13use Moose::Autobox;
6cf5bcf2 14
15is('Hello World'->lc, 'hello world', '... $str->lc');
16is('Hello World'->uc, 'HELLO WORLD', '... $str->uc');
17
18is('foo'->ucfirst, 'Foo', '... $str->ucfirst');
19is('Foo'->lcfirst, 'foo', '... $str->lcfirst');
20
21dies_ok { ('Hello')->chop } '... cannot modify a read-only';
22{
23 my $greeting = 'Hello';
24 is($greeting->chop, 'o', '... got the chopped off portion of the string');
25 is($greeting, 'Hell', '... and are left with the rest of the string');
26}
27
28dies_ok { "Hello\n"->chomp } '... cannot modify a read-only';
29{
30 my $greeting = "Hello\n";
31 is($greeting->chomp, '1', '... got the chopped off portion of the string');
32 is($greeting, 'Hello', '... and are left with the rest of the string');
33}
34
35is('reverse'->reverse, 'esrever', '... got the string reversal');
36is('length'->length, 6, '... got the string length');
37
38is('Hello World'->index('World'), 6, '... got the correct index');
39
40is('Hello World, Hello'->index('Hello'), 0, '... got the correct index');
41
260cc81f 42is('Hello World, Hello'->index('Hello', 6), 13, '... got the correct index');
43
dae37220 44is('Hello World, Hello'->rindex('Hello'), 13, '... got the correct right index');
45
46is('Hello World, Hello'->rindex('Hello', 6), 0, '... got the correct right index');
47