| 1 | #! /usr/local/bin/ruby |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | require 'test/unit' |
|---|
| 5 | require 'rexml/document' |
|---|
| 6 | |
|---|
| 7 | class TestDoctype < 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 |
|---|