* Fixed the double-encoding messages when using XML::Simple to read in words files. Our use for XML is simple, so despite XML::Simple being discouraged, it suits our needs well.
* Created tests for most existing module methods now.
* Updated Storage->search_directories to handle merging @INC and $ENV{'PATH'} when called with an invalid directories parameter, and exploited this behaviour to initially set the directory search list. This also deprecated the Tools->_add_environment_path_to_search_directories() method.
* Added Storage->read_config based on the old v2 'Storage->read_conf()'. Also ported over the old Tools->_add_hash_reference() and Tools->_make_hash_reference() methods to assist with this method's operation.
* Created Words->key() that returns the raw string for a given language and key.
Signed-off-by: Digimer <digimer@alteeve.ca>
cmp_ok($a2_count,'==',2,"Verifying that \$an->Storage->search_directories now has 2 entries from a passed in CSV, testing that the list changed and a fake directory was dropped.");
cmp_ok($a3_count,'==',3,"Verifying that \$an->Storage->search_directories now has 3 entries from a passed in array reference, verifying that the list changed again.");
cmp_ok($a4_count,'==',$a1_count,"Verifying that \$an->Storage->search_directories has the original number of directories: [$a4_count] after being called with an invalid 'directories' parameter, showing that it reset properly.");
is($bad_path,"#!not_found!#","Verifying that \$an->Storage->find properly returned '#!not_found!#' for a non-existed file.");
# Config file read tests.
$an->data->{foo}{bar}{a}="test";
is($an->Storage->read_config({file=>"AN/test.conf"}),0,"Verifying that '\$an->Storage->read_config' successfully found 'AN/test.conf'.");
is($an->Storage->read_config({file=>""}),1,"Verifying that '\$an->Storage->read_config' returns '1' when called without a 'file' parameter being set.");
is($an->Storage->read_config({file=>"AN/moo.conf"}),2,"Verifying that '\$an->Storage->read_config' returns '2' when the non-existent 'AN/moo.conf' is passed.");
cmp_ok($an->data->{foo}{bar}{a},'eq','I am "a"',"Verifying that 'AN/test.conf's 'foo::bar::a' overwrote an earlier set value.");
cmp_ok($an->data->{foo}{bar}{b},'eq','I am "b", split with tabs and having trailing spaces.',"Verifying that 'AN/test.conf's 'foo::bar::b' has whitespaces removed as expected.");
cmp_ok($an->data->{foo}{baz}{1},'eq','This is \'1\' with no spaces',"Verifying that 'AN/test.conf's 'foo::baz::1' parsed without spaces around '='.");
cmp_ok($an->data->{foo}{baz}{2},'eq','I had a $dollar = sign and split with tabs.',"Verifying that 'AN/test.conf's 'foo::baz::2' had no trouble with a '$' and '=' characters in the string.");
### AN::Tools::Words methods
# Make sure we can read words files
is($an->Words->read({file=>$an->data->{path}{words}{'an-tools.xml'}}),0,"Verifying that '\$an->Words->read' properly returned '0' when asked to read the AN::Tools's words file.");
is($an->Words->read({file=>''}),1,"Verifying that '\$an->Words->read' properly returned '1' when asked to read a works file without a file being passed.");
is($an->Words->read({file=>'/tmp/dummy.xml'}),2,"Verifying that '\$an->Words->read' properly returned '2' when asked to read a non-existent file.");
### NOTE: At this time, we don't test for unreadable files (rc = 3) or general read faults as set by XML::Simple (rc = 4).
# Make sure we can read strings.
is($an->Words->key({key=>'t_0001'}),"Test replace: [#!variable!test!#].","Verifying that '\$an->Words->key' returned the Canadian English 't_0001' string.");
is($an->Words->key({key=>'t_0001',language=>'jp'}),"テスト いれかえる: [#!variable!test!#]。","Verifying that '\$an->Words->read' returned the Japanese 't_0001' string.");
is($an->Words->key({key=>'t_0003',language=>'jp'}),"#!not_found!#","Verifying that '\$an->Words->read' returned '#!not_found!#' for the missing 't_0003' key.");
print$THIS_FILE." ".__LINE__."; [ Warning ] - AN::Tools::Words->read()' asked to read: [$file] which was not found.\n";
$return_code=2;
}
elsif(not-r$file)
{
# TODO: Log the problem, do not translate.
print$THIS_FILE." ".__LINE__."; [ Warning ] - AN::Tools::Words->read()' asked to read: [$file] which was not readable by: [".getpwuid($<)."/".getpwuid($>)."] (uid/euid: [".$<."/".$>."]).\n";
print$THIS_FILE." ".__LINE__."; The passed in array: [$array] wasn't an array. Using \@INC for the list of directories to search instead.\n";
$array=\@INC;
print$THIS_FILE." ".__LINE__."; [ Warning ] - The passed in array: [$array] wasn't actually an array. Using \@INC + \$ENV{'PATH'} for the list of directories to search instead.\n";
# Create a new array containing the '$ENV{'PATH'}' directories and the @INC directories.
Thefilecanbethefilename,orapath.Thespecifiedfileissearchforbymatchingthethepassedinstringagainsttheendofthefilepath.Forexample,'C<< file => 'AN/an-tools.xml' >> will match the file 'c<< /usr/share/perl5/AN/an-tools.xml>>'.
print$THIS_FILE." ".__LINE__."; AN::Tools::Words->read()' called without a file name to read.\n";
print$THIS_FILE." ".__LINE__."; [ Warning ] - AN::Tools::Words->read()' called without a file name to read.\n";
$return_code=1;
}
elsif(not-e$file)
{
# TODO: Log the problem, do not translate.
print$THIS_FILE." ".__LINE__."; AN::Tools::Words->read()' asked to read: [$file] which was not found.\n";
print$THIS_FILE." ".__LINE__."; [ Warning ] - AN::Tools::Words->read()' asked to read: [$file] which was not found.\n";
$return_code=2;
}
elsif(not-r$file)
{
# TODO: Log the problem, do not translate.
print$THIS_FILE." ".__LINE__."; AN::Tools::Words->read()' asked to read: [$file] which was not readable by: [".getpwuid($<)."/".getpwuid($>)."] (uid/euid: [".$<."/".$>."]).\n";
print$THIS_FILE." ".__LINE__."; [ Warning ] - AN::Tools::Words->read()' asked to read: [$file] which was not readable by: [".getpwuid($<)."/".getpwuid($>)."] (uid/euid: [".$<."/".$>."]).\n";