File: method.t

package info (click to toggle)
libstring-formatter-perl 0.102082-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 156 kB
  • sloc: perl: 477; makefile: 12
file content (35 lines) | stat: -rw-r--r-- 700 bytes parent folder | download | duplicates (2)
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
#!perl
use strict;

use Test::More tests => 1;

use String::Formatter;

{
  package Zombie;
  sub new     { bless {} }
  sub groan   { 'nnnnngh' }
  sub request { "Send... more... $_[1]!" }
}

{
  my $fmt = String::Formatter->new({
    input_processor => 'require_single_input',
    string_replacer => 'method_replace',

    codes => {
      g => 'groan',
      r => 'request',
      i => sub { 0 + $_[0] },
    },
  });

  {
    my $zombie = Zombie->new;
    my $have = $fmt->format(q(%g... zombie number %i say: %{cops}r), $zombie);
    my $zid  = 0 + $zombie;
    my $want = "nnnnngh... zombie number $zid say: Send... more... cops!";

    is($have, $want, "method_replace GOOD. fire BAD");
  }
}