Created
February 28, 2011 20:38
-
-
Save fabrizioc1/847984 to your computer and use it in GitHub Desktop.
A test case to check how libxml-ruby handles ruby 1.9 string encodings
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
# encoding: UTF-8 | |
require 'xml' | |
require 'test/unit' | |
class EncodingTest < Test::Unit::TestCase | |
def setup() | |
@xml = <<-EOS | |
<?xml version='1.0' encoding='UTF-8'?> | |
<test> | |
<ascii>Hello World!</ascii> | |
<unicode>Fran\u1e09ais</unicode> | |
</test> | |
EOS | |
xp = XML::Parser.string(@xml, :encoding=>XML::Encoding::UTF_8) | |
@doc = xp.parse | |
end | |
def teardown | |
@doc = nil | |
end | |
def test_document_encoding_is_utf8 | |
assert_equal(@doc.encoding,XML::Encoding::UTF_8,"Document encoding should be UTF_8") | |
end | |
def test_input_xml_is_utf8 | |
assert_equal(@xml.encoding.name,'UTF-8',"Input XML string encoding should be UTF-8") | |
assert(@xml.valid_encoding?,"Input XML string encoding should be valid") | |
end | |
def test_parsed_unicode_element_is_utf8 | |
unicode_string = @doc.find('/test/unicode').find.first.content | |
assert_equal(unicode_string.encoding.name,'UTF-8',"Parsed 'unicode' element content should be UTF-8") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the output when I run the test case: