File: formatnumber.t

package info (click to toggle)
libhtml-formfu-perl 2.07000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 4,392 kB
  • sloc: perl: 12,777; makefile: 9; sql: 5
file content (47 lines) | stat: -rw-r--r-- 1,065 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
use strict;
use warnings;

our $count;
BEGIN { $count = 3 }
use Test::More tests => $count;

use HTML::FormFu;
use Number::Format;
use POSIX qw( setlocale LC_NUMERIC );

my $form = HTML::FormFu->new;

$form->load_config_file('t/filters/formatnumber.yml');

my $backup_locale = setlocale(LC_NUMERIC);

SKIP: {

    # first test the de_DE locale is available
    my $ok = setlocale( LC_NUMERIC, 'de_DE' );

    if ( !$ok ) {

        # not available - restore locale and bail
        setlocale( LC_NUMERIC, $backup_locale );
        skip 'de_DE locale not available', $count;
    }

    my $format = Number::Format->new;

    my $formatted_number = $format->format_number('23000222.22');

    isnt( $formatted_number, '23000222.22', 'format of number has changed' );

    # restore orginal locale
    setlocale( LC_NUMERIC, $backup_locale );

    {
        $form->process( { foo => $formatted_number, } );

        ok( $form->submitted_and_valid );

        is( $form->param_value('foo'),
            '23000222.22', 'number no longer in german formatting' );
    }
}