diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-27 13:10:55 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-27 13:10:55 +0000 |
commit | ba3d2f4ac20bec871fe96a393d923d0cbb0fd96a (patch) | |
tree | 897a0308607db1dad21eef1fee86b351e93ebfa5 /test/rexml/test_encoding.rb | |
parent | 313fa180333a1eb4d1fa1542930e83f8d77e6b2d (diff) | |
download | ruby-ba3d2f4ac20bec871fe96a393d923d0cbb0fd96a.tar.gz |
* test/rexml/test_contrib.rb: Indent.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rexml/test_encoding.rb')
-rw-r--r-- | test/rexml/test_encoding.rb | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/test/rexml/test_encoding.rb b/test/rexml/test_encoding.rb index a08406782c..8205d0f366 100644 --- a/test/rexml/test_encoding.rb +++ b/test/rexml/test_encoding.rb @@ -6,91 +6,91 @@ require 'rexml/source' require 'rexml/document' module REXMLTests -class EncodingTester < Test::Unit::TestCase - include REXMLTestUtils - include REXML + class EncodingTester < Test::Unit::TestCase + include REXMLTestUtils + include REXML - def setup - @encoded_root = "<a><b>\346</b></a>" - @encoded = "<?xml version='1.0' encoding='ISO-8859-3'?>"+ - @encoded_root - @not_encoded = "<a><b>ĉ</b></a>" - end + def setup + @encoded_root = "<a><b>\346</b></a>" + @encoded = "<?xml version='1.0' encoding='ISO-8859-3'?>"+ + @encoded_root + @not_encoded = "<a><b>ĉ</b></a>" + end - # Given an encoded document, try to write out to that encoding - def test_encoded_in_encoded_out - doc = Document.new( @encoded ) - doc.write( out="" ) - out.force_encoding(::Encoding::ASCII_8BIT) - assert_equal( @encoded, out ) - end + # Given an encoded document, try to write out to that encoding + def test_encoded_in_encoded_out + doc = Document.new( @encoded ) + doc.write( out="" ) + out.force_encoding(::Encoding::ASCII_8BIT) + assert_equal( @encoded, out ) + end - # Given an encoded document, try to change the encoding and write it out - def test_encoded_in_change_out - doc = Document.new( @encoded ) - doc.xml_decl.encoding = "UTF-8" - assert_equal("UTF-8", doc.encoding) - REXML::Formatters::Default.new.write( doc.root, out="" ) - out.force_encoding(::Encoding::ASCII_8BIT) - assert_equal( @not_encoded, out ) - char = XPath.first( doc, "/a/b/text()" ).to_s - char.force_encoding(::Encoding::ASCII_8BIT) - assert_equal( "ĉ", char ) - end + # Given an encoded document, try to change the encoding and write it out + def test_encoded_in_change_out + doc = Document.new( @encoded ) + doc.xml_decl.encoding = "UTF-8" + assert_equal("UTF-8", doc.encoding) + REXML::Formatters::Default.new.write( doc.root, out="" ) + out.force_encoding(::Encoding::ASCII_8BIT) + assert_equal( @not_encoded, out ) + char = XPath.first( doc, "/a/b/text()" ).to_s + char.force_encoding(::Encoding::ASCII_8BIT) + assert_equal( "ĉ", char ) + end - # * Given an encoded document, try to write it to a different encoding - def test_encoded_in_different_out - doc = Document.new( @encoded ) - REXML::Formatters::Default.new.write( doc.root, Output.new( out="", "UTF-8" ) ) - out.force_encoding(::Encoding::ASCII_8BIT) - assert_equal( @not_encoded, out ) - end + # * Given an encoded document, try to write it to a different encoding + def test_encoded_in_different_out + doc = Document.new( @encoded ) + REXML::Formatters::Default.new.write( doc.root, Output.new( out="", "UTF-8" ) ) + out.force_encoding(::Encoding::ASCII_8BIT) + assert_equal( @not_encoded, out ) + end - # * Given a non-encoded document, change the encoding - def test_in_change_out - doc = Document.new( @not_encoded ) - doc.xml_decl.encoding = "ISO-8859-3" - assert_equal("ISO-8859-3", doc.encoding) - doc.write( out="" ) - out.force_encoding(::Encoding::ASCII_8BIT) - assert_equal( @encoded, out ) - end + # * Given a non-encoded document, change the encoding + def test_in_change_out + doc = Document.new( @not_encoded ) + doc.xml_decl.encoding = "ISO-8859-3" + assert_equal("ISO-8859-3", doc.encoding) + doc.write( out="" ) + out.force_encoding(::Encoding::ASCII_8BIT) + assert_equal( @encoded, out ) + end - # * Given a non-encoded document, write to a different encoding - def test_in_different_out - doc = Document.new( @not_encoded ) - doc.write( Output.new( out="", "ISO-8859-3" ) ) - out.force_encoding(::Encoding::ASCII_8BIT) - assert_equal( "<?xml version='1.0'?>#{@encoded_root}", out ) - end + # * Given a non-encoded document, write to a different encoding + def test_in_different_out + doc = Document.new( @not_encoded ) + doc.write( Output.new( out="", "ISO-8859-3" ) ) + out.force_encoding(::Encoding::ASCII_8BIT) + assert_equal( "<?xml version='1.0'?>#{@encoded_root}", out ) + end - # * Given an encoded document, accessing text and attribute nodes - # should provide UTF-8 text. - def test_in_different_access - doc = Document.new <<-EOL - <?xml version='1.0' encoding='ISO-8859-1'?> - <a a="\xFF">\xFF</a> - EOL - expect = "\303\277" - expect.force_encoding(::Encoding::UTF_8) - assert_equal( expect, doc.elements['a'].attributes['a'] ) - assert_equal( expect, doc.elements['a'].text ) - end + # * Given an encoded document, accessing text and attribute nodes + # should provide UTF-8 text. + def test_in_different_access + doc = Document.new <<-EOL + <?xml version='1.0' encoding='ISO-8859-1'?> + <a a="\xFF">\xFF</a> + EOL + expect = "\303\277" + expect.force_encoding(::Encoding::UTF_8) + assert_equal( expect, doc.elements['a'].attributes['a'] ) + assert_equal( expect, doc.elements['a'].text ) + end - def test_ticket_89 - doc = Document.new <<-EOL - <?xml version="1.0" encoding="CP-1252" ?> - <xml><foo></foo></xml> - EOL + def test_ticket_89 + doc = Document.new <<-EOL + <?xml version="1.0" encoding="CP-1252" ?> + <xml><foo></foo></xml> + EOL - REXML::Document.new doc - end + REXML::Document.new doc + end - def test_ticket_110 - utf16 = REXML::Document.new(File.new(fixture_path("ticket_110_utf16.xml"))) - assert_equal(utf16.encoding, "UTF-16") - assert( utf16[0].kind_of?(REXML::XMLDecl)) + def test_ticket_110 + utf16 = REXML::Document.new(File.new(fixture_path("ticket_110_utf16.xml"))) + assert_equal(utf16.encoding, "UTF-16") + assert( utf16[0].kind_of?(REXML::XMLDecl)) + end end end -end |