use_ok stinks; just load the library
[gitmo/Moose-Autobox.git] / t / 005_string.t
CommitLineData
6cf5bcf2 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
171cd606 6use Test::More tests => 22;
6cf5bcf2 7use Test::Exception;
8
7dad2765 9use Moose::Autobox;
6cf5bcf2 10
3f4dd8b7 11my $VAR1; # for eval of dumps
12
6cf5bcf2 13is('Hello World'->lc, 'hello world', '... $str->lc');
14is('Hello World'->uc, 'HELLO WORLD', '... $str->uc');
15
16is('foo'->ucfirst, 'Foo', '... $str->ucfirst');
17is('Foo'->lcfirst, 'foo', '... $str->lcfirst');
18
19dies_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
26dies_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
33is('reverse'->reverse, 'esrever', '... got the string reversal');
34is('length'->length, 6, '... got the string length');
35
36is('Hello World'->index('World'), 6, '... got the correct index');
37
38is('Hello World, Hello'->index('Hello'), 0, '... got the correct index');
39
260cc81f 40is('Hello World, Hello'->index('Hello', 6), 13, '... got the correct index');
41
dae37220 42is('Hello World, Hello'->rindex('Hello'), 13, '... got the correct right index');
43
44is('Hello World, Hello'->rindex('Hello', 6), 0, '... got the correct right index');
45
bf868259 46is_deeply('/foo/bar/baz'->split('/'), ['', 'foo', 'bar', 'baz'], '... got the correct fragments');
47is_deeply('Hello World'->words, ['Hello', 'World'], '... got the correct words');
48is_deeply("Hello\nWor\n\nld\n"->lines, ['Hello', 'Wor', '', 'ld'], '... got the correct lines');
2e99cc07 49
3f4dd8b7 50eval 'Hello World, Hello'->dump;
51is($VAR1, 'Hello World, Hello' , '... eval of &dump works');
52
53eval 'Hello World, Hello'->perl;
54is($VAR1, 'Hello World, Hello' , '... eval of &perl works');
55