2 require '../../t/test.pl';
3 require '../../t/loc_tools.pl'; # to find locales
9 skip_all("locales not available") unless locales_enabled('LC_NUMERIC');
11 my @locales = eval { find_locales( &LC_NUMERIC ) };
12 skip_all("no LC_NUMERIC locales available") unless @locales;
15 for my $locale (@locales) {
18 setlocale(LC_NUMERIC, $locale) or next;
19 my $in = 4.2; # avoid any constant folding bugs
20 my $s = sprintf("%g", $in);
22 $comma_locale = $locale;
29 if ($Config{usequadmath}) {
30 skip "no gconvert with usequadmath", 2;
32 is(test_Gconvert(4.179, 2), "4.2", "Gconvert doesn't recognize underlying locale outside 'use locale'");
34 is(test_Gconvert(4.179, 2), "4.2", "Gconvert doesn't recognize underlying locale inside 'use locale'");
37 sub check_in_bounds($$$) {
38 my ($value, $lower, $upper) = @_;
40 $value >= $lower && $value <= $upper
44 # This checks that when switching to the global locale, the service that
45 # Perl provides of transparently dealing with locales that have a non-dot
46 # radix is turned off, but gets turned on again after a sync_locale();
48 skip "no locale with a comma radix available", 5 unless $comma_locale;
50 my $global_locale = switch_to_global_and_setlocale(LC_NUMERIC,
52 # Can't do a compare of $global_locale and $comma_locale because what the
53 # system returns may be an alias. ALl we can do is test for
55 ok($global_locale, "Successfully switched to $comma_locale");
56 is(newSvNV("4.888"), 4, "dot not recognized in global comma locale for SvNV");
58 no warnings 'numeric'; # Otherwise get "Argument isn't numeric in
61 is(check_in_bounds(newSvNV("4,888"), 4.88, 4.89), 1,
62 "comma recognized in global comma locale for SvNV");
63 isnt(sync_locale, 0, "sync_locale() returns that was in the global locale");
65 is(check_in_bounds(newSvNV("4.888"), 4.88, 4.89), 1,
66 "dot recognized in perl-controlled comma locale for SvNV");
69 my %correct_C_responses = (
70 # Entries that are undef could have varying returns
105 ERA_D_T_FMT => undef,
115 MON_9 => 'September',
117 MON_11 => 'November',
118 MON_12 => 'December',
130 my $hdr = "../../perl_langinfo.h";
131 open my $fh, "<", $hdr;
135 skip "No LC_ALL", 1 unless locales_enabled('LC_ALL');
138 setlocale(LC_ALL, "C");
139 eval "use I18N::Langinfo qw(langinfo RADIXCHAR); langinfo(RADIXCHAR)";
140 my $has_nl_langinfo = $@ eq "";
142 skip "Can't open $hdr for reading: $!", 1 unless $fh;
146 # Find all the current items from the header, and their values.
147 # For non-nl_langinfo systems, those values are arbitrary negative numbers
148 # set in the header. Otherwise they are the nl_langinfo approved values,
149 # which for the moment is the item name.
150 # The relevant lines look like: # define YESSTR -54
153 next unless / - \d+ $ /x;
154 s/ ^ \# \s* define \s*//x;
156 $items{$1} = ($has_nl_langinfo)
157 ? $1 # Yields 'YESSTR'
161 # Get the translation from item name to numeric value.
162 I18N::Langinfo->import(keys %items) if $has_nl_langinfo;
164 foreach my $formal_item (sort keys %items) {
166 if (exists $correct_C_responses{$formal_item}) {
167 my $correct = $correct_C_responses{$formal_item};
168 my $item = eval $items{$formal_item};
169 skip "This platform apparently doesn't support $formal_item", 1 if $@;
170 my $result = test_Perl_langinfo($item);
171 if (defined $correct) {
172 is ($result, $correct,
173 "Returns expected value" . "('$correct') for $formal_item");
175 elsif (defined $result) {
176 pass("Returns a value (in this case '$result') for $formal_item");
179 fail("Returned undef for $formal_item");