File: 005_string.t

package info (click to toggle)
libmoose-autobox-perl 0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 224 kB
  • ctags: 124
  • sloc: perl: 1,057; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 22;
use Test::Exception;

use Moose::Autobox;

my $VAR1; # for eval of dumps

is('Hello World'->lc, 'hello world', '... $str->lc');
is('Hello World'->uc, 'HELLO WORLD', '... $str->uc');

is('foo'->ucfirst, 'Foo', '... $str->ucfirst');
is('Foo'->lcfirst, 'foo', '... $str->lcfirst');

dies_ok { ('Hello')->chop } '... cannot modify a read-only';
{
    my $greeting = 'Hello';
    is($greeting->chop, 'o', '... got the chopped off portion of the string');
    is($greeting, 'Hell', '... and are left with the rest of the string');
}

dies_ok { "Hello\n"->chomp } '... cannot modify a read-only';
{
    my $greeting = "Hello\n";
    is($greeting->chomp, '1', '... got the chopped off portion of the string');
    is($greeting, 'Hello', '... and are left with the rest of the string');
}

is('reverse'->reverse, 'esrever', '... got the string reversal');
is('length'->length, 6, '... got the string length');

is('Hello World'->index('World'), 6, '... got the correct index');

is('Hello World, Hello'->index('Hello'), 0, '... got the correct index');

is('Hello World, Hello'->index('Hello', 6), 13, '... got the correct index');

is('Hello World, Hello'->rindex('Hello'), 13, '... got the correct right index');

is('Hello World, Hello'->rindex('Hello', 6), 0, '... got the correct right index');

is_deeply('/foo/bar/baz'->split('/'), ['', 'foo', 'bar', 'baz'], '... got the correct fragments');
is_deeply('Hello World'->words, ['Hello', 'World'], '... got the correct words');
is_deeply("Hello\nWor\n\nld\n"->lines, ['Hello', 'Wor', '', 'ld'], '... got the correct lines');

eval 'Hello World, Hello'->dump;
is($VAR1, 'Hello World, Hello' , '... eval of &dump works');

eval 'Hello World, Hello'->perl;
is($VAR1, 'Hello World, Hello' , '... eval of &perl works');