#!/usr/bin/ruby $:.unshift '../lib' require 'test/unit' require 'xmpp4r/rexmladdons' class REXMLTest < Test::Unit::TestCase def test_simple e = REXML::Element.new('e') assert_kind_of(REXML::Element, e) assert_nil(e.text) assert_nil(e.attributes['x']) end def test_normalize assert_equal('&', REXML::Text::normalize('&')) assert_equal('&amp;', REXML::Text::normalize('&')) assert_equal('&amp;amp;', REXML::Text::normalize('&amp;')) assert_equal('&nbsp;', REXML::Text::normalize(' ')) end def test_unnormalize assert_equal('&', REXML::Text::unnormalize('&')) assert_equal('&', REXML::Text::unnormalize('&amp;')) assert_equal('&amp;', REXML::Text::unnormalize('&amp;amp;')) assert_equal(' ', REXML::Text::unnormalize('&nbsp;')) assert_equal(' ', REXML::Text::unnormalize(' ')) # ? end def test_text_entities e = REXML::Element.new('e') e.text = '&' assert_equal('&', e.to_s) e.text = '&' assert_equal('&amp;', e.to_s) e.text = ' ' assert_equal('&nbsp', e.to_s) e.text = ' ' assert_equal('&nbsp;', e.to_s) e.text = '&<;' assert_equal('&<;', e.to_s) e.text = '<>"\'' assert_equal('<>"'', e.to_s) e.text = '&' assert_equal('<x>&amp;</x>', e.to_s) end def test_attribute_entites e = REXML::Element.new('e') e.attributes['x'] = '&' assert_equal('&', e.attributes['x']) e.attributes['x'] = '&' assert_equal('&', e.attributes['x']) e.attributes['x'] = ' ' assert_equal(' ', e.attributes['x']) e.attributes['x'] = ' ' assert_equal(' ', e.attributes['x']) end end