Sha256: 5bb5bb81078f4c3ae8d3499ae433f63ba67327016b781d3ab16a763bb1a0f25c
Contents?: true
Size: 1.98 KB
Versions: 4
Compression:
Stored size: 1.98 KB
Contents
# encoding: UTF-8 require './test_helper' class TestTextNode < Minitest::Test def test_content node = XML::Node.new_text('testdata') assert_instance_of(XML::Node, node) assert_equal('testdata', node.content) end def test_invalid_content error = assert_raises(TypeError) do node = XML::Node.new_text(nil) end assert_equal('wrong argument type nil (expected String)', error.to_s) end # We use the same facility that libXSLT does here to disable output escaping. # This lets you specify that the node's content should be rendered unaltered # whenever it is being output. This is useful for things like <script> and # <style> nodes in HTML documents if you don't want to be forced to wrap them # in CDATA nodes. Or if you are sanitizing existing HTML documents and want # to preserve the content of any of the text nodes. # def test_output_escaping textnoenc = 'if (a < b || c > d) return "e";' text = "if (a < b || c > d) return \"e\";" node = XML::Node.new_text(textnoenc) assert node.output_escaping? assert_equal text, node.to_s node.output_escaping = false assert_equal textnoenc, node.to_s node.output_escaping = true assert_equal text, node.to_s node.output_escaping = nil assert_equal textnoenc, node.to_s node.output_escaping = true assert_equal text, node.to_s end # Just a sanity check for output escaping. def test_output_escaping_sanity node = XML::Node.new_text('testdata') assert_equal 'text', node.name assert node.output_escaping? node.output_escaping = false assert_equal 'textnoenc', node.name assert ! node.output_escaping? node.output_escaping = true assert_equal 'text', node.name assert node.output_escaping? node.output_escaping = nil assert_equal 'textnoenc', node.name assert ! node.output_escaping? node.output_escaping = true assert_equal 'text', node.name assert node.output_escaping? end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
libxml-ruby-3.0.0-x64-mingw32 | test/tc_node_text.rb |
libxml-ruby-3.0.0 | test/tc_node_text.rb |
libxml-ruby-2.9.0-x64-mingw32 | test/tc_node_text.rb |
libxml-ruby-2.9.0 | test/tc_node_text.rb |