File: format_picture.t

package info (click to toggle)
libnumber-format-perl 1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: perl: 590; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,436 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
# -*- CPerl -*-

use Test::More qw(no_plan);
use strict;
use warnings;

use POSIX;
setlocale(&LC_ALL, 'C');

BEGIN { use_ok('Number::Format') }

my $pic = 'US$##,###,###.##';
my $x = Number::Format->new;
$x->{neg_format} = '-x';
is($x->format_picture(123456.512, $pic),    'US$    123,456.51',  'thou');
is($x->format_picture(-1234567.509, $pic),  'US$ -1,234,567.51',  'neg');
is($x->format_picture(12345678.5, $pic),    'US$ 12,345,678.50',  'zero');
is($x->format_picture(123456789.51, $pic),  'US$ **,***,***.**',  'pos over');
is($x->format_picture(-123456789.51, $pic), 'US$-**,***,***.**',  'neg over');
is($x->format_picture(1023012.34, $pic),    'US$  1,023,012.34',  'million');
is($x->format_picture(120450.789012, $pic), 'US$    120,450.79',  'pos rnd');
is($x->format_picture(-120450.789012, $pic),'US$   -120,450.79',  'neg rnd');
$x->{neg_format} = '(x)';
is($x->format_picture(120450.789012, $pic), 'US$    120,450.79 ', 'pos paren');
is($x->format_picture(-120450.789012, $pic),'US$   (120,450.79)', 'neg paren');
$pic = '#';
is($x->format_picture(1, $pic), ' 1 ',  'one digit 1');
is($x->format_picture(2, $pic), ' 2 ',  'one digit 2');

{
    my @warnings;
    local $SIG{__WARN__} = sub { @warnings = @_ };
    is($x->format_picture(undef, $pic), " 0 ");
    my $file = __FILE__;
    like("@warnings",
         qr{Use of uninitialized value in call to Number::Format::format_picture at \Q$file\E line \d+[.]?\n});
}