Class: REXMLTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/vendor/xmpp4r/test/tc_rexml.rb

Instance Method Summary collapse

Instance Method Details

#test_attribute_entitesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 49

def test_attribute_entites
  e = REXML::Element.new('e')
  e.attributes['x'] = '&'
  assert_equal('&', e.attributes['x'])
  e.attributes['x'] = '&'
  # bug in REXML 3.1.6 unescaped the ampersand
  # assert_equal('&', e.attributes['x'])
  # substituting a test that works with 3.1.5, 3.1.6, and 3.1.7
  assert_equal('&', e.attribute('x').to_s)
  e.attributes['x'] = '&nbsp'
  assert_equal('&nbsp', e.attributes['x'])
  e.attributes['x'] = ' '
  assert_equal(' ', e.attributes['x'])
end

#test_element_equal_simpleObject



76
77
78
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 76

def test_element_equal_simple
  assert_equal(REXML::Element.new('foo'), REXML::Element.new('foo'))
end

#test_element_equal_when_all_are_sameObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 84

def test_element_equal_when_all_are_same
  e1 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e1.attributes['a:bar'] = 'baz'
  e2 = REXML::Element.new('foo')
  e2.add_namespace('a', 'urn:test:foo')
  e2.attributes['a:bar'] = 'baz'

  assert_equal(e1, e2)
end

#test_element_not_equal_simpleObject



80
81
82
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 80

def test_element_not_equal_simple
  assert_not_equal(REXML::Element.new('foo'), REXML::Element.new('bar'))
end

#test_element_not_equal_when_attribute_name_differsObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 117

def test_element_not_equal_when_attribute_name_differs
  e1 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e1.attributes['a:bar'] = 'baz'
  e2 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e2.attributes['b:bar'] = 'baz'

  assert_not_equal(e1, e2)
end

#test_element_not_equal_when_attribute_value_differsObject



128
129
130
131
132
133
134
135
136
137
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 128

def test_element_not_equal_when_attribute_value_differs
  e1 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e1.attributes['a:bar'] = 'baz'
  e2 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e2.attributes['a:bar'] = 'bar'

  assert_not_equal(e1, e2)
end

#test_element_not_equal_when_namespace_name_differsObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 95

def test_element_not_equal_when_namespace_name_differs
  e1 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e1.attributes['a:bar'] = 'baz'
  e2 = REXML::Element.new('foo')
  e2.add_namespace('b', 'urn:test:foo')
  e2.attributes['a:bar'] = 'baz'

  assert_not_equal(e1, e2)
end

#test_element_not_equal_when_namespace_value_differsObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 106

def test_element_not_equal_when_namespace_value_differs
  e1 = REXML::Element.new('foo')
  e1.add_namespace('a', 'urn:test:foo')
  e1.attributes['a:bar'] = 'baz'
  e2 = REXML::Element.new('foo')
  e2.add_namespace('a', 'urn:test:bar')
  e2.attributes['a:bar'] = 'baz'

  assert_not_equal(e1, e2)
end

#test_normalizeObject



16
17
18
19
20
21
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 16

def test_normalize
  assert_equal('&', REXML::Text::normalize('&'))
  assert_equal('&', REXML::Text::normalize('&'))
  assert_equal('&', REXML::Text::normalize('&'))
  assert_equal(' ', REXML::Text::normalize(' '))
end

#test_passing_in_non_rexml_element_as_comparison_objectObject



71
72
73
74
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 71

def test_passing_in_non_rexml_element_as_comparison_object
  o = Object.new
  assert_not_equal(REXML::Element.new('foo'), o)
end

#test_passing_in_non_rexml_element_as_selfObject

test ‘==(o)’



66
67
68
69
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 66

def test_passing_in_non_rexml_element_as_self
  o = Object.new
  assert_not_equal(o, REXML::Element.new('foo'))
end

#test_simpleObject



9
10
11
12
13
14
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 9

def test_simple
  e = REXML::Element.new('e')
  assert_kind_of(REXML::Element, e)
  assert_nil(e.text)
  assert_nil(e.attributes['x'])
end

#test_text_entitiesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 31

def test_text_entities
  e = REXML::Element.new('e')
  e.text = '&'
  assert_equal('<e>&amp;</e>', e.to_s)
  e.text = '&amp;'
  assert_equal('<e>&amp;amp;</e>', e.to_s)
  e.text = '&nbsp'
  assert_equal('<e>&amp;nbsp</e>', e.to_s)
  e.text = '&nbsp;'
  assert_equal('<e>&amp;nbsp;</e>', e.to_s)
  e.text = '&<;'
  assert_equal('<e>&amp;&lt;;</e>', e.to_s)
  e.text = '<>"\''
  assert_equal('<e>&lt;&gt;&quot;&apos;</e>', e.to_s)
  e.text = '<x>&amp;</x>'
  assert_equal('<e>&lt;x&gt;&amp;amp;&lt;/x&gt;</e>', e.to_s)
end

#test_unnormalizeObject



23
24
25
26
27
28
29
# File 'lib/vendor/xmpp4r/test/tc_rexml.rb', line 23

def test_unnormalize
  assert_equal('&', REXML::Text::unnormalize('&amp;'))
  assert_equal('&amp;', REXML::Text::unnormalize('&amp;amp;'))
  assert_equal('&amp;amp;', REXML::Text::unnormalize('&amp;amp;amp;'))
  assert_equal('&nbsp;', REXML::Text::unnormalize('&amp;nbsp;'))
  assert_equal('&nbsp;', REXML::Text::unnormalize('&nbsp;'))  # ?
end