File: test-methodlist-item.rb

package info (click to toggle)
rdtool 0.6.22-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 724 kB
  • ctags: 1,162
  • sloc: ruby: 8,017; lisp: 347; makefile: 55; sh: 30
file content (73 lines) | stat: -rwxr-xr-x 2,549 bytes parent folder | download | duplicates (8)
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
67
68
69
70
71
72
73
require 'test/unit'

require 'rd/methodlist'
require 'rd/rd-struct'

include RD

class TestMethodListItem < Test::Unit::TestCase
  def test_set_term
    p = MethodListItem.new
    c = MethodListItem::Term.new
    p.set_term_under_document_struct(c, DocumentStructure::RD)
    assert_equal(c, p.term)
    assert_equal(p, c.parent)
  end

  def test_make_term
    tr = Tree.new_with_document_struct(DocumentStructure::RD)
    de = DocumentElement.new
    tr.root = de
    di, dt = nil
    de.build do
      new MethodList do
        di = new MethodListItem do
          dt = make_term
        end
      end
    end
    assert_equal("<RD::MethodListItem>\n  <RD::MethodListItem::Term>",
                 di.inspect)
    assert_equal(di.term, dt)
  end

  def test_inspect
    mi = MethodListItem.new
    mt = MethodListItem::Term.new
    se = StringElement.new "string"
    tb = TextBlock.new
    mi.set_term_under_document_struct(mt, DocumentStructure::RD)
    mi.add_child_under_document_struct(tb, DocumentStructure::RD)
    assert_equal("<RD::MethodListItem>\n  <RD::MethodListItem::Term>\n" +
                 "  <RD::TextBlock>", mi.inspect)
    
    mi_no_desc = MethodListItem.new
    mt_no_desc = MethodListItem::Term.new
    mi_no_desc.set_term_under_document_struct(mt_no_desc,
                                              DocumentStructure::RD)
    assert_equal("<RD::MethodListItem>\n  <RD::MethodListItem::Term>",
                 mi_no_desc.inspect)

    mi_no_term = MethodListItem.new
    mi_no_term.add_child_under_document_struct(TextBlock.new,
                                               DocumentStructure::RD)
    assert_equal("<RD::MethodListItem>\n  <RD::TextBlock>",
                 mi_no_term.inspect)
    assert_equal("<RD::MethodListItem>", MethodListItem.new.inspect)
  end

end

class TestMethodListItemTerm < Test::Unit::TestCase
  def test_to_label
    assert_equal("", MethodListItem::Term.new.to_label)
    assert_equal("foo", MethodListItem::Term.new("foo").to_label)
    assert_equal("foo", MethodListItem::Term.new("foo()").to_label)
    assert_equal("foo", MethodListItem::Term.new("foo(arg)").to_label)
    assert_equal("Foo#foo", MethodListItem::Term.new("Foo#foo(arg)").to_label)
    assert_equal("Foo::foo", MethodListItem::Term.new("Foo::foo(arg)").to_label)    
    assert_equal("foo", MethodListItem::Term.new("foo{|arg| ...}").to_label)
    assert_equal("foo", MethodListItem::Term.new("foo(arg){|arg| ...}").to_label)
    assert_equal("foo", MethodListItem::Term.new("foo  (arg)").to_label)
  end
end