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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
require File.expand_path '../xref_test_case', __FILE__
class TestRDocMethodAttr < XrefTestCase
def test_initialize_copy
refute_same @c1_m.full_name, @c1_m.dup.full_name
end
def test_block_params_equal
m = RDoc::MethodAttr.new(nil, 'foo')
m.block_params = ''
assert_equal '', m.block_params
m.block_params = 'a_var'
assert_equal 'a_var', m.block_params
m.block_params = '()'
assert_equal '', m.block_params
m.block_params = '(a_var, b_var)'
assert_equal 'a_var, b_var', m.block_params
m.block_params = '.to_s + "</#{element.upcase}>"'
assert_equal '', m.block_params
m.block_params = 'i.name'
assert_equal 'name', m.block_params
m.block_params = 'attr.expanded_name, attr.value'
assert_equal 'expanded_name, value', m.block_params
m.block_params = 'expanded_name, attr.value'
assert_equal 'expanded_name, value', m.block_params
m.block_params = 'attr.expanded_name, value'
assert_equal 'expanded_name, value', m.block_params
m.block_params = '(@base_notifier)'
assert_equal 'base_notifier', m.block_params
m.block_params = 'if @signal_status == :IN_LOAD'
assert_equal '', m.block_params
m.block_params = 'e if e.kind_of? Element'
assert_equal 'e', m.block_params
m.block_params = '(e, f) if e.kind_of? Element'
assert_equal 'e, f', m.block_params
m.block_params = 'back_path, back_name'
assert_equal 'back_path, back_name', m.block_params
m.block_params = '(*a[1..-1])'
assert_equal '*a', m.block_params
m.block_params = '@@context[:node] if defined? @@context[:node].namespace'
assert_equal 'context', m.block_params
m.block_params = '(result, klass.const_get(constant_name))'
assert_equal 'result, const', m.block_params
m.block_params = 'name.to_s if (bitmap & bit) != 0'
assert_equal 'name', m.block_params
m.block_params = 'line unless line.deleted'
assert_equal 'line', m.block_params
m.block_params = 'str + rs'
assert_equal 'str', m.block_params
m.block_params = 'f+rs'
assert_equal 'f', m.block_params
m.block_params = '[user, realm, hash[user]]'
assert_equal 'user, realm, hash', m.block_params
m.block_params = 'proc{|rc| rc == "rc" ? irbrc : irbrc+rc| ... }'
assert_equal 'proc', m.block_params
m.block_params = 'lambda { |x| x.to_i }'
assert_equal 'lambda', m.block_params
m.block_params = '$&'
assert_equal 'str', m.block_params
m.block_params = 'Inflections.instance'
assert_equal 'instance', m.block_params
m.block_params = 'self.class::STARTED'
assert_equal 'STARTED', m.block_params
m.block_params = 'Test::Unit::TestCase::STARTED'
assert_equal 'STARTED', m.block_params
m.block_params = 'ActiveSupport::OptionMerger.new(self, options)'
assert_equal 'option_merger', m.block_params
m.block_params = ', msg'
assert_equal '', m.block_params
m.block_params = '[size.to_s(16), term, chunk, term].join'
assert_equal '[size, term, chunk, term].join', m.block_params
m.block_params = 'YPath.new( path )'
assert_equal 'y_path', m.block_params
end
def test_find_method_or_attribute_recursive
inc = RDoc::Include.new 'M1', nil
@m1.add_include inc # M1 now includes itself
assert_nil @m1_m.find_method_or_attribute 'm'
end
def test_full_name
assert_equal 'C1#m', @c1_m.full_name
assert_equal 'C1::m', @c1__m.full_name
end
def test_is_alias_for
assert_equal @c2_b, @c2_a.is_alias_for
end
def test_output_name
assert_equal '#m', @c1_m.output_name(@c1)
assert_equal '::m', @c1__m.output_name(@c1)
assert_equal 'C1#m', @c1_m.output_name(@c2)
assert_equal 'C1.m', @c1__m.output_name(@c2)
end
def test_search_record
@c1_m.comment = 'This is a comment.'
expected = [
'm',
'C1#m',
'm',
'C1',
'C1.html#method-i-m',
'(foo)',
"<p>This is a comment.\n",
]
assert_equal expected, @c1_m.search_record
end
def test_spaceship
assert_nil @c1_m.<=>(RDoc::CodeObject.new)
end
def test_equals2
assert_equal @c1_m, @c1_m
refute_equal @c1_m, @parent_m
end
def test_pretty_print
temp_dir do |tmpdir|
s = RDoc::RI::Store.new tmpdir
s.rdoc = @rdoc
top_level = s.add_file 'file.rb'
meth_bang = RDoc::AnyMethod.new nil, 'method!'
meth_bang.record_location top_level
meth_bang_alias = RDoc::Alias.new nil, 'method!', 'method_bang', ''
meth_bang_alias.record_location top_level
klass = top_level.add_class RDoc::NormalClass, 'Object'
klass.add_method meth_bang
meth_bang.add_alias meth_bang_alias, klass
s.save
meth_alias_from_store = s.load_method 'Object', '#method_bang'
expected = "[RDoc::AnyMethod Object#method_bang public alias for method!]"
actual = mu_pp meth_alias_from_store
assert_equal expected, actual
end
end
def test_to_s
assert_equal 'RDoc::AnyMethod: C1#m', @c1_m.to_s
assert_equal 'RDoc::AnyMethod: C2#b', @c2_b.to_s
assert_equal 'RDoc::AnyMethod: C1::m', @c1__m.to_s
end
end
|