did_you_mean 1.5.0 → 1.6.2

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/.github/dependabot.yml +6 -0
  3. data/.github/workflows/ruby.yml +3 -3
  4. data/CHANGELOG.md +37 -2
  5. data/README.md +7 -15
  6. data/Rakefile +9 -2
  7. data/documentation/tree_spell_checker_api.md +1 -1
  8. data/lib/did_you_mean/core_ext/name_error.rb +43 -11
  9. data/lib/did_you_mean/formatter.rb +44 -0
  10. data/lib/did_you_mean/formatters/plain_formatter.rb +3 -32
  11. data/lib/did_you_mean/formatters/verbose_formatter.rb +5 -44
  12. data/lib/did_you_mean/spell_checker.rb +9 -9
  13. data/lib/did_you_mean/spell_checkers/method_name_checker.rb +3 -0
  14. data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +4 -1
  15. data/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb +20 -0
  16. data/lib/did_you_mean/spell_checkers/require_path_checker.rb +5 -1
  17. data/lib/did_you_mean/verbose.rb +2 -4
  18. data/lib/did_you_mean/version.rb +1 -1
  19. data/lib/did_you_mean.rb +51 -8
  20. data/test/core_ext/test_name_error_extension.rb +15 -8
  21. data/test/helper.rb +14 -0
  22. data/test/lib/core_assertions.rb +757 -0
  23. data/test/lib/envutil.rb +372 -0
  24. data/test/lib/find_executable.rb +22 -0
  25. data/test/lib/helper.rb +3 -0
  26. data/test/spell_checking/test_key_name_check.rb +7 -7
  27. data/test/spell_checking/test_method_name_check.rb +10 -10
  28. data/test/spell_checking/test_pattern_key_name_check.rb +20 -0
  29. data/test/spell_checking/test_require_path_check.rb +3 -3
  30. data/test/spell_checking/test_uncorrectable_name_check.rb +1 -1
  31. data/test/spell_checking/test_variable_name_check.rb +24 -12
  32. data/test/test_ractor_compatibility.rb +117 -0
  33. data/test/test_spell_checker.rb +1 -0
  34. data/test/tree_spell/test_change_word.rb +1 -1
  35. metadata +21 -8
  36. data/test/test_verbose_formatter.rb +0 -23
@@ -0,0 +1,117 @@
1
+ require_relative './helper'
2
+
3
+ return if not DidYouMean::TestHelper.ractor_compatible?
4
+
5
+ class RactorCompatibilityTest < Test::Unit::TestCase
6
+ def test_class_name_suggestion_works_in_ractor
7
+ assert_ractor(<<~CODE, require_relative: "helper")
8
+ class ::Book; end
9
+ include DidYouMean::TestHelper
10
+ error = Ractor.new {
11
+ begin
12
+ Boook
13
+ rescue NameError => e
14
+ e.corrections # It is important to call the #corrections method within Ractor.
15
+ e
16
+ end
17
+ }.take
18
+
19
+ assert_correction "Book", error.corrections
20
+ CODE
21
+ end
22
+
23
+ def test_key_name_suggestion_works_in_ractor
24
+ assert_ractor(<<~CODE, require_relative: "helper")
25
+ include DidYouMean::TestHelper
26
+ error = Ractor.new {
27
+ begin
28
+ hash = { "foo" => 1, bar: 2 }
29
+
30
+ hash.fetch(:bax)
31
+ rescue KeyError => e
32
+ e.corrections # It is important to call the #corrections method within Ractor.
33
+ e
34
+ end
35
+ }.take
36
+
37
+ assert_correction ":bar", error.corrections
38
+ assert_match "Did you mean? :bar", get_message(error)
39
+ CODE
40
+ end
41
+
42
+ def test_method_name_suggestion_works_in_ractor
43
+ assert_ractor(<<~CODE, require_relative: "helper")
44
+ include DidYouMean::TestHelper
45
+ error = Ractor.new {
46
+ begin
47
+ self.to__s
48
+ rescue NoMethodError => e
49
+ e.corrections # It is important to call the #corrections method within Ractor.
50
+ e
51
+ end
52
+ }.take
53
+
54
+ assert_correction :to_s, error.corrections
55
+ assert_match "Did you mean? to_s", get_message(error)
56
+ CODE
57
+ end
58
+
59
+ if defined?(::NoMatchingPatternKeyError)
60
+ def test_pattern_key_name_suggestion_works_in_ractor
61
+ assert_ractor(<<~CODE, require_relative: "helper")
62
+ include DidYouMean::TestHelper
63
+ error = Ractor.new {
64
+ begin
65
+ eval(<<~RUBY, binding, __FILE__, __LINE__)
66
+ hash = {foo: 1, bar: 2, baz: 3}
67
+ hash => {fooo:}
68
+ fooo = 1 # suppress "unused variable: fooo" warning
69
+ RUBY
70
+ rescue NoMatchingPatternKeyError => e
71
+ e.corrections # It is important to call the #corrections method within Ractor.
72
+ e
73
+ end
74
+ }.take
75
+
76
+ assert_correction ":foo", error.corrections
77
+ assert_match "Did you mean? :foo", get_message(error)
78
+ CODE
79
+ end
80
+ end
81
+
82
+ def test_can_raise_other_name_error_in_ractor
83
+ assert_ractor(<<~CODE, require_relative: "helper")
84
+ class FirstNameError < NameError; end
85
+ include DidYouMean::TestHelper
86
+ error = Ractor.new {
87
+ begin
88
+ raise FirstNameError, "Other name error"
89
+ rescue FirstNameError => e
90
+ e.corrections # It is important to call the #corrections method within Ractor.
91
+ e
92
+ end
93
+ }.take
94
+
95
+ assert_not_match(/Did you mean\?/, error.message)
96
+ CODE
97
+ end
98
+
99
+ def test_variable_name_suggestion_works_in_ractor
100
+ assert_ractor(<<~CODE, require_relative: "helper")
101
+ include DidYouMean::TestHelper
102
+ error = Ractor.new {
103
+ in_ractor = in_ractor = 1
104
+
105
+ begin
106
+ in_reactor
107
+ rescue NameError => e
108
+ e.corrections # It is important to call the #corrections method within Ractor.
109
+ e
110
+ end
111
+ }.take
112
+
113
+ assert_correction :in_ractor, error.corrections
114
+ assert_match "Did you mean? in_ractor", get_message(error)
115
+ CODE
116
+ end
117
+ end
@@ -10,6 +10,7 @@ class SpellCheckerTest < Test::Unit::TestCase
10
10
  assert_spell 'eval', input: 'veal', dictionary: ['email', 'fail', 'eval']
11
11
  assert_spell 'sub!', input: 'suv!', dictionary: ['sub', 'gsub', 'sub!']
12
12
  assert_spell 'sub', input: 'suv', dictionary: ['sub', 'gsub', 'sub!']
13
+ assert_spell 'Foo', input: 'FOo', dictionary: ['Foo', 'FOo']
13
14
 
14
15
  assert_spell %w(gsub! gsub), input: 'gsuv!', dictionary: %w(sub gsub gsub!)
15
16
  assert_spell %w(sub! sub gsub!), input: 'ssub!', dictionary: %w(sub sub! gsub gsub!)
@@ -8,7 +8,7 @@ class ChangeWordTest < Test::Unit::TestCase
8
8
  @len = @input.length
9
9
  end
10
10
 
11
- def test_deleletion
11
+ def test_deletion
12
12
  assert_match @cw.deletion(5), 'spec/ervices/anything_spec'
13
13
  assert_match @cw.deletion(@len - 1), 'spec/services/anything_spe'
14
14
  assert_match @cw.deletion(0), 'pec/services/anything_spec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: did_you_mean
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-22 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/dependabot.yml"
34
35
  - ".github/workflows/ruby.yml"
35
36
  - ".gitignore"
36
37
  - CHANGELOG.md
@@ -55,6 +56,7 @@ files:
55
56
  - lib/did_you_mean.rb
56
57
  - lib/did_you_mean/core_ext/name_error.rb
57
58
  - lib/did_you_mean/experimental.rb
59
+ - lib/did_you_mean/formatter.rb
58
60
  - lib/did_you_mean/formatters/plain_formatter.rb
59
61
  - lib/did_you_mean/formatters/verbose_formatter.rb
60
62
  - lib/did_you_mean/jaro_winkler.rb
@@ -66,6 +68,7 @@ files:
66
68
  - lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
67
69
  - lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
68
70
  - lib/did_you_mean/spell_checkers/null_checker.rb
71
+ - lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb
69
72
  - lib/did_you_mean/spell_checkers/require_path_checker.rb
70
73
  - lib/did_you_mean/tree_spell_checker.rb
71
74
  - lib/did_you_mean/verbose.rb
@@ -76,15 +79,20 @@ files:
76
79
  - test/fixtures/mini_dir.yml
77
80
  - test/fixtures/rspec_dir.yml
78
81
  - test/helper.rb
82
+ - test/lib/core_assertions.rb
83
+ - test/lib/envutil.rb
84
+ - test/lib/find_executable.rb
85
+ - test/lib/helper.rb
79
86
  - test/spell_checking/test_class_name_check.rb
80
87
  - test/spell_checking/test_key_name_check.rb
81
88
  - test/spell_checking/test_method_name_check.rb
89
+ - test/spell_checking/test_pattern_key_name_check.rb
82
90
  - test/spell_checking/test_require_path_check.rb
83
91
  - test/spell_checking/test_uncorrectable_name_check.rb
84
92
  - test/spell_checking/test_variable_name_check.rb
93
+ - test/test_ractor_compatibility.rb
85
94
  - test/test_spell_checker.rb
86
95
  - test/test_tree_spell_checker.rb
87
- - test/test_verbose_formatter.rb
88
96
  - test/tree_spell/change_word.rb
89
97
  - test/tree_spell/human_typo.rb
90
98
  - test/tree_spell/test_change_word.rb
@@ -94,7 +102,7 @@ homepage: https://github.com/ruby/did_you_mean
94
102
  licenses:
95
103
  - MIT
96
104
  metadata: {}
97
- post_install_message:
105
+ post_install_message:
98
106
  rdoc_options: []
99
107
  require_paths:
100
108
  - lib
@@ -109,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
117
  - !ruby/object:Gem::Version
110
118
  version: '0'
111
119
  requirements: []
112
- rubygems_version: 3.1.3
113
- signing_key:
120
+ rubygems_version: 3.4.0.dev
121
+ signing_key:
114
122
  specification_version: 4
115
123
  summary: '"Did you mean?" experience in Ruby'
116
124
  test_files:
@@ -120,15 +128,20 @@ test_files:
120
128
  - test/fixtures/mini_dir.yml
121
129
  - test/fixtures/rspec_dir.yml
122
130
  - test/helper.rb
131
+ - test/lib/core_assertions.rb
132
+ - test/lib/envutil.rb
133
+ - test/lib/find_executable.rb
134
+ - test/lib/helper.rb
123
135
  - test/spell_checking/test_class_name_check.rb
124
136
  - test/spell_checking/test_key_name_check.rb
125
137
  - test/spell_checking/test_method_name_check.rb
138
+ - test/spell_checking/test_pattern_key_name_check.rb
126
139
  - test/spell_checking/test_require_path_check.rb
127
140
  - test/spell_checking/test_uncorrectable_name_check.rb
128
141
  - test/spell_checking/test_variable_name_check.rb
142
+ - test/test_ractor_compatibility.rb
129
143
  - test/test_spell_checker.rb
130
144
  - test/test_tree_spell_checker.rb
131
- - test/test_verbose_formatter.rb
132
145
  - test/tree_spell/change_word.rb
133
146
  - test/tree_spell/human_typo.rb
134
147
  - test/tree_spell/test_change_word.rb
@@ -1,23 +0,0 @@
1
- require_relative './helper'
2
-
3
- class VerboseFormatterTest < Test::Unit::TestCase
4
- def setup
5
- require_relative File.join(DidYouMean::TestHelper.root, 'verbose')
6
-
7
- DidYouMean.formatter = DidYouMean::VerboseFormatter.new
8
- end
9
-
10
- def teardown
11
- DidYouMean.formatter = DidYouMean::PlainFormatter.new
12
- end
13
-
14
- def test_message
15
- @error = assert_raise(NoMethodError){ 1.zeor? }
16
-
17
- assert_match <<~MESSAGE.strip, @error.message
18
- undefined method `zeor?' for 1:Integer
19
-
20
- Did you mean? zero?
21
- MESSAGE
22
- end
23
- end