did_you_mean 0.10.0 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -18
  3. data/CHANGELOG.md +28 -3
  4. data/Gemfile +0 -7
  5. data/README.md +2 -16
  6. data/Rakefile +1 -13
  7. data/benchmark/memory_usage.rb +4 -4
  8. data/did_you_mean.gemspec +2 -12
  9. data/evaluation/calculator.rb +5 -5
  10. data/lib/did_you_mean.rb +18 -26
  11. data/lib/did_you_mean/core_ext/name_error.rb +15 -25
  12. data/lib/did_you_mean/formatter.rb +5 -11
  13. data/lib/did_you_mean/jaro_winkler.rb +3 -4
  14. data/lib/did_you_mean/levenshtein.rb +1 -1
  15. data/lib/did_you_mean/{finders.rb → spell_checkable.rb} +4 -12
  16. data/lib/did_you_mean/spell_checkers/method_name_checker.rb +54 -0
  17. data/lib/did_you_mean/{finders/name_error_finders.rb → spell_checkers/name_error_checkers.rb} +7 -7
  18. data/lib/did_you_mean/{finders/name_error_finders/class_finder.rb → spell_checkers/name_error_checkers/class_name_checker.rb} +8 -26
  19. data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +20 -0
  20. data/lib/did_you_mean/spell_checkers/null_checker.rb +6 -0
  21. data/lib/did_you_mean/version.rb +1 -1
  22. data/test/core_ext/name_error_extension_test.rb +20 -23
  23. data/test/correctable/class_name_test.rb +14 -14
  24. data/test/correctable/method_name_test.rb +21 -21
  25. data/test/correctable/variable_name_test.rb +30 -25
  26. data/test/{word_collection_test.rb → spell_checker_test.rb} +20 -20
  27. data/test/test_helper.rb +5 -8
  28. metadata +15 -50
  29. data/ext/did_you_mean/extconf.rb +0 -2
  30. data/ext/did_you_mean/method_receiver.c +0 -20
  31. data/lib/did_you_mean/core_ext/no_method_error.rb +0 -46
  32. data/lib/did_you_mean/core_ext/rubinius.rb +0 -16
  33. data/lib/did_you_mean/finders/method_finder.rb +0 -62
  34. data/lib/did_you_mean/finders/name_error_finders/name_finder.rb +0 -18
  35. data/lib/did_you_mean/test_helper.rb +0 -7
  36. data/test/core_ext/no_method_error_extension_test.rb +0 -38
@@ -1,40 +1,40 @@
1
1
  require 'test_helper'
2
2
 
3
- class FinderTest < Minitest::Test
3
+ class SpellCheckerTest < Minitest::Test
4
4
  class WordCollection
5
- include DidYouMean::BaseFinder
5
+ include DidYouMean::SpellCheckable
6
6
 
7
7
  def initialize(words)
8
8
  @words = words
9
9
  end
10
10
 
11
- def similar_to(input, filter = EMPTY)
12
- @suggestions, @input = nil, input
11
+ def similar_to(input)
12
+ @corrections, @input = nil, input
13
13
 
14
- suggestions
14
+ corrections
15
15
  end
16
16
 
17
- def searches
17
+ def candidates
18
18
  { @input => @words }
19
19
  end
20
20
  end
21
21
 
22
22
  def test_similar_to_corrects_mistypes
23
23
 
24
- assert_suggestion 'foo', collection('foo', 'fork') .similar_to('doo')
25
- assert_suggestion 'email', collection('email', 'fail', 'eval').similar_to('meail')
26
- assert_suggestion 'fail', collection('email', 'fail', 'eval').similar_to('fial')
27
- assert_suggestion 'fail', collection('email', 'fail', 'eval').similar_to('afil')
28
- assert_suggestion 'eval', collection('email', 'fail', 'eval').similar_to('eavl')
29
- assert_suggestion 'eval', collection('email', 'fail', 'eval').similar_to('veal')
30
- assert_suggestion 'sub!', collection('sub', 'gsub', 'sub!') .similar_to('suv!')
31
- assert_suggestion 'sub', collection('sub', 'gsub', 'sub!') .similar_to('suv')
24
+ assert_correction 'foo', collection('foo', 'fork') .similar_to('doo')
25
+ assert_correction 'email', collection('email', 'fail', 'eval').similar_to('meail')
26
+ assert_correction 'fail', collection('email', 'fail', 'eval').similar_to('fial')
27
+ assert_correction 'fail', collection('email', 'fail', 'eval').similar_to('afil')
28
+ assert_correction 'eval', collection('email', 'fail', 'eval').similar_to('eavl')
29
+ assert_correction 'eval', collection('email', 'fail', 'eval').similar_to('veal')
30
+ assert_correction 'sub!', collection('sub', 'gsub', 'sub!') .similar_to('suv!')
31
+ assert_correction 'sub', collection('sub', 'gsub', 'sub!') .similar_to('suv')
32
32
 
33
33
  assert_equal %w(gsub! gsub), collection('sub', 'gsub', 'gsub!').similar_to('gsuv!')
34
34
  assert_equal %w(sub! sub gsub!), collection('sub', 'sub!', 'gsub', 'gsub!').similar_to('ssub!')
35
35
 
36
36
  group_methods = %w(groups group_url groups_url group_path)
37
- assert_suggestion 'groups', collection(group_methods).similar_to('group')
37
+ assert_correction 'groups', collection(group_methods).similar_to('group')
38
38
 
39
39
  group_classes = %w(
40
40
  GroupMembership
@@ -47,8 +47,8 @@ class FinderTest < Minitest::Test
47
47
  NullGroupMembership
48
48
  )
49
49
 
50
- #assert_suggestion 'GroupMembership', collection(group_classes).similar_to('GroupMemberhip')
51
- assert_suggestion 'GroupMembershipDecorator', collection(group_classes).similar_to('GroupMemberhipDecorator')
50
+ assert_correction 'GroupMembership', collection(group_classes).similar_to('GroupMemberhip')
51
+ assert_correction 'GroupMembershipDecorator', collection(group_classes).similar_to('GroupMemberhipDecorator')
52
52
 
53
53
  names = %w(first_name_change first_name_changed? first_name_will_change!)
54
54
  assert_equal names, collection(names).similar_to('first_name_change!')
@@ -58,9 +58,9 @@ class FinderTest < Minitest::Test
58
58
  end
59
59
 
60
60
  def test_similar_to_corrects_misspells
61
- assert_suggestion 'descendants', collection('descendants') .similar_to('dependents')
62
- assert_suggestion 'drag_to', collection('drag_to') .similar_to('drag')
63
- assert_suggestion 'set_result_count', collection('set_result_count').similar_to('set_result')
61
+ assert_correction 'descendants', collection('descendants') .similar_to('dependents')
62
+ assert_correction 'drag_to', collection('drag_to') .similar_to('drag')
63
+ assert_correction 'set_result_count', collection('set_result_count').similar_to('set_result')
64
64
  end
65
65
 
66
66
  def test_similar_to_sorts_results_by_simiarity
@@ -1,14 +1,11 @@
1
- NAME_ERROR = (___ rescue $!).class
2
-
3
1
  require 'minitest/autorun'
4
2
  require 'minitest/unit'
5
3
  require 'did_you_mean'
6
4
 
7
- begin
8
- MiniTest::Test
9
- rescue NameError
10
- MiniTest::Test = MiniTest::Unit::TestCase
5
+ module DidYouMean::TestHelper
6
+ def assert_correction(expected, array)
7
+ assert_equal [expected], array, "Expected #{array.inspect} to only include #{expected.inspect}"
8
+ end
11
9
  end
12
10
 
13
- require 'did_you_mean/test_helper'
14
- MiniTest::Test.send :include, DidYouMean::TestHelper
11
+ MiniTest::Test.include(DidYouMean::TestHelper)
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: did_you_mean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: interception
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +38,6 @@ dependencies:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake-compiler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: minitest
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -85,8 +57,7 @@ description: '"did you mean?" experience in Ruby: the error message will tell yo
85
57
  email:
86
58
  - mail@yukinishijima.net
87
59
  executables: []
88
- extensions:
89
- - ext/did_you_mean/extconf.rb
60
+ extensions: []
90
61
  extra_rdoc_files: []
91
62
  files:
92
63
  - ".gitignore"
@@ -108,31 +79,26 @@ files:
108
79
  - evaluation/calculator.rb
109
80
  - evaluation/dictionary_generator.rb
110
81
  - evaluation/incorrect_words.yaml
111
- - ext/did_you_mean/extconf.rb
112
- - ext/did_you_mean/method_receiver.c
113
82
  - lib/did_you_mean.rb
114
83
  - lib/did_you_mean/core_ext/name_error.rb
115
- - lib/did_you_mean/core_ext/no_method_error.rb
116
- - lib/did_you_mean/core_ext/rubinius.rb
117
- - lib/did_you_mean/finders.rb
118
- - lib/did_you_mean/finders/method_finder.rb
119
- - lib/did_you_mean/finders/name_error_finders.rb
120
- - lib/did_you_mean/finders/name_error_finders/class_finder.rb
121
- - lib/did_you_mean/finders/name_error_finders/name_finder.rb
122
84
  - lib/did_you_mean/formatter.rb
123
85
  - lib/did_you_mean/jaro_winkler.rb
124
86
  - lib/did_you_mean/levenshtein.rb
125
- - lib/did_you_mean/test_helper.rb
87
+ - lib/did_you_mean/spell_checkable.rb
88
+ - lib/did_you_mean/spell_checkers/method_name_checker.rb
89
+ - lib/did_you_mean/spell_checkers/name_error_checkers.rb
90
+ - lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
91
+ - lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
92
+ - lib/did_you_mean/spell_checkers/null_checker.rb
126
93
  - lib/did_you_mean/version.rb
127
94
  - test/core_ext/name_error_extension_test.rb
128
- - test/core_ext/no_method_error_extension_test.rb
129
95
  - test/correctable/class_name_test.rb
130
96
  - test/correctable/method_name_test.rb
131
97
  - test/correctable/uncorrectable_name_test.rb
132
98
  - test/correctable/variable_name_test.rb
133
99
  - test/edit_distance/jaro_winkler_test.rb
100
+ - test/spell_checker_test.rb
134
101
  - test/test_helper.rb
135
- - test/word_collection_test.rb
136
102
  homepage: https://github.com/yuki24/did_you_mean
137
103
  licenses:
138
104
  - MIT
@@ -145,25 +111,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
111
  requirements:
146
112
  - - ">="
147
113
  - !ruby/object:Gem::Version
148
- version: 1.9.3
114
+ version: 2.3.0dev
149
115
  required_rubygems_version: !ruby/object:Gem::Requirement
150
116
  requirements:
151
- - - ">="
117
+ - - ">"
152
118
  - !ruby/object:Gem::Version
153
- version: '0'
119
+ version: 1.3.1
154
120
  requirements: []
155
121
  rubyforge_project:
156
- rubygems_version: 2.4.8
122
+ rubygems_version: 2.5.0
157
123
  signing_key:
158
124
  specification_version: 4
159
125
  summary: '"Did you mean?" experience in Ruby'
160
126
  test_files:
161
127
  - test/core_ext/name_error_extension_test.rb
162
- - test/core_ext/no_method_error_extension_test.rb
163
128
  - test/correctable/class_name_test.rb
164
129
  - test/correctable/method_name_test.rb
165
130
  - test/correctable/uncorrectable_name_test.rb
166
131
  - test/correctable/variable_name_test.rb
167
132
  - test/edit_distance/jaro_winkler_test.rb
133
+ - test/spell_checker_test.rb
168
134
  - test/test_helper.rb
169
- - test/word_collection_test.rb
@@ -1,2 +0,0 @@
1
- require 'mkmf'
2
- create_makefile 'did_you_mean/method_receiver'
@@ -1,20 +0,0 @@
1
- #include <ruby.h>
2
-
3
- static const rb_data_type_t *type;
4
-
5
- static VALUE
6
- name_err_receiver(VALUE self)
7
- {
8
- VALUE *ptr, mesg = rb_attr_get(self, rb_intern("mesg"));
9
- TypedData_Get_Struct(mesg, VALUE, type, ptr);
10
- return ptr[1];
11
- }
12
-
13
- void
14
- Init_method_receiver()
15
- {
16
- VALUE err_mesg = rb_funcall(rb_cNameErrorMesg, '!', 3, Qnil, Qnil, Qnil);
17
- type = RTYPEDDATA(err_mesg)->type;
18
-
19
- rb_define_method(rb_eNameError, "receiver", name_err_receiver, 0);
20
- }
@@ -1,46 +0,0 @@
1
- case RUBY_ENGINE
2
- when 'ruby'
3
- name_error = begin
4
- raise_name_error
5
- rescue NameError => e
6
- e
7
- end
8
-
9
- unless name_error.respond_to?(:receiver)
10
- require 'did_you_mean/method_receiver'
11
- end
12
- when 'jruby'
13
- NoMethodError.class_eval do
14
- def to_s
15
- receiver unless defined?(@receiver)
16
- super
17
- end
18
-
19
- def receiver
20
- @receiver ||= begin
21
- field = JRuby.reference(__message__).java_class.getDeclaredField("object")
22
- field.setAccessible(true)
23
- field.get(__message__)
24
- rescue
25
- nil
26
- end
27
- end
28
-
29
- private
30
-
31
- if JRUBY_VERSION >= '9.0.0.0'
32
- def __message__
33
- JRuby.reference(self).getMessage
34
- end
35
- else
36
- def __message__
37
- error = JRuby.reference(self)
38
- error.java_class.getField("message").get(error)
39
- end
40
- end
41
- end
42
-
43
- when 'rbx'
44
- require 'did_you_mean/core_ext/rubinius'
45
- NoMethodError.class_eval { attr_reader :receiver }
46
- end
@@ -1,16 +0,0 @@
1
- if defined?(Rubinius)
2
- class << Rubinius
3
- alias raise_with_no_receiver_capturer raise_exception
4
-
5
- def raise_exception(exc)
6
- if exc.is_a?(NoMethodError)
7
- bt = Rubinius::VM.backtrace(0, true).detect do |x|
8
- x.method.name == :method_missing
9
- end
10
- exc.instance_variable_set(:@receiver, bt.variables.self) if bt
11
- end
12
-
13
- raise_with_no_receiver_capturer(exc)
14
- end
15
- end
16
- end
@@ -1,62 +0,0 @@
1
- module DidYouMean
2
- class MethodFinder
3
- include BaseFinder
4
- attr_reader :method_name, :receiver
5
-
6
- def initialize(exception)
7
- @method_name = exception.name
8
- @receiver = exception.receiver
9
- @binding = exception.frame_binding
10
- @location = exception.backtrace.first
11
- @ivar_names = NameFinder.new(exception).ivar_names
12
- end
13
-
14
- def searches
15
- {
16
- method_name => method_names,
17
- receiver_name.to_s => @ivar_names
18
- }
19
- end
20
-
21
- def method_names
22
- method_names = receiver.methods + receiver.singleton_methods
23
- method_names += receiver.private_methods if receiver.equal?(@binding.eval("self"))
24
- method_names.delete(method_name)
25
- method_names.uniq!
26
- method_names
27
- end
28
-
29
- def receiver_name
30
- return unless @receiver.nil?
31
-
32
- abs_path, lineno, label =
33
- /(.*):(.*):in `(.*)'/ =~ @location && [$1, $2.to_i, $3]
34
-
35
- line =
36
- case abs_path
37
- when "(irb)"
38
- Readline::HISTORY.to_a.last
39
- when "(pry)"
40
- ::Pry.history.to_a.last
41
- else
42
- File.open(abs_path) do |file|
43
- file.detect { file.lineno == lineno }
44
- end if File.exist?(abs_path)
45
- end
46
-
47
- /@(\w+)*\.#{@method_name}/ =~ line.to_s && $1
48
- end
49
- end
50
-
51
- if RUBY_ENGINE == 'rbx'
52
- module MethodFinder::RubiniusSupport
53
- def self.new(exception)
54
- if exception.receiver === exception.frame_binding.eval("self")
55
- NameErrorFinders.new(exception)
56
- else
57
- MethodFinder.new(exception)
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,18 +0,0 @@
1
- module DidYouMean
2
- class NameFinder
3
- include BaseFinder
4
- attr_reader :name, :method_names, :lvar_names, :ivar_names, :cvar_names
5
-
6
- def initialize(exception)
7
- @name = exception.name.to_s.tr(AT, EMPTY)
8
- @lvar_names = exception.frame_binding.eval("local_variables")
9
- @method_names = exception.frame_binding.eval("methods + private_methods")
10
- @cvar_names = exception.frame_binding.eval("self.class.class_variables")
11
- @ivar_names = exception.frame_binding.eval("instance_variables")
12
- end
13
-
14
- def searches
15
- {name => (lvar_names + method_names + ivar_names + cvar_names)}
16
- end
17
- end
18
- end
@@ -1,7 +0,0 @@
1
- module DidYouMean
2
- module TestHelper
3
- def assert_suggestion(expected, array)
4
- assert_equal [expected], array, "Expected #{array.inspect} to only include #{expected.inspect}"
5
- end
6
- end
7
- end
@@ -1,38 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NoMethodErrorExtensionTest < Minitest::Test
4
- def test_receiver_with_string
5
- receiver = "receiver"
6
- error = assert_raises(NoMethodError) do
7
- receiver.doesnt_exist
8
- end
9
-
10
- assert_same receiver, error.receiver
11
- end
12
-
13
- def test_receiver_with_class
14
- error = assert_raises(NoMethodError) do
15
- Object.doesnt_exist
16
- end
17
-
18
- assert_same Object, error.receiver
19
- end
20
-
21
- def test_receiver_with_class_after_calling_to_s
22
- error = assert_raises(NoMethodError) do
23
- Object.doesnt_exist
24
- end
25
-
26
- error.to_s
27
- assert_same Object, error.receiver
28
- end
29
-
30
- def test_receiver_with_class_after_calling_message
31
- error = assert_raises(NoMethodError) do
32
- Object.doesnt_exist
33
- end
34
-
35
- error.message
36
- assert_same Object, error.receiver
37
- end
38
- end