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-struct.rb < prev    next >
Text File  |  2001-03-15  |  2KB  |  84 lines

  1. require 'runit/testcase'
  2. require 'runit/cui/mytestrunner'
  3. require 'runit/topublic'
  4.  
  5. require 'rd/document-struct.rb'
  6. require 'rd/rdfmt'
  7.  
  8. class TestDocumentStructure < RUNIT::TestCase
  9.   include RD
  10.  
  11.   def test_each_relationship
  12.     a = DocumentStructure.new
  13.     r1 = ElementRelationship.new(TextBlock, InlineElement)
  14.     r2 = ElementRelationship.new(DocumentElement, BlockElement)
  15.     r3 = ElementRelationship.new(ListItem, BlockElement)
  16.     r4 = ElementRelationship.new(ItemList, ItemListItem)
  17.     exp = [r1, r2, r3, r4]
  18.  
  19.     a.add_relationships(*exp)
  20.  
  21.     a.each_relationship do |i|
  22.       assert(exp.include?(i))
  23.       exp.delete(i)
  24.     end
  25.     assert_equal([], exp)
  26.   end
  27.  
  28.   def test_is_valid?
  29.     a = DocumentStructure.new
  30.     r1 = ElementRelationship.new(TextBlock, InlineElement)
  31.     r2 = ElementRelationship.new(DocumentElement, BlockElement)
  32.     r3 = ElementRelationship.new(ListItem, BlockElement)
  33.     r4 = ElementRelationship.new(ItemList, ItemListItem)
  34.     a.add_relationships(r1, r2, r3, r4)
  35.  
  36.     assert(a.is_valid?(TextBlock.new, Emphasis.new))
  37.     assert(a.is_valid?(DocumentElement.new, TextBlock.new))
  38.     assert(a.is_valid?(ItemList.new, ItemListItem.new))
  39.     assert_false(a.is_valid?(TextBlock.new, Headline.new(1)))
  40.     assert_false(a.is_valid?(ItemList.new, TextBlock.new))
  41.   end
  42. end
  43.  
  44. class TestElementRelationship < RUNIT::TestCase
  45.   include RUNIT::ToPublic
  46.   include RD
  47.  
  48.   def test_match?
  49.     a = ElementRelationship.new(TextBlock, InlineElement)
  50.     assert(a.match?(TextBlock.new, Emphasis.new))
  51.     assert_false(a.match?(TextBlock.new, Headline.new(1)))
  52.  
  53.     a = ElementRelationship.new(InlineElement, InlineElement)
  54.     assert(a.match?(Emphasis.new, Code.new))
  55.     assert_false(a.match?(Emphasis.new, Headline.new(1)))
  56.     
  57.     a = ElementRelationship.new(DocumentElement, BlockElement)
  58.     assert(a.match?(DocumentElement.new, Headline.new(1)))
  59.     assert_false(a.match?(DocumentElement.new, Emphasis.new))
  60.  
  61.     a = ElementRelationship.new(ItemList, ItemListItem)
  62.     assert(a.match?(ItemList.new, ItemListItem.new))
  63.     assert_false(a.match?(ItemList.new, TextBlock.new))
  64.   end
  65. end
  66.  
  67. def assert_false(cond)
  68.   assert_equal(false, cond)
  69. end
  70.  
  71.  
  72. if $0 == __FILE__
  73.   if ARGV.size == 0
  74.     suite = TestDocumentStructure.suite
  75.     suite.add_test(TestElementRelationship.suite)
  76.   else
  77.     suite = RUNIT::TestSuite.new
  78.     ARGV.each do |testmethod|
  79.       suite.add_test(TestDocumentStructure.new(testmethod))
  80.     end
  81.   end
  82.   RUNIT::CUI::MyTestRunner.run(suite)
  83. end
  84.