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-inline-parser.rb < prev    next >
Text File  |  2001-05-17  |  2KB  |  54 lines

  1. require 'runit/testcase'
  2. require 'runit/cui/mytestrunner'
  3. require 'runit/topublic'
  4.  
  5. require 'rd/rdinlineparser.tab'
  6. require 'rd/rd-struct'
  7.  
  8. include RD
  9.  
  10. class TestInlineParser < RUNIT::TestCase
  11.   include RUNIT::ToPublic
  12.   def setup
  13.     @block_parser = to_public(RDParser).new
  14.     @tree = tree = Tree.new_with_document_struct(DocumentStructure::RD)
  15.     @block_parser.instance_eval do
  16.       @tree = tree
  17.     end
  18.  
  19.     @inline_parser = to_public(RDInlineParser).new(@block_parser)
  20.   end
  21.  
  22.   def test_tree
  23.     assert_equal(@tree, @inline_parser.tree)
  24.   end
  25.  
  26.   def test_make_reference_from_label
  27.     label = Reference::TemporaryLabel.new([StringElement.new("label")])
  28.     expect = Reference.new_from_label_under_document_struct(label,
  29.             DocumentStructure::RD)
  30.     ref = @inline_parser.make_reference_from_label(label)
  31.     assert_equal(expect.label.element_label, ref.label.element_label)
  32.     assert_equal(expect.label.filename, ref.label.filename)
  33.   end
  34.  
  35.   def test_prev_words_on_error
  36.     @inline_parser.instance_eval{@pre="foo bar baz"}
  37.     assert_equal("foo bar baz", @inline_parser.prev_words_on_error("foo"))
  38.     assert_equal("foo bar ", @inline_parser.prev_words_on_error("baz"))
  39.     assert_equal("foo bar baz", @inline_parser.prev_words_on_error(false))
  40.     assert_equal("foo bar baz", @inline_parser.prev_words_on_error("not exist"))
  41.     @inline_parser.instance_eval{@pre="foo bar\nfoo2 bar2"}
  42.     assert_equal("foo2 bar2", @inline_parser.prev_words_on_error("foo2"))
  43.     assert_equal("foo2 ", @inline_parser.prev_words_on_error("bar2"))
  44.  
  45.     @inline_parser.instance_eval{@pre="foo?"}
  46.     assert_equal("foo", @inline_parser.prev_words_on_error("?"))
  47.   end
  48. end
  49.  
  50. if $0 == __FILE__
  51.   RUNIT::CUI::MyTestRunner.run(TestInlineParser.suite)
  52. end
  53.  
  54.