~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rexml/test_doctype.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/local/bin/ruby
 
2
 
 
3
 
 
4
require 'test/unit'
 
5
require 'rexml/document'
 
6
 
 
7
class TestDocTypeAccessor < Test::Unit::TestCase
 
8
 
 
9
  def setup
 
10
    @sysid = "urn:x-test:sysid1"
 
11
    @notid1 = "urn:x-test:notation1"
 
12
    @notid2 = "urn:x-test:notation2"
 
13
    document_string1 = <<-"XMLEND"
 
14
    <!DOCTYPE r SYSTEM "#{@sysid}" [
 
15
      <!NOTATION n1 SYSTEM "#{@notid1}">
 
16
      <!NOTATION n2 SYSTEM "#{@notid2}">
 
17
    ]>
 
18
    <r/>
 
19
    XMLEND
 
20
    @doctype1 = REXML::Document.new(document_string1).doctype
 
21
 
 
22
    @pubid = "TEST_ID"
 
23
    document_string2 = <<-"XMLEND"
 
24
    <!DOCTYPE r PUBLIC "#{@pubid}">
 
25
    <r/>
 
26
    XMLEND
 
27
    @doctype2 = REXML::Document.new(document_string2).doctype
 
28
 
 
29
    document_string3 = <<-"XMLEND"
 
30
    <!DOCTYPE r PUBLIC "#{@pubid}" "#{@sysid}">
 
31
    <r/>
 
32
    XMLEND
 
33
    @doctype3 = REXML::Document.new(document_string3).doctype
 
34
 
 
35
  end
 
36
 
 
37
  def test_public
 
38
    assert_equal(nil, @doctype1.public)
 
39
    assert_equal(@pubid, @doctype2.public)
 
40
    assert_equal(@pubid, @doctype3.public)
 
41
  end
 
42
 
 
43
  def test_system
 
44
    assert_equal(@sysid, @doctype1.system)
 
45
    assert_equal(nil, @doctype2.system)
 
46
    assert_equal(@sysid, @doctype3.system)
 
47
  end
 
48
 
 
49
  def test_notation
 
50
    assert_equal(@notid1, @doctype1.notation("n1").system)
 
51
    assert_equal(@notid2, @doctype1.notation("n2").system)
 
52
  end
 
53
 
 
54
  def test_notations
 
55
    notations = @doctype1.notations
 
56
    assert_equal(2, notations.length)
 
57
    assert_equal(@notid1, find_notation(notations, "n1").system)
 
58
    assert_equal(@notid2, find_notation(notations, "n2").system)
 
59
  end
 
60
 
 
61
  def find_notation(notations, name)
 
62
    notations.find { |notation|
 
63
      name == notation.name
 
64
    }
 
65
  end
 
66
 
 
67
end
 
68
 
 
69
class TestNotationDeclPublic < Test::Unit::TestCase
 
70
  def setup
 
71
    @name = "vrml"
 
72
    @id = "VRML 1.0"
 
73
    @uri = "http://www.web3d.org/"
 
74
  end
 
75
 
 
76
  def test_to_s
 
77
    assert_equal("<!NOTATION #{@name} PUBLIC \"#{@id}\">",
 
78
                 decl(@id, nil).to_s)
 
79
  end
 
80
 
 
81
  def test_to_s_with_uri
 
82
    assert_equal("<!NOTATION #{@name} PUBLIC \"#{@id}\" \"#{@uri}\">",
 
83
                 decl(@id, @uri).to_s)
 
84
  end
 
85
 
 
86
  private
 
87
  def decl(id, uri)
 
88
    REXML::NotationDecl.new(@name, "PUBLIC", id, uri)
 
89
  end
 
90
end
 
91
 
 
92
class TestNotationDeclSystem < Test::Unit::TestCase
 
93
  def setup
 
94
    @name = "gif"
 
95
    @id = "gif viewer"
 
96
  end
 
97
 
 
98
  def test_to_s
 
99
    assert_equal("<!NOTATION #{@name} SYSTEM \"#{@id}\">",
 
100
                 decl(@id).to_s)
 
101
  end
 
102
 
 
103
  private
 
104
  def decl(id)
 
105
    REXML::NotationDecl.new(@name, "SYSTEM", id, nil)
 
106
  end
 
107
end