Bubblegum

 view release on metacpan or  search on metacpan

t/bubblegum/object/string.t  view on Meta::CPAN

    is_deeply $string->lines, # ['who am i?','where am i?','how did I get here']
        ['who am i?','where am i?','how did I get here'];
};

can_ok 'Bubblegum::Object::String', 'lowercase';
subtest 'test the lowercase method' => sub {
    my $string = 'EXCITING';
    is 'exciting', $string->lowercase; # exciting
};

can_ok 'Bubblegum::Object::String', 'replace';
subtest 'test the replace method' => sub {
    my $string;

    $string = 'Hello World';
    is $string->replace('World', 'Universe'),
        'Hello Universe'; # Hello Universe

    $string = 'Hello World';
    is $string->replace('world', 'Universe', 'i'),
        'Hello Universe'; # Hello Universe

    $string = 'Hello World';
    is $string->replace(qr/world/i, 'Universe'),
        'Hello Universe'; # Hello Universe

    $string = 'Hello World';
    is $string->replace(qr/.*/, 'Nada'),
        'Nada'; # Nada
};

can_ok 'Bubblegum::Object::String', 'reverse';
subtest 'test the reverse method' => sub {
    my $string = 'dlrow ,olleH';
    is 'Hello, world', $string->reverse; # Hello, world
};

can_ok 'Bubblegum::Object::String', 'rindex';
subtest 'test the rindex method' => sub {
    my $string = 'explain the unexplainable';
    is 14, $string->rindex('explain'); # 14
    is 0, $string->rindex('explain', 0); # 0
    is 14, $string->rindex('explain', 21); # 14
    is 14, $string->rindex('explain', 22); # 14
    is 14, $string->rindex('explain', 23); # 14
    is 14, $string->rindex('explain', 20); # 14
    is 14, $string->rindex('explain', 14); # 14
    is 0, $string->rindex('explain', 13); # 0
    is 0, $string->rindex('explain', 0); # 0
    is -1, $string->rindex('explained'); # -1
};

can_ok 'Bubblegum::Object::String', 'snakecase';
subtest 'test the snakecase method' => sub {
    my $string = 'hello world';
    is 'helloWorld', $string->snakecase; # helloWorld
    is 'helloWorld', $string; # helloWorld
};

can_ok 'Bubblegum::Object::String', 'split';
subtest 'test the split method' => sub {
    my $string = 'name, age, dob, email';
    is_deeply $string->split(qr/\,\s*/), # ['name', 'age', 'dob', 'email']
        ['name', 'age', 'dob', 'email'];
    is_deeply $string->split(qr/\,\s*/, 2), # ['name', 'age, dob, email']
        ['name', 'age, dob, email'];
    is_deeply $string->split(', '), # ['name', 'age', 'dob', 'email']
        ['name', 'age', 'dob', 'email'];
    is_deeply $string->split(', ', 2), # ['name', 'age, dob, email']
        ['name', 'age, dob, email'];
};

can_ok 'Bubblegum::Object::String', 'strip';
subtest 'test the strip method' => sub {
    my $string = 'one,  two,  three';
    is 'one, two, three', $string->strip; # one, two, three
    is 'one, two, three', $string; # one, two, three
};

can_ok 'Bubblegum::Object::String', 'titlecase';
subtest 'test the titlecase method' => sub {
    my $string = 'mr. wellington III';
    is 'Mr. Wellington III', $string->titlecase; # Mr. Wellington III
    is 'Mr. Wellington III', $string; # Mr. Wellington III
};

can_ok 'Bubblegum::Object::String', 'to_array';
subtest 'test the to_array method' => sub {
    my $string = 'uniform';
    is_deeply $string->to_array, ['uniform']; # ['uniform']
};

can_ok 'Bubblegum::Object::String', 'to_code';
subtest 'test the to_code method' => sub {
    my $string = 'uniform';
    is 'CODE', ref $string->to_code; # sub { 'uniform' }
    is 'uniform', $string->to_code->(); # uniform
};

can_ok 'Bubblegum::Object::String', 'to_hash';
subtest 'test the to_hash method' => sub {
    my $string = 'uniform';
    is_deeply $string->to_hash, # { 'uniform' => 1 }
        { 'uniform' => 1 };
};

can_ok 'Bubblegum::Object::String', 'to_number';
subtest 'test the to_number method' => sub {
    my $string = 'uniform';
    is 0, $string->to_number; # 0

    $string = '123';
    is 123, $string->to_number; # 123
};

can_ok 'Bubblegum::Object::String', 'to_string';
subtest 'test the to_string method' => sub {
    my $string = 'uniform';
    is 'uniform', $string->to_string; # uniform
};



( run in 1.057 second using v1.01-cache-2.11-cpan-483215c6ad5 )