Class: StreamParserTest

Inherits:
Test::Unit::TestCase show all
Defined in:
lib/gems/xmpp4r-0.4/test/tc_streamparser.rb

Constant Summary collapse

STREAM =
'<stream:stream xmlns:stream="http://etherx.jabber.org/streams">'

Instance Method Summary collapse

Methods inherited from Test::Unit::TestCase

#assert_array_equal, expect, #run

Instance Method Details

#parse_simple_helper(fixture) {|parse_with_rexml(fixture)| ... } ⇒ Object

Yields:



35
36
37
38
39
40
41
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 35

def parse_simple_helper(fixture)
  parser = StreamParser.new(STREAM + fixture, @listener)

  parser.parse

  yield parse_with_rexml(fixture)
end

#parse_with_rexml(fixture) ⇒ Object



43
44
45
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 43

def parse_with_rexml(fixture)
  REXML::Document.new(fixture).root
end

#setupObject



27
28
29
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 27

def setup
  @listener = MockListener.new
end

#teardownObject



31
32
33
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 31

def teardown
  @listener = nil
end

#test_complex_composite_cdata_textObject



79
80
81
82
83
84
85
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 79

def test_complex_composite_cdata_text
  parse_simple_helper( "<a><![CDATA[<cdata>]]>text<![CDATA[<cdata>]]>text</a>" ) do |desired|
    assert_equal desired.name, @listener.received.name
    assert_equal desired.text, @listener.received.text
    assert_equal desired.cdatas, @listener.received.cdatas
  end
end

#test_composite_cdata_textObject



71
72
73
74
75
76
77
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 71

def test_composite_cdata_text
  parse_simple_helper( "<a><![CDATA[<cdata>]]>text</a>" ) do |desired|
    assert_equal desired.name, @listener.received.name
    assert_equal desired.text, @listener.received.text
    assert_equal desired.cdatas, @listener.received.cdatas
  end
end

#test_composite_text_cdataObject



63
64
65
66
67
68
69
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 63

def test_composite_text_cdata
  parse_simple_helper( "<a>text<![CDATA[<cdata>]]></a>" ) do |desired|
    assert_equal desired.name, @listener.received.name
    assert_equal desired.text, @listener.received.text
    assert_equal desired.cdatas, @listener.received.cdatas
  end
end

#test_entity_escaping1Object



87
88
89
90
91
92
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 87

def test_entity_escaping1
  parse_simple_helper( "<a>&apos;&amp;&quot;</a>" ) do |desired|
    assert_equal "'&\"", @listener.received.text
    assert_equal "<a>&apos;&amp;&quot;</a>", @listener.received.to_s
  end
end

#test_entity_escaping2Object



94
95
96
97
98
99
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 94

def test_entity_escaping2
  parse_simple_helper( "<a>&amp;amp;amp;</a>" ) do |desired|
    assert_equal "&amp;amp;", @listener.received.text
    assert_equal "<a>&amp;amp;amp;</a>", @listener.received.to_s
  end
end

#test_simple_cdataObject



55
56
57
58
59
60
61
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 55

def test_simple_cdata
  parse_simple_helper( "<a><![CDATA[<cdata>]]></a>" ) do |desired|
    assert_equal desired.name, @listener.received.name
    assert_equal desired.text, @listener.received.text
    assert_equal desired.cdatas, @listener.received.cdatas
  end
end

#test_simple_textObject



47
48
49
50
51
52
53
# File 'lib/gems/xmpp4r-0.4/test/tc_streamparser.rb', line 47

def test_simple_text
  parse_simple_helper( "<a>text</a>" ) do |desired|
    assert_equal desired.name, @listener.received.name
    assert_equal desired.text, @listener.received.text
    assert_equal desired.cdatas, @listener.received.cdatas
  end
end