File: test-document-struct.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 (66 lines) | stat: -rwxr-xr-x 2,084 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'test/unit'

require 'rd/document-struct.rb'
require 'rd/rdfmt'

class TestDocumentStructure < Test::Unit::TestCase
  include RD

  def test_each_relationship
    a = DocumentStructure.new
    r1 = ElementRelationship.new(TextBlock, InlineElement)
    r2 = ElementRelationship.new(DocumentElement, BlockElement)
    r3 = ElementRelationship.new(ListItem, BlockElement)
    r4 = ElementRelationship.new(ItemList, ItemListItem)
    exp = [r1, r2, r3, r4]

    a.add_relationships(*exp)

    a.each_relationship do |i|
      assert(exp.include?(i))
      exp.delete(i)
    end
    assert_equal([], exp)
  end

  def test_is_valid?
    a = DocumentStructure.new
    r1 = ElementRelationship.new(TextBlock, InlineElement)
    r2 = ElementRelationship.new(DocumentElement, BlockElement)
    r3 = ElementRelationship.new(ListItem, BlockElement)
    r4 = ElementRelationship.new(ItemList, ItemListItem)
    a.add_relationships(r1, r2, r3, r4)

    assert(a.is_valid?(TextBlock.new, Emphasis.new))
    assert(a.is_valid?(DocumentElement.new, TextBlock.new))
    assert(a.is_valid?(ItemList.new, ItemListItem.new))
    assert_false(a.is_valid?(TextBlock.new, Headline.new(1)))
    assert_false(a.is_valid?(ItemList.new, TextBlock.new))
  end
end

class TestElementRelationship < Test::Unit::TestCase
  include RD

  def test_match?
    a = ElementRelationship.new(TextBlock, InlineElement)
    assert(a.match?(TextBlock.new, Emphasis.new))
    assert_false(a.match?(TextBlock.new, Headline.new(1)))

    a = ElementRelationship.new(InlineElement, InlineElement)
    assert(a.match?(Emphasis.new, Code.new))
    assert_false(a.match?(Emphasis.new, Headline.new(1)))
    
    a = ElementRelationship.new(DocumentElement, BlockElement)
    assert(a.match?(DocumentElement.new, Headline.new(1)))
    assert_false(a.match?(DocumentElement.new, Emphasis.new))

    a = ElementRelationship.new(ItemList, ItemListItem)
    assert(a.match?(ItemList.new, ItemListItem.new))
    assert_false(a.match?(ItemList.new, TextBlock.new))
  end
end

def assert_false(cond)
  assert_equal(false, cond)
end