File: bad.t

package info (click to toggle)
libstring-errf-perl 0.009-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 328; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,003 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
use Test::More tests => 2;
use String::Errf 'errf';

my $payload = {
  total_amount => 1010,
  limit        => 1000,
  category     => "sandwiches",
};

{
  # Here String::Errf could warn about a malformed format string, or it could
  # produce reasonable partial output, but it does neither.
  my $format = join(" ",
    "payment of \$%{total_amount}",
    "for category '%{category}s'",
    "over limit of \$%{limit;.2}f",
  );

  my $output = eval { errf($format, $payload) };
  isnt($output, 'payment of $\' over limit of $1000.00', "wat");
}

{
  # Here String::Errf could warn about a malformed format string, or it could
  # produce reasonable partial output, but it does neither.
  my $format = join(" ",
    "payment of \$%{total_amount;.2}",
    "for category '%{category}s'",
    "over limit of \$%{limit;.2}f",
  );

  my $output = eval { errf($format, $payload) };
  ok(
    ! defined $output || $output =~ qr/category.*sandwiches/,
    "where did the literal text 'category' go?",
  );
}