File: 53m_default.t

package info (click to toggle)
libstring-print-perl 0.96-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184 kB
  • sloc: perl: 781; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,396 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
#!/usr/bin/env perl
# Test the 'undef default' modifier

use warnings;
use strict;
use utf8;

use Test::More;

use String::Print;

my $f = String::Print->new;
isa_ok($f, 'String::Print');

### these are all examples from the manual page

is $f->sprinti("visitors: {count //0}", count => 1), "visitors: 1", 'count';
is $f->sprinti("visitors: {count //0}", count => undef), "visitors: 0";
is $f->sprinti("visitors: {count//0}",  count => undef), "visitors: 0";

is $f->sprinti("published: {date DT//'not yet'}", date => undef),
   "published: not yet", 'date';
is $f->sprinti('published: {date DT//"not yet"}', date => undef),
   "published: not yet";
is $f->sprinti("published: {date DT//'not yet'}", date =>"2017-06-25 12:35:00"),
   "published: 2017-06-25 12:35:00";

is $f->sprinti("copyright: {year//2017 YEAR}", year => " 2018 "),
   'copyright: 2018', 'year';
is $f->sprinti("copyright: {year//2017 YEAR}", year => undef),
   'copyright: 2017';

$f->addModifiers(qw/EUR\b/ => sub {
    my ($sp, $format, $value, $args) = @_;
    defined $value ? "$value€" : undef;
});

is $f->sprinti("price: {price//5 EUR}", price => 3), 'price: 3€', 'price';
is $f->sprinti("price: {price//5 EUR}", price => undef), 'price: 5€';
is $f->sprinti("price: {price EUR//unknown}", price => 3), 'price: 3€';
is $f->sprinti("price: {price EUR//unknown}", price => undef), 'price: unknown';

done_testing;