Advanced-Config
view release on metacpan or search on metacpan
t/76-check_all_languages2.t view on Meta::CPAN
}
my $tmp = $lang;
# $tmp = Advanced::Config::Date::swap_language ($lang);
if ( $tmp ne $lang ) {
dbug_ok (0, "Language was changed to ${lang}");
next;
}
dbug_ok (1, "Validating dates for language ${lang} ...");
# Validate the weekdays ...
my $wd = $sCfg->get_list_values ("WeekDays", qr/\s*,\s*/, undef, {required => 1});
my $cnt = @{$wd};
$cnt = 7 if ( $cnt == 8 && $wd->[0] eq $wd->[-1] );
dbug_is ( $cnt, 7, "Found 7 weekdays defined by tag 'WeekDays' ($cnt)" );
foreach my $tag ( @{$wd} ) {
my $val = $sCfg->get_value ($tag) || "";
DBUG_PRINT ("UTF8", "utf8 flag (%d)", utf8::is_utf8($val));
my $ok = ($val =~ m/^Found /) ? 1 : 0;
dbug_ok ($ok, "Found Weekday Tag ($tag): ${val}");
}
# Validate the date itself ...
foreach my $tag ( $sCfg->find_tags (qr /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/, 0) ) {
my $val1 = $sCfg->get_value ($tag);
DBUG_PRINT ("UTF8", "utf8 flag (%d)", utf8::is_utf8($val1));
my $val2 = $sCfg->get_date ($tag, $lang, date_language_warn => 1);
if ( $val2 && $val2 eq $tag ) {
dbug_ok (1, "Found tag: ${tag} in section '${s}' for ${lang} --> ${val2} -- ${val1}");
} else {
dbug_ok (0, "Tag ${tag} in section '${s}' for ${lang} points to a valid date: ${val1}");
}
}
DBUG_PRINT ("----", "-------------------------------------------------");
}
DBUG_VOID_RETURN ();
}
# ====================================================================
# From here on down deals with creating the config file.
# ====================================================================
sub build_config_file
{
DBUG_ENTER_FUNC (@_);
my $all_languages = shift;
my $wide_flag = shift;
my $file = $wide_flag ? $config_file_wide : $config_file_normal;
unless ( open (CONFIG, ">", $file) ) {
dbug_ok (0, "Creating the UTF-8 config file: $file");
return DBUG_RETURN (0);
}
my $msg;
if ( $wide_flag ) {
dbug_ok (1, "Creating the UTF-8 config file: $file");
binmode (CONFIG, "encoding(UTF-8)"); # Converts to wide-char / Unicode output.
$msg = "This file was created using UTF-8 Encoding";
} else {
dbug_ok (1, "Creating the normal config file: $file");
$msg = "This file was created without any special Encoding";
}
print CONFIG "\n";
print CONFIG "# This is an auto-genearted config file.\n";
print CONFIG "# Do not modify it by hand!\n\n";
print CONFIG "# ${msg}\n\n";
my $englishDoW = $all_languages->{English}->{DoW};
foreach my $lang ( sort keys %{$all_languages} ) {
my $l = $all_languages->{$lang};
next if ( $l->{wide} && ! $wide_flag );
print CONFIG "[ $lang ]\n";
print CONFIG " Language = $lang\n"; # To preserve the case...
print CONFIG " Wide = $l->{wide}\n";
print CONFIG " WeekDays = ", join (", ", @{$l->{DoW}}), "\n\n";
foreach ( 0..6 ) {
print CONFIG " $l->{DoW}->[$_] = Found $englishDoW->[$_] in ${lang} ($l->{DoW}->[$_])\n";
}
print CONFIG "\n";
# ---------------------------
# The 4 digit years ....
# ---------------------------
foreach ( 1..12 ) {
print CONFIG build_date (0, 2018, $_, $_ + 1, $l);
}
print CONFIG "\n";
foreach ( 1..12 ) {
print CONFIG build_date (1, 2019, $_, $_ + 14, $l);
}
print CONFIG "\n";
# ----------------------------------------------------------
# The 2 digit years .... Use 199x years to avoid ambiguity
# ----------------------------------------------------------
foreach ( 1..12 ) {
print CONFIG build_date (2, 1998, $_, $_ + 2, $l);
}
print CONFIG "\n";
foreach ( 1..12 ) {
print CONFIG build_date (3, 1999, $_, $_ + 15, $l);
}
print CONFIG "\n";
}
print CONFIG "----------------------------------------------------------\n\n";
# These extra sections are for advanced checks ...
# Using variables and Encryption ...
my $cntr = 0;
( run in 0.569 second using v1.01-cache-2.11-cpan-39bf76dae61 )