Test AN::Tools::String

From Alteeve Wiki
Revision as of 03:24, 5 May 2013 by Digimer (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 AN!Tools :: AN::Tools :: Test AN::Tools::String

t/String.t

#!/usr/bin/perl -Tw
#
# This is the test script for the AN::Tools family of modules.
# 

use AN::Tools 0.0.001;
my $an=AN::Tools->new();

# Make sure that $parent matches $an.
my $parent=$an->String->parent();
is($an, $parent, "Internal 'parent' method returns same blessed reference as is in \$an.");

# use Data::Dumper;
# print Dumper $an->data;

# Make sure that all methods are available.
my @methods=(
	"parent", 
	"force_utf8", 
	"read_words",
	"get_string",
	"_insert_vars",
	"_process",
	"_insert_word",
	"_protect",
	"_restore_protected",
	"_format_mode"
);
can_ok("AN::Tools::String", @methods);

### This is String testing stuff, feel free to ignore for now.
is($an->String->get_string("t_0000"), "Test", "get_string(); key only, array type call.");
is($an->String->get_string({key=>"t_0000"}), "Test", "get_string(); key only, hash reference-type call.");
is($an->String->get_string("t_0001", ["A"]), "Test replace: [A].", "get_string(); key and one variable, array type call.");
is($an->String->get_string({key=>"t_0001",variable=>["A"]}), "Test replace: [A].", "get_string(); key and one variable, hash reference type call.");
is($an->String->get_string({key=>"t_0002",variable=>["A", "B"]}), "Test Out of order: [B] replace: [A].", "get_string(); key and two variables, out of order injection.");
is($an->String->get_string({key=>"t_0002",variable=>["あ", "い"],language=>"jp"}), "テスト、 整理: [い]/[あ].", "get_string(); key and two variables, out of order injection, alternate language.");
# Test reading in a second words file into a second hash reference.
my $test={};
is($an->String->read_words("./t/test.xml", $test), 1, "read_words(); Read in 'test.xml' into a new hash reference, array type call.");
use Data::Dumper;
print Dumper $test;
exit;
is($an->String->get_string({key=>"ta_0000",variable=>["A"],hash=>$test}), "Test replace: [A].", "get_string(); key and one variable, alternate words hash.");
$test={};	# Blank
is($an->String->read_words({file=>"./t/test.xml", hash=>$test}), 1, "read_words(); Read in 'test.xml' into cleared hash reference for next set of tests, hash reference type call.");
is($an->String->read_words("./t/test.xml", $test), 1, "read_words(); Read in 'test.xml' into a new hash reference for next set of tests.");
is($an->String->get_string({key=>"ta_0000",variable=>["A"],hash=>$test,language=>"jp"}), "テスト、 整理: [い]/[あ].", "get_string(); key and one variable, alternate words hash and alternate language.");

### Failure tests.
# is($an->String->read_words("./test.xml", $hash), 1, "read_words(); Read in 'test.xml' into a new hash reference for next set of tests.");

# my $conf=$an->data()->{words}{lang}{en_CA}{key}{an_0000}{content};
# my $confj=$an->data()->{words}{lang}{jp}{key}{an_0000}{content};
# print "Data: [$conf] ($confj)\n";
# use IO::Handle;
# my $test=IO::Handle->new();
# open ($test, ">test.txt") or die "Failed to open 'test.txt' for writting. error was: $!\n";
# print $test "Data: [$conf] ($confj)\n";
# $test->close();
# foreach my $key (keys %{$conf})
# {
# 	print "key: [$key] = [$conf->{$key}]\n";
# }
# 
# use Data::Dumper;
# print Dumper $an->data();

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.