File: test-element.rb

package info (click to toggle)
rdtool 0.6.38-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 940 kB
  • sloc: ruby: 8,213; lisp: 387; sh: 33; makefile: 16
file content (46 lines) | stat: -rwxr-xr-x 1,138 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'test/unit'

require 'rd/tree'
require 'rd/element'
require 'rd/rd-struct'

include RD

class TestElement < Test::Unit::TestCase

  def setup
    @tree = Tree.new_with_document_struct(DocumentStructure::RD)
    @de = DocumentElement.new
    @tree.root = @de
    @tb = TextBlock.new
    @de.add_child(@tb)

    @err = TextBlock.new
  end

  def test_tree
    assert_equal(@tree, @de.tree)
    assert_equal(@tree, @tb.tree)
    assert_raises(RuntimeError) do
      @err.tree
    end
  end

  def test_inspect
    assert_equal("<RD::TextBlock>", TextBlock.new.inspect)

    t = TextBlock.new
    s = StringElement.new ""
    t.add_child_under_document_struct(s, DocumentStructure::RD)
    assert_equal("<RD::TextBlock>\n  <RD::StringElement>", t.inspect)

    t = TextBlock.new
    e = Emphasis.new
    s = StringElement.new ""
    s2 = StringElement.new "a"
    e.add_child_under_document_struct(s, DocumentStructure::RD)
    t.add_children_under_document_struct([e, s2], DocumentStructure::RD)
    exp = "<RD::TextBlock>\n  <RD::Emphasis>\n    <RD::StringElement>\n  <RD::StringElement>"
    assert_equal(exp, t.inspect)
  end
end