~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to test/rdoc/test_rdoc_markup_attribute_manager.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-16 12:37:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080516123706-r4llcdfd35aobrjv
Tags: 1.9.0.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.
* debian/control:
  - ruby1.9 pkg: moved rdoc1.9 suggestion to depends. (LP: #228345)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require "test/unit"
 
2
require "rdoc/markup/inline"
 
3
 
 
4
class TestRDocMarkupAttributeManager < Test::Unit::TestCase
 
5
 
 
6
  def setup
 
7
    @am = RDoc::Markup::AttributeManager.new
 
8
 
 
9
    @bold_on  = @am.changed_attribute_by_name([], [:BOLD])
 
10
    @bold_off = @am.changed_attribute_by_name([:BOLD], [])
 
11
 
 
12
    @tt_on    = @am.changed_attribute_by_name([], [:TT])
 
13
    @tt_off   = @am.changed_attribute_by_name([:TT], [])
 
14
 
 
15
    @em_on    = @am.changed_attribute_by_name([], [:EM])
 
16
    @em_off   = @am.changed_attribute_by_name([:EM], [])
 
17
 
 
18
    @bold_em_on   = @am.changed_attribute_by_name([], [:BOLD] | [:EM])
 
19
    @bold_em_off  = @am.changed_attribute_by_name([:BOLD] | [:EM], [])
 
20
 
 
21
    @em_then_bold = @am.changed_attribute_by_name([:EM], [:EM] | [:BOLD])
 
22
 
 
23
    @em_to_bold   = @am.changed_attribute_by_name([:EM], [:BOLD])
 
24
 
 
25
    @am.add_word_pair("{", "}", :WOMBAT)
 
26
    @wombat_on    = @am.changed_attribute_by_name([], [:WOMBAT])
 
27
    @wombat_off   = @am.changed_attribute_by_name([:WOMBAT], [])
 
28
  end
 
29
 
 
30
  def crossref(text)
 
31
    crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
 
32
                      RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
 
33
 
 
34
    [ @am.changed_attribute_by_name([], [:CROSSREF, :_SPECIAL_]),
 
35
      RDoc::Markup::Special.new(crossref_bitmap, text),
 
36
      @am.changed_attribute_by_name([:CROSSREF, :_SPECIAL_], [])
 
37
    ]
 
38
  end
 
39
 
 
40
  def test_adding
 
41
    assert_equal(["cat ", @wombat_on, "and", @wombat_off, " dog" ],
 
42
                  @am.flow("cat {and} dog"))
 
43
    #assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
 
44
  end
 
45
 
 
46
  def test_basic
 
47
    assert_equal(["cat"], @am.flow("cat"))
 
48
 
 
49
    assert_equal(["cat ", @bold_on, "and", @bold_off, " dog"],
 
50
                  @am.flow("cat *and* dog"))
 
51
 
 
52
    assert_equal(["cat ", @bold_on, "AND", @bold_off, " dog"],
 
53
                  @am.flow("cat *AND* dog"))
 
54
 
 
55
    assert_equal(["cat ", @em_on, "And", @em_off, " dog"],
 
56
                  @am.flow("cat _And_ dog"))
 
57
 
 
58
    assert_equal(["cat *and dog*"], @am.flow("cat *and dog*"))
 
59
 
 
60
    assert_equal(["*cat and* dog"], @am.flow("*cat and* dog"))
 
61
 
 
62
    assert_equal(["cat *and ", @bold_on, "dog", @bold_off],
 
63
                  @am.flow("cat *and *dog*"))
 
64
 
 
65
    assert_equal(["cat ", @em_on, "and", @em_off, " dog"],
 
66
                  @am.flow("cat _and_ dog"))
 
67
 
 
68
    assert_equal(["cat_and_dog"],
 
69
                  @am.flow("cat_and_dog"))
 
70
 
 
71
    assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"],
 
72
                  @am.flow("cat +and+ dog"))
 
73
 
 
74
    assert_equal(["cat ", @bold_on, "a_b_c", @bold_off, " dog"],
 
75
                  @am.flow("cat *a_b_c* dog"))
 
76
 
 
77
    assert_equal(["cat __ dog"],
 
78
                  @am.flow("cat __ dog"))
 
79
 
 
80
    assert_equal(["cat ", @em_on, "_", @em_off, " dog"],
 
81
                  @am.flow("cat ___ dog"))
 
82
 
 
83
  end
 
84
 
 
85
  def test_bold
 
86
    assert_equal [@bold_on, 'bold', @bold_off],
 
87
                 @am.flow("*bold*")
 
88
 
 
89
    assert_equal [@bold_on, 'Bold:', @bold_off],
 
90
                 @am.flow("*Bold:*")
 
91
 
 
92
    assert_equal [@bold_on, '\\bold', @bold_off],
 
93
                 @am.flow("*\\bold*")
 
94
  end
 
95
 
 
96
  def test_combined
 
97
    assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
 
98
                  @am.flow("cat _and_ *dog*"))
 
99
 
 
100
    assert_equal(["cat ", @em_on, "a__nd", @em_off, " ", @bold_on, "dog", @bold_off],
 
101
                  @am.flow("cat _a__nd_ *dog*"))
 
102
  end
 
103
 
 
104
  def test_html_like_em_bold
 
105
    assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
 
106
                  @am.flow("cat <i>and </i><b>dog</b>")
 
107
  end
 
108
 
 
109
  def test_html_like_em_bold_SGML
 
110
    assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
 
111
                  @am.flow("cat <i>and <b></i>dog</b>")
 
112
  end
 
113
 
 
114
  def test_html_like_em_bold_nested_1
 
115
    assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
 
116
                  @am.flow("cat <i><b>and</b></i> dog"))
 
117
  end
 
118
 
 
119
  def test_html_like_em_bold_nested_2
 
120
    assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
 
121
                  @am.flow("cat <i>and <b>dog</b></i>")
 
122
  end
 
123
 
 
124
  def test_html_like_em_bold_nested_mixed_case
 
125
    assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
 
126
                  @am.flow("cat <i>and <B>dog</B></I>")
 
127
  end
 
128
 
 
129
  def test_html_like_em_bold_mixed_case
 
130
    assert_equal ["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
 
131
                  @am.flow("cat <i>and</i> <B>dog</b>")
 
132
  end
 
133
 
 
134
  def test_html_like_teletype
 
135
    assert_equal ["cat ", @tt_on, "dog", @tt_off],
 
136
                 @am.flow("cat <tt>dog</Tt>")
 
137
  end
 
138
 
 
139
  def test_html_like_teletype_em_bold_SGML
 
140
    assert_equal [@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
 
141
                  @am.flow("<tt>cat</tt> <i>and <b></i>dog</b>")
 
142
  end
 
143
 
 
144
  def test_protect
 
145
    assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
 
146
 
 
147
    assert_equal(["cat <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
 
148
 
 
149
    assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
 
150
                  @am.flow("cat <i>and</i> \\<B>dog</b>"))
 
151
 
 
152
    assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
 
153
 
 
154
    assert_equal(["_cat_", @em_on, "dog", @em_off],
 
155
                  @am.flow("\\_cat_<i>dog</i>"))
 
156
  end
 
157
 
 
158
  def test_special
 
159
    # class names, variable names, file names, or instance variables
 
160
    @am.add_special(/(
 
161
                       \b([A-Z]\w+(::\w+)*)
 
162
                       | \#\w+[!?=]?
 
163
                       | \b\w+([_\/\.]+\w+)+[!?=]?
 
164
                      )/x,
 
165
                    :CROSSREF)
 
166
 
 
167
    assert_equal(["cat"], @am.flow("cat"))
 
168
 
 
169
    assert_equal(["cat ", crossref("#fred"), " dog"].flatten,
 
170
                  @am.flow("cat #fred dog"))
 
171
 
 
172
    assert_equal([crossref("#fred"), " dog"].flatten,
 
173
                  @am.flow("#fred dog"))
 
174
 
 
175
    assert_equal(["cat ", crossref("#fred")].flatten, @am.flow("cat #fred"))
 
176
  end
 
177
 
 
178
end
 
179