fastri 0.1.1.1 → 0.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ # Copyright (C) 2006 Mauricio Fernandez <mfp@acm.org>
2
+ #
3
+
4
+ require 'test/unit'
5
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
6
+ $:.unshift "lib"
7
+ require 'fastri/full_text_indexer'
8
+ require 'fastri/full_text_index'
9
+
10
+ class TestIntegrationFullTextIndex < Test::Unit::TestCase
11
+ include FastRI
12
+ def setup
13
+ @indexer = FullTextIndexer.new(20)
14
+ end
15
+
16
+ require 'stringio'
17
+ def get_index
18
+ fulltextIO = StringIO.new("")
19
+ suffixIO = StringIO.new("")
20
+ @indexer.build_index(fulltextIO, suffixIO)
21
+ FullTextIndex.new_from_ios(fulltextIO, suffixIO)
22
+ end
23
+
24
+ def test_basic_matching
25
+ @indexer.add_document("first.txt", "this is the first document: foo")
26
+ @indexer.add_document("second.txt", "this is the second document: bar")
27
+ index = get_index
28
+ assert_equal("first.txt", index.lookup("foo").path)
29
+ assert_equal("second.txt", index.lookup("bar").path)
30
+ end
31
+
32
+ def test_metadata
33
+ @indexer.add_document("first.txt", "this is the first document: foo",
34
+ :type => "text/plain", :foo => 'baz')
35
+ @indexer.add_document("second.doc", "this is the second document: bar",
36
+ :type => "application/msword", :bar => "foo")
37
+ index = get_index
38
+ assert_equal("first.txt", index.lookup("foo").path)
39
+ assert_equal("second.doc", index.lookup("bar").path)
40
+ assert_equal({:foo=>"baz", :type=>"text/plain"}, index.lookup("foo").metadata)
41
+ assert_equal({:bar=>"foo", :type=>"application/msword"}, index.lookup("bar").metadata)
42
+ end
43
+ end
@@ -89,6 +89,7 @@ EOF
89
89
  end
90
90
 
91
91
  def test_get_class_entry
92
+ assert_nil(@index.get_class_entry("NONEXISTENT_FOO"))
92
93
  assert_equal("ABC", @index.get_class_entry("ABC", nil).full_name)
93
94
  assert_nil(@index.get_class_entry("ABC", nil).source_index)
94
95
  assert_nil(@index.get_class_entry("ABC::DEF::Foo", 0))
@@ -141,6 +142,22 @@ EOF
141
142
  @index.namespaces_under(toplevel, true, "stuff-1.1.0").map{|x| x.full_name})
142
143
  end
143
144
 
145
+ def test_source_paths_for_string
146
+ assert_equal([], @index.source_paths_for(""))
147
+ assert_equal([], @index.source_paths_for(nil))
148
+
149
+ assert_equal(["/usr/share/ri/system/", "/long/path/somegem-0.1.0"], @index.source_paths_for("ABC::DEF"))
150
+ assert_equal(["/long/path/somegem-0.1.0", "/long/path/stuff-1.1.0"], @index.source_paths_for("CDE.foo"))
151
+ end
152
+
153
+ def test_source_paths_for_entry
154
+ assert_equal(["/usr/share/ri/system/", "/long/path/somegem-0.1.0"],
155
+ @index.source_paths_for(@index.get_class_entry("ABC::DEF")))
156
+ assert_equal(["/long/path/somegem-0.1.0", "/long/path/stuff-1.1.0"],
157
+ @index.source_paths_for(@index.get_method_entry("CDE.foo")))
158
+ end
159
+
160
+
144
161
  def test_methods_under_scoped
145
162
  results = @index.methods_under("ABC", true, 1)
146
163
  assert_equal(["ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo", "ABC::Zzz.foo"], results.map{|x| x.full_name})
@@ -255,7 +272,16 @@ EOF
255
272
  assert_equal(["CDE.foo"], @index.find_methods("foo", true, toplevel).map{|x| x.full_name})
256
273
  end
257
274
 
258
- def test_classentry_contained_modules_matching
275
+ def test_num_namespaces
276
+ assert_equal(7, @index.num_namespaces)
277
+ end
278
+
279
+ def test_num_methods
280
+ assert_equal(7, @index.num_methods)
281
+ end
282
+
283
+ #{{{ ClassEntry and MethodEntry
284
+ def test_ClassEntry_contained_modules_matching
259
285
  toplevel = @index.top_level_namespace[0]
260
286
  assert_equal(["ABC"], toplevel.contained_modules_matching("ABC").map{|x| x.full_name})
261
287
 
@@ -263,5 +289,77 @@ EOF
263
289
  assert_equal([], class_entry.contained_modules_matching("ABC").map{|x| x.full_name})
264
290
  assert_equal(["ABC::DEF", "ABC::Zzz"], class_entry.contained_modules_matching("").map{|x| x.full_name})
265
291
  end
292
+
293
+ def test_ClassEntry_type
294
+ class_entry = @index.get_class_entry("ABC")
295
+ assert_equal(:namespace, class_entry.type)
296
+ end
297
+
298
+ def test_ClassEntry_path_names
299
+ class_entry = @index.get_class_entry("ABC")
300
+ assert_equal(["/usr/share/ri/system/ABC", "/long/path/somegem-0.1.0/ABC"], class_entry.path_names)
301
+
302
+ class_entry = @index.get_class_entry("ABC", 0)
303
+ assert_equal(["/usr/share/ri/system/ABC"], class_entry.path_names)
304
+ class_entry = @index.get_class_entry("ABC", 1)
305
+ assert_equal(["/long/path/somegem-0.1.0/ABC"], class_entry.path_names)
306
+ end
307
+
308
+ def test_ClassEntry_classes_and_modules
309
+ class_entry = @index.get_class_entry("ABC")
310
+ assert_equal(["ABC::DEF", "ABC::Zzz"],
311
+ class_entry.classes_and_modules.map{|x| x.full_name})
312
+ class_entry = @index.get_class_entry("ABC::DEF")
313
+ assert_equal(["ABC::DEF::Foo"], class_entry.classes_and_modules.map{|x| x.full_name})
314
+ end
315
+
316
+ def test_ClassEntry_contained_class_named
317
+ class_entry = @index.get_class_entry("ABC")
318
+ class_entry = class_entry.contained_class_named("DEF")
319
+ assert_equal("ABC::DEF", class_entry.full_name)
320
+ assert_equal(1, class_entry.index)
321
+ class_entry = class_entry.contained_class_named("Foo")
322
+ assert_equal(2, class_entry.index)
323
+ assert_nil(class_entry.contained_class_named("Bar"))
324
+ assert_equal(3, @index.get_class_entry("ABC").contained_class_named("Zzz").index)
325
+ end
326
+
327
+ def test_ClassEntry_methods_matching
328
+ class_entry = @index.get_class_entry("ABC::Zzz")
329
+ assert_equal([], class_entry.methods_matching("nonexistent", false))
330
+ assert_equal([3], class_entry.methods_matching("foo", true).map{|x| x.index})
331
+ assert_equal([4], class_entry.methods_matching("foo", false).map{|x| x.index})
332
+ end
333
+
334
+ def test_ClassEntry_recursively_find_methods_matching
335
+ class_entry = @index.get_class_entry("ABC")
336
+ assert_equal(["ABC::DEF.bar", "ABC::Zzz.foo"],
337
+ class_entry.recursively_find_methods_matching(//, true).map{|x| x.full_name})
338
+ assert_equal(["ABC::DEF::Foo#baz", "ABC::DEF::Foo#foo", "ABC::Zzz#foo"],
339
+ class_entry.recursively_find_methods_matching(//, false).map{|x| x.full_name})
340
+ assert_equal([], class_entry.recursively_find_methods_matching(/nonono/, false).map{|x| x.full_name})
341
+ end
342
+
343
+ def test_ClassEntry_all_method_names
344
+ class_entry = @index.get_class_entry("ABC")
345
+ assert_equal([], class_entry.all_method_names)
346
+ class_entry = @index.get_class_entry("ABC::Zzz")
347
+ assert_equal(["ABC::Zzz.foo", "ABC::Zzz#foo"], class_entry.all_method_names)
348
+ end
349
+
350
+ def test_MethodEntry_path_name
351
+ method_entry = @index.get_method_entry("CDE.foo")
352
+ assert_equal("/long/path/somegem-0.1.0/CDE/foo-c.yaml", method_entry.path_name)
353
+
354
+ method_entry = @index.get_method_entry("CDE.foo", 1)
355
+ assert_equal("/long/path/somegem-0.1.0/CDE/foo-c.yaml", method_entry.path_name)
356
+ method_entry = @index.get_method_entry("CDE.foo", 2)
357
+ assert_equal("/long/path/stuff-1.1.0/CDE/foo-c.yaml", method_entry.path_name)
358
+ end
359
+
360
+ def test_MethodEntry_type
361
+ method_entry = @index.get_method_entry("CDE.foo")
362
+ assert_equal(:method, method_entry.type)
363
+ end
266
364
  end
267
365
 
data/test/test_util.rb ADDED
@@ -0,0 +1,38 @@
1
+ # Copyright (C) 2006 Mauricio Fernandez <mfp@acm.org>
2
+ #
3
+
4
+ require 'test/unit'
5
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
6
+ $:.unshift "lib"
7
+ require 'fastri/util'
8
+
9
+ class TestUtil < Test::Unit::TestCase
10
+ data = <<EOF
11
+ foo 0.1.1 /usr/local/lib/ruby/gems/1.8/doc/foo-0.1.1/ri
12
+ foo 1.1.1 /usr/local/lib/ruby/gems/1.8/doc/foo-1.1.1/ri
13
+ bar 0.1.1 /usr/local/lib/ruby/gems/1.8/doc/bar-0.1.1/ri
14
+ baz 0.1.1 /usr/local/lib/ruby/gems/1.8/doc/baz-0.1.1/ri
15
+ EOF
16
+ GEM_DIR_INFO = data.split(/\n/).map{|l| l.split(/\s+/)}
17
+
18
+ include FastRI::Util
19
+ def test_gem_info_for_path
20
+ assert_equal(["foo", "0.1.1", "/usr/local/lib/ruby/gems/1.8/doc/foo-0.1.1/ri"],
21
+ gem_info_for_path("/usr/local/lib/ruby/gems/1.8/doc/foo-0.1.1/ri/Array/cdesc-Array.yaml", GEM_DIR_INFO))
22
+ assert_equal(["foo", "1.1.1", "/usr/local/lib/ruby/gems/1.8/doc/foo-1.1.1/ri"],
23
+ gem_info_for_path("/usr/local/lib/ruby/gems/1.8/doc/foo-1.1.1/ri/Array/cdesc-Array.yaml", GEM_DIR_INFO))
24
+ assert_equal(["bar", "0.1.1", "/usr/local/lib/ruby/gems/1.8/doc/bar-0.1.1/ri"],
25
+ gem_info_for_path("/usr/local/lib/ruby/gems/1.8/doc/bar-0.1.1/ri/Array/cdesc-Array.yaml", GEM_DIR_INFO))
26
+ assert_equal(["baz", "0.1.1", "/usr/local/lib/ruby/gems/1.8/doc/baz-0.1.1/ri"],
27
+ gem_info_for_path("/usr/local/lib/ruby/gems/1.8/doc/baz-0.1.1/ri/Array/cdesc-Array.yaml", GEM_DIR_INFO))
28
+ assert_nil(gem_info_for_path("/usr/lib/ruby/gems/1.8/doc/baz-1.1.1/ri/Array/cdesc-Array.yaml", GEM_DIR_INFO))
29
+ end
30
+
31
+ def test_gem_relpath_to_full_name
32
+ assert_equal("Array", gem_relpath_to_full_name("Array/cdesc-Array.yaml"))
33
+ assert_equal("String", gem_relpath_to_full_name("String/cdesc-String.yaml"))
34
+ assert_equal("Foo::Bar::String", gem_relpath_to_full_name("Foo/Bar/String/cdesc-String.yaml"))
35
+ assert_equal("Foo::Bar#eql?", gem_relpath_to_full_name("Foo/Bar/eql%3f-i.yaml"))
36
+ assert_equal("Foo::Bar.eql?", gem_relpath_to_full_name("Foo/Bar/eql%3f-c.yaml"))
37
+ end
38
+ end
metadata CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: fastri
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1.1
7
- date: 2006-11-10 00:00:00 +01:00
6
+ version: 0.2.0.1
7
+ date: 2006-11-15 00:00:00 +01:00
8
8
  summary: RI docs across machines, faster and smarter than ri.
9
9
  require_paths:
10
10
  - lib
11
11
  email: mfp@acm.org
12
12
  homepage: http://eigenclass.org/hiki.rb?fastri
13
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.
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 smarter than ri, and can find classes anywhere in the hierarchy without specifying the "full path". FastRI can perform fast full-text searches. It also knows about gems, and can tell you e.g. which extensions to a core class were added by a specific gem.
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin
@@ -60,6 +60,9 @@ files:
60
60
  - lib/fastri/ri_index.rb
61
61
  - lib/fastri/ri_service.rb
62
62
  - lib/fastri/version.rb
63
+ - lib/fastri/util.rb
64
+ - lib/fastri/full_text_indexer.rb
65
+ - lib/fastri/full_text_index.rb
63
66
  - lib/fastri/name_descriptor.rb
64
67
  - CHANGES
65
68
  - COPYING
@@ -68,14 +71,22 @@ files:
68
71
  - Rakefile
69
72
  - README.en
70
73
  - test/test_ri_index.rb
74
+ - test/test_full_text_index.rb
71
75
  - test/test_functional_ri_service.rb
76
+ - test/test_full_text_indexer.rb
72
77
  - test/test_name_descriptor.rb
78
+ - test/test_util.rb
79
+ - test/test_integration_full_text_index.rb
73
80
  - setup.rb
74
81
  - pre-install.rb
75
82
  test_files:
76
83
  - test/test_ri_index.rb
84
+ - test/test_full_text_index.rb
77
85
  - test/test_functional_ri_service.rb
86
+ - test/test_full_text_indexer.rb
78
87
  - test/test_name_descriptor.rb
88
+ - test/test_util.rb
89
+ - test/test_integration_full_text_index.rb
79
90
  rdoc_options:
80
91
  - --title
81
92
  - "FastRI: better, faster ri"