~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rdoc/test_rdoc_any_method.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require File.expand_path '../xref_test_case', __FILE__
 
2
require 'rdoc/code_objects'
 
3
require 'rdoc/generator/markup'
2
4
 
3
5
class RDocAnyMethodTest < XrefTestCase
4
6
 
5
7
  def test_aref
6
8
    m = RDoc::AnyMethod.new nil, 'method?'
7
9
 
8
 
    assert_equal 'method-i-method%3F', m.aref
 
10
    assert_equal 'method-i-method-3F', m.aref
9
11
 
10
12
    m.singleton = true
11
13
 
12
 
    assert_equal 'method-c-method%3F', m.aref
 
14
    assert_equal 'method-c-method-3F', m.aref
13
15
  end
14
16
 
15
17
  def test_arglists
32
34
    assert_equal call_seq, m.arglists
33
35
  end
34
36
 
 
37
  def test_c_function
 
38
    @c1_m.c_function = 'my_c1_m'
 
39
 
 
40
    assert_equal 'my_c1_m', @c1_m.c_function
 
41
  end
 
42
 
35
43
  def test_full_name
36
44
    assert_equal 'C1::m', @c1.method_list.first.full_name
37
45
  end
38
46
 
 
47
  def test_markup_code
 
48
    tokens = [
 
49
      RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'),
 
50
      RDoc::RubyToken::TkDEF.       new(0, 0, 0, 'KW'),
 
51
      RDoc::RubyToken::TkIVAR.     new(0, 0, 0, 'IVAR'),
 
52
      RDoc::RubyToken::TkOp.       new(0, 0, 0, 'Op'),
 
53
      RDoc::RubyToken::TkId.       new(0, 0, 0, 'Id'),
 
54
      RDoc::RubyToken::TkNode.     new(0, 0, 0, 'Node'),
 
55
      RDoc::RubyToken::TkCOMMENT.  new(0, 0, 0, 'COMMENT'),
 
56
      RDoc::RubyToken::TkREGEXP.   new(0, 0, 0, 'REGEXP'),
 
57
      RDoc::RubyToken::TkSTRING.   new(0, 0, 0, 'STRING'),
 
58
      RDoc::RubyToken::TkVal.      new(0, 0, 0, 'Val'),
 
59
      RDoc::RubyToken::TkBACKSLASH.new(0, 0, 0, '\\'),
 
60
    ]
 
61
 
 
62
    @c2_a.collect_tokens
 
63
    @c2_a.add_tokens(*tokens)
 
64
 
 
65
    expected = [
 
66
      '<span class="ruby-constant">CONSTANT</span>',
 
67
      '<span class="ruby-keyword">KW</span>',
 
68
      '<span class="ruby-ivar">IVAR</span>',
 
69
      '<span class="ruby-operator">Op</span>',
 
70
      '<span class="ruby-identifier">Id</span>',
 
71
      '<span class="ruby-node">Node</span>',
 
72
      '<span class="ruby-comment">COMMENT</span>',
 
73
      '<span class="ruby-regexp">REGEXP</span>',
 
74
      '<span class="ruby-string">STRING</span>',
 
75
      '<span class="ruby-value">Val</span>',
 
76
      '\\'
 
77
    ].join
 
78
 
 
79
    assert_equal expected, @c2_a.markup_code
 
80
  end
 
81
 
 
82
  def test_markup_code_empty
 
83
    assert_equal '', @c2_a.markup_code
 
84
  end
 
85
 
 
86
  def test_marshal_dump
 
87
    top_level = RDoc::TopLevel.new 'file.rb'
 
88
    m = RDoc::AnyMethod.new nil, 'method'
 
89
    m.block_params = 'some_block'
 
90
    m.call_seq     = 'call_seq'
 
91
    m.comment      = 'this is a comment'
 
92
    m.params       = 'param'
 
93
    m.record_location top_level
 
94
 
 
95
    cm = RDoc::ClassModule.new 'Klass'
 
96
    cm.add_method m
 
97
 
 
98
    al = RDoc::Alias.new nil, 'method', 'aliased', 'alias comment'
 
99
    al_m = m.add_alias al, cm
 
100
 
 
101
    loaded = Marshal.load Marshal.dump m
 
102
 
 
103
    comment = RDoc::Markup::Document.new(
 
104
                RDoc::Markup::Paragraph.new('this is a comment'))
 
105
 
 
106
    assert_equal m, loaded
 
107
 
 
108
    assert_equal [al_m],         loaded.aliases
 
109
    assert_equal 'some_block',   loaded.block_params
 
110
    assert_equal 'call_seq',     loaded.call_seq
 
111
    assert_equal comment,        loaded.comment
 
112
    assert_equal top_level,      loaded.file
 
113
    assert_equal 'Klass#method', loaded.full_name
 
114
    assert_equal 'method',       loaded.name
 
115
    assert_equal 'param',        loaded.params
 
116
    assert_equal nil,            loaded.singleton # defaults to nil
 
117
    assert_equal :public,        loaded.visibility
 
118
  end
 
119
 
39
120
  def test_marshal_load
40
121
    instance_method = Marshal.load Marshal.dump(@c1.method_list.last)
41
122
 
43
124
    assert_equal 'C1',    instance_method.parent_name
44
125
    assert_equal '(foo)', instance_method.params
45
126
 
 
127
    aliased_method = Marshal.load Marshal.dump(@c2.method_list.last)
 
128
 
 
129
    assert_equal 'C2#a',  aliased_method.full_name
 
130
    assert_equal 'C2',    aliased_method.parent_name
 
131
    assert_equal '()',    aliased_method.params
 
132
 
46
133
    class_method = Marshal.load Marshal.dump(@c1.method_list.first)
47
134
 
48
135
    assert_equal 'C1::m', class_method.full_name
50
137
    assert_equal '()',    class_method.params
51
138
  end
52
139
 
 
140
  def test_marshal_load_version_0
 
141
    m = RDoc::AnyMethod.new nil, 'method'
 
142
    cm = RDoc::ClassModule.new 'Klass'
 
143
    cm.add_method m
 
144
    al = RDoc::Alias.new nil, 'method', 'aliased', 'alias comment'
 
145
    al_m = m.add_alias al, cm
 
146
 
 
147
    loaded = Marshal.load "\x04\bU:\x14RDoc::AnyMethod[\x0Fi\x00I" \
 
148
                          "\"\vmethod\x06:\x06EF\"\x11Klass#method0:\vpublic" \
 
149
                          "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" \
 
150
                          "o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" \
 
151
                          "\"\x16this is a comment\x06;\x06FI" \
 
152
                          "\"\rcall_seq\x06;\x06FI\"\x0Fsome_block\x06;\x06F" \
 
153
                          "[\x06[\aI\"\faliased\x06;\x06Fo;\b\x06;\t[\x06" \
 
154
                          "o;\n\x06;\t[\x06I\"\x12alias comment\x06;\x06FI" \
 
155
                          "\"\nparam\x06;\x06F"
 
156
 
 
157
    comment = RDoc::Markup::Document.new(
 
158
                RDoc::Markup::Paragraph.new('this is a comment'))
 
159
 
 
160
    assert_equal m, loaded
 
161
 
 
162
    assert_equal [al_m],         loaded.aliases
 
163
    assert_equal 'some_block',   loaded.block_params
 
164
    assert_equal 'call_seq',     loaded.call_seq
 
165
    assert_equal comment,        loaded.comment
 
166
    assert_equal 'Klass#method', loaded.full_name
 
167
    assert_equal 'method',       loaded.name
 
168
    assert_equal 'param',        loaded.params
 
169
    assert_equal nil,            loaded.singleton # defaults to nil
 
170
    assert_equal :public,        loaded.visibility
 
171
    assert_equal nil,            loaded.file
 
172
  end
 
173
 
53
174
  def test_name
54
175
    m = RDoc::AnyMethod.new nil, nil
55
176
 
56
177
    assert_nil m.name
57
178
  end
58
179
 
 
180
  def test_param_list_block_params
 
181
    m = RDoc::AnyMethod.new nil, 'method'
 
182
    m.parent = @c1
 
183
 
 
184
    m.block_params = 'c, d'
 
185
 
 
186
    assert_equal %w[c d], m.param_list
 
187
  end
 
188
 
 
189
  def test_param_list_call_seq
 
190
    m = RDoc::AnyMethod.new nil, 'method'
 
191
    m.parent = @c1
 
192
 
 
193
    call_seq = <<-SEQ
 
194
method(a) { |c| ... }
 
195
method(a, b) { |c, d| ... }
 
196
    SEQ
 
197
 
 
198
    m.call_seq = call_seq
 
199
 
 
200
    assert_equal %w[a b c d], m.param_list
 
201
  end
 
202
 
 
203
  def test_param_list_params
 
204
    m = RDoc::AnyMethod.new nil, 'method'
 
205
    m.parent = @c1
 
206
 
 
207
    m.params = '(a, b)'
 
208
 
 
209
    assert_equal %w[a b], m.param_list
 
210
  end
 
211
 
 
212
  def test_param_list_params_block_params
 
213
    m = RDoc::AnyMethod.new nil, 'method'
 
214
    m.parent = @c1
 
215
 
 
216
    m.params = '(a, b)'
 
217
    m.block_params = 'c, d'
 
218
 
 
219
    assert_equal %w[a b c d], m.param_list
 
220
  end
 
221
 
59
222
  def test_param_seq
60
223
    m = RDoc::AnyMethod.new nil, 'method'
61
224
    m.parent = @c1
76
239
    assert_equal '(a, b) { |c, d| ... }', m.param_seq
77
240
  end
78
241
 
 
242
  def test_param_seq_call_seq
 
243
    m = RDoc::AnyMethod.new nil, 'method'
 
244
    m.parent = @c1
 
245
 
 
246
    call_seq = <<-SEQ
 
247
method(a) { |c| ... }
 
248
method(a, b) { |c, d| ... }
 
249
    SEQ
 
250
 
 
251
    m.call_seq = call_seq
 
252
 
 
253
    assert_equal '(a, b) { |c, d| }', m.param_seq
 
254
 
 
255
  end
 
256
 
79
257
  def test_parent_name
80
258
    assert_equal 'C1', @c1.method_list.first.parent_name
81
259
    assert_equal 'C1', @c1.method_list.last.parent_name