Anonymous avatar Anonymous committed c02ab6c

Modified Files:
t/01basic.t
- encoding tests

Added Files:
t/19encoding.t
tests manual and magic string encoding.

Comments (0)

Files changed (2)

 use Test;
-BEGIN { plan tests => 4 }
+BEGIN { plan tests => 2}
 END { ok(0) unless $loaded }
 use XML::LibXML;
 $loaded = 1;
 my $p = XML::LibXML->new();
 ok($p);
 
-# encoding tests
-my $tstr1 = "test";
-my $tstr2 = "täst";
-
-ok( decodeFromUTF8( 'UTF-8' , encodeToUTF8('UTF-8', $tstr1 ) ) eq $tstr1 );
-ok( decodeFromUTF8( 'iso-8859-1' , encodeToUTF8('iso-8859-1', $tstr2 ) ), $tstr2 );
 # warn "# $tstr2\n";
+use Test;
+BEGIN { plan tests => 17 }
+END { ok(0) unless $loaded }
+use XML::LibXML;
+$loaded = 1;
+ok(1);
+
+my $p = XML::LibXML->new();
+ok($p);
+
+# encoding tests
+# ok there is the UTF16 test still missing
+
+my $tstr_utf8       = 'test';
+my $tstr_iso_latin1 = 'täst';
+my $tstr_euc_jp     = 'Ŕ¸ÇţŔ¸ĘĆŔ¸Íń';
+
+my $domstrlat1 = q{<?xml version="1.0" encoding="iso-8859-1"?>
+<täst>täst</täst>
+};
+my $domstrjp = q{<?xml version="1.0" encoding="EUC-JP"?>
+<Ŕ¸ÇţŔ¸ĘĆŔ¸Íń>Ŕ¸ÇţŔ¸ĘĆŔ¸Íń</Ŕ¸ÇţŔ¸ĘĆŔ¸Íń>
+};
+
+# simple encoding interface
+
+ok( decodeFromUTF8( 'UTF-8' , encodeToUTF8('UTF-8', $tstr_utf8 ) ),
+    $tstr_utf8 );
+
+ok( decodeFromUTF8( 'iso-8859-1' , encodeToUTF8('iso-8859-1', $tstr_iso_latin1 ) ),
+    $tstr_iso_latin1 );
+
+ok( decodeFromUTF8( 'EUC-JP' , encodeToUTF8('EUC-JP', $tstr_euc_jp ) ),
+    $tstr_euc_jp );
+
+# magic encoding
+
+my $dom_latin1 = XML::LibXML::Document->new('1.0', 'iso-8859-1');
+my $elemlat1 = $dom_latin1->createElement( $tstr_iso_latin1 );
+
+ok( decodeFromUTF8( 'iso-8859-1' ,$elemlat1->nodeName()), $tstr_iso_latin1 );
+
+$dom_latin1->setDocumentElement( $elemlat1 );
+
+my $dom_euc_jp = XML::LibXML::Document->new('1.0', 'EUC-JP');
+$elemjp = $dom_euc_jp->createElement( $tstr_euc_jp );
+
+ok( decodeFromUTF8( 'EUC-JP' ,$elemjp->nodeName()), $tstr_euc_jp );
+
+$dom_euc_jp->setDocumentElement( $elemjp );
+
+# "magic" decoding 
+
+ok( decodeFromUTF8( 'iso-8859-1' ,$elemlat1->toString()), "<$tstr_iso_latin1/>");
+ok( decodeFromUTF8( 'EUC-JP' ,$elemjp->toString()), "<$tstr_euc_jp/>");
+
+ok( $elemlat1->toString(1), "<$tstr_iso_latin1/>");
+ok( $elemjp->toString(1), "<$tstr_euc_jp/>");
+
+$elemlat1->appendText( $tstr_iso_latin1 );
+$elemjp->appendText( $tstr_euc_jp );
+
+ok( decodeFromUTF8( 'iso-8859-1' ,$elemlat1->string_value()), $tstr_iso_latin1);
+ok( decodeFromUTF8( 'EUC-JP' ,$elemjp->string_value()), $tstr_euc_jp);
+
+ok( $elemlat1->string_value(1), $tstr_iso_latin1);
+ok( $elemjp->string_value(1), $tstr_euc_jp);
+
+ok( $dom_latin1->toString(), $domstrlat1 );
+ok( $dom_euc_jp->toString(), $domstrjp );
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.