home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ruby164.zip / rbemx164.zip / ruby / share / doc / rdtool-0.6.10 / test / test-reference.rb < prev    next >
Text File  |  2001-06-06  |  4KB  |  141 lines

  1. require 'runit/testcase'
  2. require 'runit/cui/mytestrunner'
  3.  
  4. require 'rd/inline-element'
  5. require 'rd/document-struct'
  6. require 'rd/rd-struct'
  7. require 'rd/loose-struct'
  8. require 'test/dummy'
  9.  
  10. include RD
  11.  
  12. DummyStruct.define_relationship(Reference, DummyElement)
  13.  
  14. class TestReference < RUNIT::TestCase
  15.   def test_initialize
  16.     d1 = DummyElement.new
  17.     l = Reference::TemporaryLabel.new([d1])
  18.     ref = Reference.new_from_label_under_document_struct(l, DummyStruct)
  19.     assert_kind_of(Reference::RDLabel, ref.label)
  20.     assert_equal([d1], ref.instance_eval("children"))
  21.  
  22.     l2 = Reference::TemporaryLabel.new([d1], "filename")
  23.     ref = Reference.new_from_label_under_document_struct(l2, DummyStruct)
  24.     assert_kind_of(Reference::RDLabel, ref.label)
  25.     assert_equal([d1], ref.instance_eval("children"))
  26.     assert_equal("filename", ref.label.filename)
  27.  
  28.     l = Reference::RDLabel.new("label")
  29.     ref = Reference.new(l)
  30.     assert_kind_of(Reference::RDLabel, ref.label)
  31.     assert_equal([], ref.instance_eval("children"))
  32.  
  33.     url = Reference::URL.new("label")
  34.     ref2 = Reference.new_from_label_under_document_struct(url,
  35.                               DocumentStructure::RD)
  36.     assert_kind_of(Reference::URL, ref2.label)
  37.     assert_kind_of(StringElement, ref2.instance_eval("children")[0])
  38.     assert_equal("<URL:label>", ref2.instance_eval("children")[0].content)
  39.   end
  40.  
  41.   def test_s_new_from_label_without_document_struct
  42.     se = StringElement.new "string"
  43.     label = Reference::TemporaryLabel.new([se])
  44.     ref = Reference.new_from_label_without_document_struct(label)
  45.     assert_kind_of(Reference::RDLabel, ref.label)
  46.     assert_equal([se], ref.instance_eval("children"))
  47.   end
  48.   
  49.   def test_to_label_RDLabel
  50.     l = Reference::TemporaryLabel.new([DummyElement.new])
  51.     ref = Reference.new(l)
  52.     assert_equal("label", ref.to_label)
  53.   end
  54.  
  55.   def test_to_label_URL
  56.     l = Reference::URL.new "http://www.ruby-lang.org/"
  57.     ref = Reference.new l
  58.     assert_equal("", ref.to_label)
  59.   end
  60.  
  61.   def test_result_of_apply_method_of
  62.     visitor = DummyVisitor.new
  63.     label = Reference::RDLabel.new("label")
  64.     reference = Reference.new(label)
  65.     result = ["apply_to_Reference_with_RDLabel",
  66.       [reference, []]]
  67.     assert_equal(result, reference.result_of_apply_method_of(visitor, []))
  68.  
  69.     url = Reference::URL.new("url")
  70.     reference = Reference.new(url)
  71.     result = ["apply_to_Reference_with_URL",
  72.       [reference, []]]
  73.     assert_equal(result, reference.result_of_apply_method_of(visitor, []))
  74.   end
  75.  
  76.   def test_add_child
  77.     d1 = DummyElement.new
  78.     d2 = DummyElement.new
  79.     l = Reference::TemporaryLabel.new([d1])
  80.     ref = Reference.new_from_label_under_document_struct(l, DummyStruct)
  81.     ref.add_child_under_document_struct(d2, DummyStruct)
  82.     assert_equal(3, ref.to_a.size)
  83.     assert_equal("label", ref.label.element_label)
  84.   end
  85.  
  86.   def test_build
  87.     lb = Reference::RDLabel.new("label")
  88.     ref = Reference.new(lb).build(DocumentStructure::LOOSE) do
  89.       set_label(Reference::RDLabel.new("LABEL"))
  90.     end
  91.     assert_equal("LABEL", ref.to_label)
  92.   end
  93. end
  94.  
  95. class TestRDLabel < RUNIT::TestCase
  96.   def test_to_label
  97.     one = Reference::RDLabel.new("label")
  98.     assert_equal("label", one.to_label)
  99.     zero = Reference::RDLabel.new("")
  100.     assert_equal("", zero.to_label)
  101.     file = Reference::RDLabel.new("label", "filename")
  102.     assert_equal("label", file.to_label)
  103.   end
  104.  
  105.   def test_result_of_apply_method_of
  106.     visitor = DummyVisitor.new
  107.     label = Reference::RDLabel.new("label")
  108.     reference = Reference.new(label)
  109.     result = ["apply_to_Reference_with_RDLabel",
  110.       [reference, []]]
  111.     assert_equal(result, label.result_of_apply_method_of(visitor, reference,
  112.                              []))
  113.   end
  114. end
  115.  
  116. class TestURL < RUNIT::TestCase
  117.   def test_to_label
  118.     nor = Reference::URL.new "http://www.ruby-lang.org/"
  119.     assert_equal("", nor.to_label)
  120.     empty = Reference::URL.new ""
  121.     assert_equal("", empty.to_label)
  122.   end
  123.  
  124.   def test_result_of_apply_method_of
  125.     visitor = DummyVisitor.new
  126.     label = Reference::URL.new("label")
  127.     reference = Reference.new(label)
  128.     result = ["apply_to_Reference_with_URL",
  129.       [reference, []]]
  130.     assert_equal(result, label.result_of_apply_method_of(visitor, reference,
  131.                              []))
  132.   end
  133. end
  134.  
  135. if $0 == __FILE__
  136.   suite = TestReference.suite
  137.   suite.add_test(TestRDLabel.suite)
  138.   suite.add_test(TestURL.suite)
  139.   RUNIT::CUI::MyTestRunner.run(suite)
  140. end
  141.