File: 01-string.t

package info (click to toggle)
libstring-trim-perl 0.005-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 208 kB
  • ctags: 2
  • sloc: perl: 180; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 972 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More 0.94 tests => 2;
use Test::Builder 0.94 qw();
use String::Trim;

my $strings = {
    'one'       => 'one',
    'tw o'      => 'tw o',
    ' three'    => 'three',
    'four '     => 'four',
    ' five '    => 'five',
    '               six          ' => 'six',
    " seven\n"  => 'seven',
    "\n\neight" => 'eight',
    " nine\nten " => "nine\nten",
};

subtest 'return' => sub {
    plan tests => scalar keys %$strings;
    foreach my $key (keys %$strings) {
        my $to_trim = $key;
        my $ought   = $strings->{$key};
        my $trimmed = trim($to_trim);
        is($trimmed, $ought, "trim($to_trim) returned '$ought' OK");
    }
};

subtest 'in-place' => sub {
    plan tests => scalar keys %$strings;
    foreach my $key (keys %$strings) {
        my $to_trim = $key;
        my $ought   = $strings->{$key};
        trim($to_trim);
        is($to_trim, $ought, "'$to_trim' trimmed to '$ought' in-place OK");
    }
};