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-element.rb < prev    next >
Text File  |  2001-04-26  |  1KB  |  55 lines

  1. require 'runit/testcase'
  2. require 'runit/cui/mytestrunner'
  3. require 'runit/topublic'
  4.  
  5. require 'rd/tree'
  6. require 'rd/element'
  7. require 'rd/rd-struct'
  8.  
  9. include RD
  10.  
  11. class TestElement < RUNIT::TestCase
  12.   include RUNIT::ToPublic
  13.  
  14.   def setup
  15.     @tree = Tree.new_with_document_struct(DocumentStructure::RD)
  16.     @de = DocumentElement.new
  17.     @tree.root = @de
  18.     @tb = TextBlock.new
  19.     @de.add_child(@tb)
  20.  
  21.     @err = TextBlock.new
  22.   end
  23.  
  24.   def test_tree
  25.     assert_equal(@tree, @de.tree)
  26.     assert_equal(@tree, @tb.tree)
  27.     assert_exception(RuntimeError) do
  28.       @err.tree
  29.     end
  30.   end
  31.  
  32.   def test_inspect
  33.     assert_equal("<RD::TextBlock>", TextBlock.new.inspect)
  34.  
  35.     t = TextBlock.new
  36.     s = StringElement.new ""
  37.     t.add_child_under_document_struct(s, DocumentStructure::RD)
  38.     assert_equal("<RD::TextBlock>\n  <RD::StringElement>", t.inspect)
  39.  
  40.     t = TextBlock.new
  41.     e = Emphasis.new
  42.     s = StringElement.new ""
  43.     s2 = StringElement.new "a"
  44.     e.add_child_under_document_struct(s, DocumentStructure::RD)
  45.     t.add_children_under_document_struct([e, s2], DocumentStructure::RD)
  46.     exp = "<RD::TextBlock>\n  <RD::Emphasis>\n    <RD::StringElement>\n  <RD::StringElement>"
  47.     assert_equal(exp, t.inspect)
  48.   end
  49. end
  50.  
  51. if $0 == __FILE__
  52.   suite = TestElement.suite
  53.   RUNIT::CUI::MyTestRunner.run(suite)
  54. end
  55.