File: basic.t

package info (click to toggle)
libstring-rewriteprefix-perl 0.007-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 128 kB
  • sloc: perl: 74; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,130 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use strict;
use warnings;

use Test::More tests => 3;

use String::RewritePrefix;

# testing this method directly seems excessive -- rjbs, 2009-11-30
my $rewriter = String::RewritePrefix->_new_rewriter(undef, {
  prefixes => {
    '-' => 'Tet::',
    '@' => 'KaTet::',
    '+' => sub { $_[0] . '::Foo::' },
    '!' => sub { return undef },
  },
});

my @results = $rewriter->(qw(
  -Corporation
  @Roller
  Plinko
  -@Oops
  +Bar
  !None
));

is_deeply(
  \@results,
  [ qw(Tet::Corporation KaTet::Roller Plinko Tet::@Oops Bar::Foo::Bar None) ],
  "rewrote prefices",
);

my @to_load = String::RewritePrefix->rewrite(
  { '' => 'MyApp::', '+' => '' },
  qw(Plugin Mixin Addon +Corporate::Thinger),
);

is_deeply(
  \@to_load,
  [ qw(MyApp::Plugin MyApp::Mixin MyApp::Addon Corporate::Thinger) ],
  "from synopsis, code okay",
);

{
  String::RewritePrefix->import(
    rewrite => { -as => 'pfx_rw', prefixes => {
      '-' => 'minus ',
      '+' => 'plus ',
      ''  => 'plus ',
    } }
  );
  
  is_deeply(
    [ pfx_rw(qw(+10 10 -10 0)) ],
    [ 'plus 10', 'plus 10', 'minus 10', 'plus 0' ],
    'rewrote with import',
  );
}