Created
June 19, 2009 18:48
-
-
Save robinsmidsrod/132784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 5b70fa7ed266b78825dbf8d3dba65857d69fb54d | |
Author: Robin Smidsrød <[email protected]> | |
Date: Fri Jun 19 20:47:10 2009 +0200 | |
Tests for namespaced loading | |
diff --git a/t/03_1.namespaced_loading.t b/t/03_1.namespaced_loading.t | |
new file mode 100644 | |
index 0000000..825cf36 | |
--- /dev/null | |
+++ b/t/03_1.namespaced_loading.t | |
@@ -0,0 +1,41 @@ | |
+#!/usr/bin/perl | |
+ | |
+use strict; | |
+use warnings; | |
+ | |
+use Test::More tests => 5; | |
+ | |
+use XML::Toolkit::Builder (); | |
+use XML::Toolkit::Loader (); | |
+ | |
+my $xml1 = '<root xmlns="abc">test1</root>'; | |
+my $xml2 = '<my:root xmlns:my="abc">test2</my:root>'; | |
+ | |
+my $args={ | |
+ namespace_map => { 'abc' => 'ABC' } | |
+}; | |
+ | |
+eval { | |
+ my $builder = XML::Toolkit::Builder->new($args); | |
+ $builder->parse_string($xml1); | |
+ my $code = $builder->render(); | |
+ eval $code; | |
+ my $root = ABC::Root->new(); | |
+ isa_ok($root, 'ABC::Root'); | |
+}; | |
+ | |
+eval { | |
+ my $loader = XML::Toolkit::Loader->new($args); | |
+ $loader->parse_string($xml1); | |
+ my $root = $loader->root_object; | |
+ isa_ok($root,'ABC::Root'); | |
+ ok($root->text eq 'test1', 'root node text was not loaded correctly'); | |
+}; | |
+ | |
+eval { | |
+ my $loader = XML::Toolkit::Loader->new($args); | |
+ $loader->parse_string($xml2); | |
+ my $root = $loader->root_object; | |
+ isa_ok($root,'ABC::Root'); | |
+ ok($root->text eq 'test2', 'root node text was not loaded correctly'); | |
+}; | |
diff --git a/t/03_2.namespaced_loading.t b/t/03_2.namespaced_loading.t | |
new file mode 100644 | |
index 0000000..28ab4f0 | |
--- /dev/null | |
+++ b/t/03_2.namespaced_loading.t | |
@@ -0,0 +1,41 @@ | |
+#!/usr/bin/perl | |
+ | |
+use strict; | |
+use warnings; | |
+ | |
+use Test::More tests => 5; | |
+ | |
+use XML::Toolkit::Builder (); | |
+use XML::Toolkit::Loader (); | |
+ | |
+my $xml1 = '<root xmlns="abc">test1</root>'; | |
+my $xml2 = '<my:root xmlns:my="abc">test2</my:root>'; | |
+ | |
+my $args={ | |
+ namespace_map => { 'abc' => 'ABC' } | |
+}; | |
+ | |
+eval { | |
+ my $builder = XML::Toolkit::Builder->new($args); | |
+ $builder->parse_string($xml2); | |
+ my $code = $builder->render(); | |
+ eval $code; | |
+ my $root = ABC::Root->new(); | |
+ isa_ok($root, 'ABC::Root'); | |
+}; | |
+ | |
+eval { | |
+ my $loader = XML::Toolkit::Loader->new($args); | |
+ $loader->parse_string($xml1); | |
+ my $root = $loader->root_object; | |
+ isa_ok($root,'ABC::Root'); | |
+ ok($root->text eq 'test1', 'root node text was not loaded correctly'); | |
+}; | |
+ | |
+eval { | |
+ my $loader = XML::Toolkit::Loader->new($args); | |
+ $loader->parse_string($xml2); | |
+ my $root = $loader->root_object; | |
+ isa_ok($root,'ABC::Root'); | |
+ ok($root->text eq 'test2', 'root node text was not loaded correctly'); | |
+}; | |
diff --git a/t/03_3.namespaced_loading.t b/t/03_3.namespaced_loading.t | |
new file mode 100644 | |
index 0000000..494f874 | |
--- /dev/null | |
+++ b/t/03_3.namespaced_loading.t | |
@@ -0,0 +1,49 @@ | |
+#!/usr/bin/perl | |
+ | |
+use strict; | |
+use warnings; | |
+ | |
+use Test::More tests => 5; | |
+ | |
+use XML::Toolkit::Builder (); | |
+use XML::Toolkit::Loader (); | |
+ | |
+my $xml1 = '<root xmlns:a="a" xmlns:b="b"><a:one>oneA</a:one><b:one>twoB</b:one></root>'; | |
+my $xml2 = '<root xmlns:y="a" xmlns:z="b"><y:one>oneY</y:one><z:one>twoZ</z:one></root>'; | |
+ | |
+my $args={ | |
+ namespace_map => { | |
+ 'a' => 'A', | |
+ 'b' => 'B', | |
+ }, | |
+}; | |
+ | |
+my $root_class_name = 'MyApp::Root'; | |
+ | |
+eval { | |
+ my $builder = XML::Toolkit::Builder->new($args); | |
+ $builder->parse_string($xml2); | |
+ my $code = $builder->render(); | |
+ diag($code); | |
+ eval $code; | |
+ my $root = ABC::Root->new(); | |
+ isa_ok($root, $root_class_name); | |
+}; | |
+ | |
+eval { | |
+ my $loader = XML::Toolkit::Loader->new($args); | |
+ $loader->parse_string($xml1); | |
+ my $root = $loader->root_object; | |
+ isa_ok($root,$root_class_name); | |
+ # FIXME: Need to pull out the data here | |
+ #ok($root->text eq 'test1', 'root node text was not loaded correctly'); | |
+}; | |
+ | |
+eval { | |
+ my $loader = XML::Toolkit::Loader->new($args); | |
+ $loader->parse_string($xml2); | |
+ my $root = $loader->root_object; | |
+ isa_ok($root,$root_class_name); | |
+ # FIXME:: Need to pull out the data here | |
+ #ok($root->text eq 'test2', 'root node text was not loaded correctly'); | |
+}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment