fastri 0.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ require 'test/unit'
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+ require 'fastri/ri_service'
4
+ require 'fastri/ri_index'
5
+
6
+ class TestFunctionalRiService < Test::Unit::TestCase
7
+ # only created once, since it takes a long time
8
+ @@ri = FastRI::RiService.new(FastRI::RiIndex.new_from_paths(RI::Paths::PATH))
9
+ def setup
10
+ @ri = @@ri
11
+ end
12
+
13
+ def assert_include(arr, actual)
14
+ arr.each{|w| assert(actual.include?(w), "#{w} should be included in #{actual}") }
15
+ end
16
+
17
+ def test_completion_list
18
+ completion_each = %w[each_pair each_byte each_key each_value]
19
+ assert_include(completion_each, @ri.completion_list("each_"))
20
+ assert_kind_of(Array, @ri.completion_list("each_"))
21
+
22
+ assert_include(%w[Array Fixnum Hash String], @ri.completion_list(""))
23
+ assert_kind_of(Array, @ri.completion_list(""))
24
+
25
+ assert_include(%w[Array ArgumentError], @ri.completion_list("Ar"))
26
+ end
27
+
28
+ def test_info
29
+ assert_include(%w[collect collect! compact compact! concat],
30
+ @ri.info("Array"))
31
+ assert_include(%w[each each_key each_pair each_value empty],
32
+ @ri.info("Hash"))
33
+ assert_kind_of(String, @ri.info("Hash"))
34
+ end
35
+
36
+ def test_args
37
+ assert_match(/map\s+\{\|\s*\w+\s*\|\s+block\s+\}/,
38
+ @ri.args("map"))
39
+ assert_kind_of(String,@ri.args("map"))
40
+ end
41
+
42
+ def test_class_list
43
+ assert_include(%w[StringIO Range Array Hash String Struct],
44
+ @ri.class_list("each"))
45
+ assert_kind_of(Array, @ri.class_list("each"))
46
+ assert_include(%w[Hash Struct],
47
+ @ri.class_list("each_pair"))
48
+ assert_equal(nil, @ri.class_list("__super_bogus_method___"))
49
+ end
50
+
51
+ def test_class_list_with_flag
52
+ assert_include(%w[StringIO# Range# Array# Hash# String# Struct#],
53
+ @ri.class_list_with_flag("each"))
54
+ assert_include(%w[Hash# Struct#],
55
+ @ri.class_list_with_flag("each_pair"))
56
+ assert_equal(nil, @ri.class_list_with_flag("__super_bogus_method___"))
57
+ end
58
+ end
59
+
60
+
@@ -0,0 +1,267 @@
1
+ require 'test/unit'
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+ $:.unshift "lib"
4
+ require 'fastri/ri_index'
5
+
6
+ class TestRiIndex < Test::Unit::TestCase
7
+ INDEX_DATA =<<EOF
8
+ #{FastRI::RiIndex::MAGIC}
9
+ Sources:
10
+ system /usr/share/ri/system/
11
+ somegem-0.1.0 /long/path/somegem-0.1.0
12
+ stuff-1.1.0 /long/path/stuff-1.1.0
13
+ ================================================================================
14
+ Namespaces:
15
+ ABC 0 1
16
+ ABC::DEF 0 1
17
+ ABC::DEF::Foo 1
18
+ ABC::Zzz 0
19
+ CDE 1 2
20
+ FGH 2
21
+ FGH::Adfdsf 2
22
+ ================================================================================
23
+ Methods:
24
+ ABC::DEF.bar 0
25
+ ABC::DEF::Foo#baz 1
26
+ ABC::DEF::Foo#foo 1
27
+ ABC::Zzz.foo 0 1
28
+ ABC::Zzz#foo 0
29
+ CDE.foo 1 2
30
+ FGH::Adfdsf#foo 2
31
+ ================================================================================
32
+ EOF
33
+
34
+ require 'stringio'
35
+ def setup
36
+ @index = FastRI::RiIndex.new_from_IO(StringIO.new(INDEX_DATA))
37
+ end
38
+
39
+ def test_dump
40
+ s = StringIO.new("")
41
+ @index.dump(s)
42
+ assert_equal(INDEX_DATA, s.string)
43
+ end
44
+
45
+ def test_toplevel_namespace
46
+ ret = @index.top_level_namespace
47
+ assert_kind_of(Array, ret)
48
+ assert_kind_of(FastRI::RiIndex::TopLevelEntry, ret[0])
49
+ end
50
+
51
+ def test_full_class_names
52
+ assert_equal(["ABC", "ABC::DEF", "ABC::DEF::Foo", "ABC::Zzz", "CDE", "FGH", "FGH::Adfdsf"], @index.full_class_names)
53
+ assert_equal(["ABC", "ABC::DEF", "ABC::Zzz"], @index.full_class_names(0))
54
+ assert_equal(["ABC", "ABC::DEF", "ABC::DEF::Foo", "CDE"], @index.full_class_names(1))
55
+ assert_equal(["CDE", "FGH", "FGH::Adfdsf"], @index.full_class_names(2))
56
+ assert_equal(["CDE", "FGH", "FGH::Adfdsf"], @index.full_class_names("stuff-1.1.0"))
57
+ assert_equal([], @index.full_class_names("nonexistent-1.1.0"))
58
+ end
59
+
60
+ def test_full_method_names
61
+ assert_equal(["ABC::DEF.bar", "ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo",
62
+ "ABC::Zzz.foo", "ABC::Zzz#foo", "CDE.foo", "FGH::Adfdsf#foo"],
63
+ @index.full_method_names)
64
+ assert_equal(["ABC::DEF.bar", "ABC::Zzz.foo", "ABC::Zzz#foo"],
65
+ @index.full_method_names(0))
66
+ assert_equal(["ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo", "ABC::Zzz.foo", "CDE.foo"],
67
+ @index.full_method_names(1))
68
+ assert_equal(["CDE.foo", "FGH::Adfdsf#foo"], @index.full_method_names(2))
69
+ assert_equal(["CDE.foo", "FGH::Adfdsf#foo"], @index.full_method_names("stuff-1.1.0"))
70
+ assert_equal([], @index.full_method_names("nonexistent-1.1.0"))
71
+ end
72
+
73
+ def test_all_names
74
+ assert_equal(["ABC", "ABC::DEF", "ABC::DEF::Foo", "ABC::Zzz", "CDE", "FGH",
75
+ "FGH::Adfdsf", "ABC::DEF.bar", "ABC::DEF::Foo#baz",
76
+ "ABC::DEF::Foo#foo", "ABC::Zzz.foo", "ABC::Zzz#foo",
77
+ "CDE.foo", "FGH::Adfdsf#foo"], @index.all_names)
78
+ assert_equal(["ABC", "ABC::DEF", "ABC::Zzz", "ABC::DEF.bar",
79
+ "ABC::Zzz.foo", "ABC::Zzz#foo"], @index.all_names(0))
80
+ assert_equal(["ABC", "ABC::DEF", "ABC::DEF::Foo", "CDE",
81
+ "ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo", "ABC::Zzz.foo",
82
+ "CDE.foo"], @index.all_names(1))
83
+ assert_equal(["CDE", "FGH", "FGH::Adfdsf", "CDE.foo", "FGH::Adfdsf#foo"],
84
+ @index.all_names(2))
85
+ assert_equal(["ABC", "ABC::DEF", "ABC::DEF::Foo", "CDE",
86
+ "ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo", "ABC::Zzz.foo",
87
+ "CDE.foo"], @index.all_names("somegem-0.1.0"))
88
+ assert_equal([], @index.all_names("notinstalled-1.0"))
89
+ end
90
+
91
+ def test_get_class_entry
92
+ assert_equal("ABC", @index.get_class_entry("ABC", nil).full_name)
93
+ assert_nil(@index.get_class_entry("ABC", nil).source_index)
94
+ assert_nil(@index.get_class_entry("ABC::DEF::Foo", 0))
95
+ assert_equal(1, @index.get_class_entry("ABC::DEF::Foo", 1).source_index)
96
+ assert_equal(2, @index.get_class_entry("ABC::DEF::Foo", 1).index)
97
+ end
98
+
99
+ def test_get_method_entry
100
+ assert_equal("ABC::DEF.bar", @index.get_method_entry("ABC::DEF.bar", nil).full_name)
101
+ assert_equal(0, @index.get_method_entry("ABC::DEF.bar", 0).source_index)
102
+ assert_nil(@index.get_method_entry("FGH::Adfdsf#foo", 1))
103
+ assert_equal(6, @index.get_method_entry("FGH::Adfdsf#foo", 2).index)
104
+ assert_equal(2, @index.get_method_entry("FGH::Adfdsf#foo", 2).source_index)
105
+ assert_equal("FGH::Adfdsf#foo", @index.get_method_entry("FGH::Adfdsf#foo", 2).full_name)
106
+ end
107
+
108
+ def test_namespaces_under
109
+ assert_kind_of(Array, @index.namespaces_under("ABC", true, nil))
110
+ results = @index.namespaces_under("ABC", true, nil)
111
+ assert_equal(3, results.size)
112
+ assert_equal(["ABC::DEF", "ABC::DEF::Foo", "ABC::Zzz"], results.map{|x| x.full_name})
113
+ results = @index.namespaces_under("ABC", false, nil)
114
+ assert_equal(2, results.size)
115
+ assert_equal(["ABC::DEF", "ABC::Zzz"], results.map{|x| x.full_name})
116
+ end
117
+
118
+ def test_namespaces_under_scoped
119
+ results = @index.namespaces_under("ABC", false, 1)
120
+ assert_kind_of(Array, results)
121
+ assert_equal(["ABC::DEF"], results.map{|x| x.full_name})
122
+ results = @index.namespaces_under("ABC", true, 1)
123
+ assert_equal(2, results.size)
124
+ assert_equal(["ABC::DEF", "ABC::DEF::Foo"], results.map{|x| x.full_name})
125
+ results = @index.namespaces_under("ABC", true, "somegem-0.1.0")
126
+ assert_equal(2, results.size)
127
+ assert_equal(["ABC::DEF", "ABC::DEF::Foo"], results.map{|x| x.full_name})
128
+ results = @index.namespaces_under("ABC", true, 0)
129
+ assert_equal(2, results.size)
130
+ assert_equal(["ABC::DEF", "ABC::Zzz"], results.map{|x| x.full_name})
131
+ end
132
+
133
+ def test_namespaces_under_toplevel
134
+ toplevel = @index.top_level_namespace[0]
135
+ assert_equal(["ABC", "CDE", "FGH"],
136
+ @index.namespaces_under(toplevel, false, nil).map{|x| x.full_name})
137
+ assert_equal(["ABC", "ABC::DEF", "ABC::DEF::Foo", "ABC::Zzz",
138
+ "CDE", "FGH", "FGH::Adfdsf"],
139
+ @index.namespaces_under(toplevel, true, nil).map{|x| x.full_name})
140
+ assert_equal(["CDE", "FGH", "FGH::Adfdsf"],
141
+ @index.namespaces_under(toplevel, true, "stuff-1.1.0").map{|x| x.full_name})
142
+ end
143
+
144
+ def test_methods_under_scoped
145
+ results = @index.methods_under("ABC", true, 1)
146
+ assert_equal(["ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo", "ABC::Zzz.foo"], results.map{|x| x.full_name})
147
+ results = @index.methods_under("CDE", false, "stuff-1.1.0")
148
+ assert_equal(["CDE.foo"], results.map{|x| x.full_name})
149
+ results = @index.methods_under("ABC", true, nil)
150
+ assert_equal(["ABC::DEF.bar", "ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo",
151
+ "ABC::Zzz.foo", "ABC::Zzz#foo"], results.map{|x| x.full_name})
152
+ assert_equal(["ABC::DEF.bar", "ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo",
153
+ "ABC::Zzz.foo", "ABC::Zzz#foo", "CDE.foo", "FGH::Adfdsf#foo"],
154
+ @index.methods_under("", true, nil).map{|x| x.full_name})
155
+ assert_equal([], @index.methods_under("ABC", false, nil).map{|x| x.full_name})
156
+ assert_equal(["CDE.foo"],
157
+ @index.methods_under("CDE", false, nil).map{|x| x.full_name})
158
+ assert_equal(["FGH::Adfdsf#foo"],
159
+ @index.methods_under("FGH", true, nil).map{|x| x.full_name})
160
+ assert_equal([], @index.methods_under("FGH", true, 0).map{|x| x.full_name})
161
+ assert_equal(["FGH::Adfdsf#foo"],
162
+ @index.methods_under("FGH", true, 2).map{|x| x.full_name})
163
+ assert_equal([], @index.methods_under("FGH", false, 2).map{|x| x.full_name})
164
+ assert_equal(["FGH::Adfdsf#foo"],
165
+ @index.methods_under("FGH::Adfdsf", false, 2).map{|x| x.full_name})
166
+ assert_equal(["FGH::Adfdsf#foo"],
167
+ @index.methods_under("FGH::Adfdsf", true, 2).map{|x| x.full_name})
168
+ assert_equal([], @index.methods_under("FGH::Adfdsf", false, 0).map{|x| x.full_name})
169
+ end
170
+
171
+ def test_lookup_namespace_in
172
+ toplevel = @index.top_level_namespace
173
+ res = @index.lookup_namespace_in("ABC", toplevel)
174
+ assert_equal(["ABC"], res.map{|x| x.full_name})
175
+ toplevel2 = @index.top_level_namespace(2)
176
+ assert_equal([], @index.lookup_namespace_in("ABC", toplevel2))
177
+ assert_equal(["FGH"], @index.lookup_namespace_in("FGH", toplevel2).map{|x| x.full_name})
178
+ end
179
+
180
+ def test_find_class_by_name
181
+ class_entry = nil
182
+ class << @index; self end.module_eval do
183
+ define_method(:get_class){|x| class_entry = x}
184
+ end
185
+ @index.find_class_by_name("ABC")
186
+ assert_kind_of(FastRI::RiIndex::ClassEntry, class_entry)
187
+ assert_equal("ABC", class_entry.full_name)
188
+ assert_nil(class_entry.source_index)
189
+ assert_equal(0, class_entry.index)
190
+ class_entry = nil
191
+ @index.find_class_by_name("ABC::DEF::Foo")
192
+ assert_kind_of(FastRI::RiIndex::ClassEntry, class_entry)
193
+ assert_equal("ABC::DEF::Foo", class_entry.full_name)
194
+ assert_nil(class_entry.source_index)
195
+ assert_equal(2, class_entry.index)
196
+ class_entry = nil
197
+ @index.find_class_by_name("ABC::DEF::Foo", 1)
198
+ assert_kind_of(FastRI::RiIndex::ClassEntry, class_entry)
199
+ assert_equal("ABC::DEF::Foo", class_entry.full_name)
200
+ assert_equal(1, class_entry.source_index)
201
+ assert_equal(2, class_entry.index)
202
+ class_entry = nil
203
+ @index.find_class_by_name("ABC::DEF::Foo", 0)
204
+ assert_nil(class_entry)
205
+ @index.find_class_by_name("AB", nil)
206
+ assert_nil(class_entry)
207
+ end
208
+
209
+ def test_find_method_by_name
210
+ method_entry = nil
211
+ class << @index; self end.module_eval do
212
+ define_method(:get_method){|x| method_entry = x}
213
+ end
214
+ @index.find_method_by_name("ABC")
215
+ assert_nil(method_entry)
216
+ @index.find_method_by_name("ABC::DEF.bar")
217
+ assert_equal("ABC::DEF.bar", method_entry.full_name)
218
+ method_entry = nil
219
+ @index.find_method_by_name("ABC::DEF::Foo#baz")
220
+ assert_equal("ABC::DEF::Foo#baz", method_entry.full_name)
221
+ assert_nil(method_entry.source_index)
222
+ assert_equal(1, method_entry.index)
223
+ method_entry = nil
224
+ @index.find_method_by_name("ABC::DEF::Foo#baz", 1)
225
+ assert_equal("ABC::DEF::Foo#baz", method_entry.full_name)
226
+ assert_equal(1, method_entry.source_index)
227
+ assert_equal(1, method_entry.index)
228
+ method_entry = nil
229
+ @index.find_method_by_name("CDE.foo", 2)
230
+ assert_equal("CDE.foo", method_entry.full_name)
231
+ assert_equal(5, method_entry.index)
232
+ assert_equal(2, method_entry.source_index)
233
+ method_entry = nil
234
+ @index.find_method_by_name("ABC::DEF::Foo#ba", 1)
235
+ assert_nil(method_entry)
236
+ @index.find_method_by_name("ABC::DEF.bar", 1)
237
+ assert_nil(method_entry)
238
+ end
239
+
240
+ def test_find_methods
241
+ toplevel = @index.top_level_namespace
242
+ assert_equal(["ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo",
243
+ "ABC::Zzz#foo", "FGH::Adfdsf#foo"],
244
+ @index.find_methods("", false, toplevel).map{|x| x.full_name})
245
+ assert_equal(["ABC::DEF.bar", "ABC::Zzz.foo", "CDE.foo"],
246
+ @index.find_methods("", true, toplevel).map{|x| x.full_name})
247
+ assert_equal([], @index.find_methods("ABC", true, toplevel).map{|x| x.full_name})
248
+ assert_equal(["ABC::DEF::Foo#foo", "ABC::Zzz#foo", "FGH::Adfdsf#foo"],
249
+ @index.find_methods("foo", false, toplevel).map{|x| x.full_name})
250
+ assert_equal(["ABC::Zzz.foo", "CDE.foo"],
251
+ @index.find_methods("foo", true, toplevel).map{|x| x.full_name})
252
+ toplevel = @index.top_level_namespace(1)
253
+ assert_equal(["ABC::DEF::Foo#foo"], @index.find_methods("foo", false, toplevel).map{|x| x.full_name})
254
+ toplevel = @index.top_level_namespace("stuff-1.1.0")
255
+ assert_equal(["CDE.foo"], @index.find_methods("foo", true, toplevel).map{|x| x.full_name})
256
+ end
257
+
258
+ def test_classentry_contained_modules_matching
259
+ toplevel = @index.top_level_namespace[0]
260
+ assert_equal(["ABC"], toplevel.contained_modules_matching("ABC").map{|x| x.full_name})
261
+
262
+ class_entry = @index.get_class_entry("ABC")
263
+ assert_equal([], class_entry.contained_modules_matching("ABC").map{|x| x.full_name})
264
+ assert_equal(["ABC::DEF", "ABC::Zzz"], class_entry.contained_modules_matching("").map{|x| x.full_name})
265
+ end
266
+ end
267
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: fastri
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0.0
7
+ date: 2006-11-08 00:00:00 +01:00
8
+ summary: RI docs across machines, faster and smarter than ri.
9
+ require_paths:
10
+ - lib
11
+ email: mfp@acm.org
12
+ homepage: http://eigenclass.org/hiki.rb?fastri
13
+ rubyforge_project:
14
+ description: FastRI is an alternative to the ri command-line tool. It is *much* faster, and also allows you to offer RI lookup services over DRb. FastRI is a bit smarter than ri, and can find classes anywhere in the hierarchy without specifying the "full path". It also knows about gems, and can tell you e.g. which extensions to a core class were added by a specific gem.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message: |+
29
+
30
+ A small note about the RubyGems + FastRI.
31
+ =========================================
32
+ RubyGems adds a noticable overhead to fri, making it run slower than if you
33
+ installed it directly from the tarball with setup.rb.
34
+
35
+ Compare the execution time when installed with RubyGems:
36
+ $ time fri -f plain String > /dev/null
37
+
38
+ real 0m0.385s
39
+ user 0m0.244s
40
+ sys 0m0.036s
41
+
42
+ to the time fri actually takes to run, without the overhead introduced by
43
+ RubyGems:
44
+ $ time ruby bin/fri -f plain String > /dev/null
45
+
46
+ real 0m0.088s
47
+ user 0m0.040s
48
+ sys 0m0.008s
49
+
50
+ If you care about those extra 300ms (and there are situations where they will
51
+ matter, e.g. when using fri for method completion), get FastRI from the
52
+ tarballs.
53
+
54
+ authors:
55
+ - Mauricio Fernandez
56
+ files:
57
+ - bin/fri
58
+ - bin/fastri-server
59
+ - bin/ri-emacs
60
+ - lib/fastri/ri_index.rb
61
+ - lib/fastri/ri_service.rb
62
+ - lib/fastri/version.rb
63
+ - COPYING
64
+ - LEGAL
65
+ - LICENSE
66
+ - Rakefile
67
+ - README.en
68
+ - test/test_ri_index.rb
69
+ - test/test_functional_ri_service.rb
70
+ - setup.rb
71
+ test_files:
72
+ - test/test_ri_index.rb
73
+ - test/test_functional_ri_service.rb
74
+ rdoc_options:
75
+ - --title
76
+ - "FastRI: better, faster ri"
77
+ extra_rdoc_files: []
78
+
79
+ executables:
80
+ - fri
81
+ - fastri-server
82
+ - ri-emacs
83
+ extensions: []
84
+
85
+ requirements: []
86
+
87
+ dependencies: []
88
+