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-document-element.rb < prev    next >
Text File  |  2001-03-15  |  1KB  |  53 lines

  1. require 'runit/testcase'
  2. require 'runit/cui/mytestrunner'
  3.  
  4. require 'rd/element'
  5. require 'rd/rd-struct'
  6.  
  7. include RD
  8.  
  9. class TestDocumentElement < RUNIT::TestCase
  10.   def setup
  11.     @p = DocumentElement.new
  12.     @c1 = Headline.new(1)
  13.     @c2 = TextBlock.new
  14.     @c3 = ItemList.new
  15.     @c31 = ItemListItem.new
  16.     @c311 = TextBlock.new
  17.     @c31.add_child_under_document_struct(@c311, DocumentStructure::RD)
  18.     @c3.add_child_under_document_struct(@c31, DocumentStructure::RD)
  19.     @p.add_children_under_document_struct([@c1, @c2, @c3],
  20.                         DocumentStructure::RD)
  21.   end
  22.   
  23.   def test_s_new
  24.     assert(DocumentElement.new)
  25.   end
  26.  
  27.   def test_blocks
  28.     assert_equal([@c1, @c2, @c3], @p.blocks)
  29.   end
  30.  
  31.   def test_each_block
  32.     i = 1
  33.     @p.each_block do |b|
  34.       assert_equal(eval("@c#{i}"), b)
  35.       i += 1
  36.     end
  37.   end
  38.  
  39.   def test_each_element
  40.     exp = [@p, @c1, @c2, @c3, @c31, @c311]
  41.     i = 0
  42.     @p.each_element do |b|
  43.       assert_equal(exp[i], b)
  44.       i += 1
  45.     end
  46.   end
  47. end
  48.  
  49. if $0 == __FILE__
  50.   suite = TestDocumentElement.suite
  51.   RUNIT::CUI::MyTestRunner.run(suite)
  52. end
  53.