File: 01..trim.t

package info (click to toggle)
libtext-trim-perl 1.02-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 104 kB
  • ctags: 4
  • sloc: perl: 26; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::More tests => 10;

BEGIN {
    use_ok('Text::Trim');
}

my $text = my $orig = "\t  foo\t  \t\n";
is(trim($text), 'foo', 'trim in scalar context');
is($text, $orig, ".. didn't affect original");

trim($text);
is($text, 'foo', 'trim in place changes original');

{
    local $_ = $orig;
    my $trimmed = trim;
    is($trimmed, 'foo', '$scalar = trim() works on $_');
    is($_,     , $orig, ".. didn't affect original");

    trim;
    is($_,     , 'foo', "trim() alters \$_")
}

my @before = (
    "  foo  ",
    "\tbar\t",
    "\nbaz\n",
);
my @expected = qw( foo bar baz );
my @trimmed = trim @before;
is_deeply(\@trimmed, \@expected, 'trim on a list in list content');
trim @before;
is_deeply(\@before, \@expected,  'trim on a list in place');

my $expected = "@expected";
my $trimmed = trim @before;
is($trimmed, $expected, 'trim on a list in scalar context');

__END__

vim: ft=perl ts=8 sts=4 sw=4 sr et