forked from rurema/bitclust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_entry.rb
More file actions
208 lines (179 loc) · 5.1 KB
/
Copy pathtest_entry.rb
File metadata and controls
208 lines (179 loc) · 5.1 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
require 'bitclust'
require 'test/unit'
class TestClassEntry < Test::Unit::TestCase
def setup
s = <<HERE
= class Hoge
alias HogeHoge
alias HogeHogeHoge
== Class Methods
--- hoge
hoge
--- fuga
{: undef}
fuga
== Instance Methods
--- fugafuga
{: undef}
fugafuga
= class Bar < Hoge
== Class Methods
--- bar
= class Err < Exception
alias ErrErr
HERE
@lib, = BitClust::RRDParser.parse(s, 'hoge')
end
def test_entries
assert_equal(['bar', 'fuga', 'fugafuga', 'hoge'],
@lib.fetch_class("Bar").entries(1).map{|e| e.name}.sort)
end
def test_aliases
assert_equal(['HogeHoge', 'HogeHogeHoge'],
@lib.fetch_class("Hoge").aliases.map{|e| e.name}.sort)
end
def test_aliasof
assert_equal(nil, @lib.fetch_class("Hoge").aliasof)
assert_equal("Hoge", @lib.fetch_class("HogeHoge").aliasof.name)
end
def test_realname
assert_equal('Hoge', @lib.fetch_class("Hoge").realname)
assert_equal('Hoge', @lib.fetch_class("HogeHoge").realname)
end
def test_error_class?
assert(!@lib.fetch_class("Hoge").error_class?)
assert(@lib.fetch_class("Err").error_class?)
assert(!@lib.fetch_class("HogeHoge").error_class?)
assert(@lib.fetch_class("ErrErr").error_class?)
end
def test_partitioned_entries
parts = @lib.fetch_class('Hoge').partitioned_entries
assert_equal(['fuga', 'fugafuga'], parts.undefined.map(&:name))
end
def test_superclass
assert('Exception', @lib.fetch_class("Err").superclass.name)
assert('Exception', @lib.fetch_class("ErrErr").superclass.name)
end
def test_instance_method?
bar = @lib.fetch_class("Bar")
assert(bar.instance_method?('fugafuga'))
assert(!bar.instance_method?('fugafuga', false))
hoge = @lib.fetch_class("Hoge")
assert(hoge.instance_method?('fugafuga'))
assert(hoge.instance_method?('fugafuga', false))
end
end
class TestEntryDescription < Test::Unit::TestCase
def parse_class(class_source)
lib, = BitClust::RRDParser.parse(class_source, 'hoge')
lib.fetch_class('Hoge')
end
def test_description_truncates_newline_between_non_ascii
klass = parse_class(<<HERE)
= class Hoge
これは1行目で
あとに続きます。
以降の段落は含まれません。
HERE
assert_equal('これは1行目であとに続きます。', klass.description)
end
def test_description_truncates_consecutive_newlines_between_non_ascii
klass = parse_class(<<HERE)
= class Hoge
あい
うえ
おか。
HERE
assert_equal('あいうえおか。', klass.description)
end
def test_description_converts_newline_to_space_around_ascii
klass = parse_class(<<HERE)
= class Hoge
first line
second line
HERE
assert_equal('first line second line', klass.description)
end
def test_description_replaces_bracket_link_with_plain_text
klass = parse_class(<<HERE)
= class Hoge
自身の hostname を文字列で返します。また、[[m:URI::Generic#host]] が設
定されていない場合は [[c:Array]] を返します。
HERE
assert_equal('自身の hostname を文字列で返します。また、URI::Generic#host が設定されていない場合は Array を返します。',
klass.description)
end
def test_description_replaces_indexer_bracket_link
klass = parse_class(<<HERE)
= class Hoge
[[m:String#[] ]] を参照。
HERE
assert_equal('String#[] を参照。', klass.description)
end
def test_method_description_is_plain_text
klass = parse_class(<<HERE)
= class Hoge
== Instance Methods
--- fuga
[[c:Array]] を日本語で
返します。
次の段落。
HERE
method = klass.entries.detect {|m| m.name == 'fuga' }
assert_equal('Array を日本語で返します。', method.description)
end
end
class TestEntryNomethod < Test::Unit::TestCase
def parse_class(class_source)
lib, = BitClust::RRDParser.parse(class_source, 'hoge')
lib.fetch_class('Hoge')
end
def test_nomethod_is_partitioned_separately
klass = parse_class(<<HERE)
= class Hoge
== Instance Methods
--- fuga
{: nomethod}
説明のためのエントリです。
HERE
parts = klass.partitioned_entries
assert_equal(['fuga'], parts.nomethod.map(&:name))
assert_equal([], parts.instance_methods.map(&:name))
end
def test_redefined_is_partitioned_separately
klass = parse_class(<<HERE)
= class Hoge
== Instance Methods
--- bar
説明です。
= redefine Hoge
== Instance Methods
--- baz
再定義の説明です。
HERE
parts = klass.partitioned_entries
assert_equal(['baz'], parts.redefined.map(&:name))
assert_equal(['bar'], parts.instance_methods.map(&:name))
end
def test_description_skips_leading_metadata_paragraph
klass = parse_class(<<HERE)
= class Hoge
== Instance Methods
--- fuga
{: nomethod}
説明のためのエントリです。
HERE
method = klass.entries.detect {|m| m.name == 'fuga' }
assert_equal('説明のためのエントリです。', method.description)
end
def test_description_is_empty_when_only_metadata
klass = parse_class(<<HERE)
= class Hoge
== Instance Methods
--- fuga
{: undef}
HERE
method = klass.entries.detect {|m| m.name == 'fuga' }
assert_equal('', method.description)
end
end