did_you_mean 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +48 -0
  3. data/CHANGELOG.md +75 -75
  4. data/Gemfile +2 -1
  5. data/README.md +2 -32
  6. data/Rakefile +4 -5
  7. data/appveyor.yml +25 -0
  8. data/did_you_mean.gemspec +6 -4
  9. data/documentation/CHANGELOG.md.erb +8 -0
  10. data/documentation/changelog_generator.rb +34 -0
  11. data/documentation/human_typo_api.md +20 -0
  12. data/documentation/tree_spell_algorithm.md +82 -0
  13. data/documentation/tree_spell_checker_api.md +24 -0
  14. data/lib/did_you_mean.rb +17 -16
  15. data/lib/did_you_mean/experimental.rb +2 -2
  16. data/lib/did_you_mean/experimental/initializer_name_correction.rb +1 -1
  17. data/lib/did_you_mean/experimental/ivar_name_correction.rb +3 -1
  18. data/lib/did_you_mean/levenshtein.rb +1 -1
  19. data/lib/did_you_mean/spell_checker.rb +7 -7
  20. data/lib/did_you_mean/spell_checkers/key_error_checker.rb +8 -2
  21. data/lib/did_you_mean/spell_checkers/method_name_checker.rb +14 -6
  22. data/lib/did_you_mean/spell_checkers/name_error_checkers.rb +2 -2
  23. data/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb +5 -5
  24. data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +1 -1
  25. data/lib/did_you_mean/tree_spell_checker.rb +137 -0
  26. data/lib/did_you_mean/verbose.rb +2 -2
  27. data/lib/did_you_mean/version.rb +1 -1
  28. data/test/core_ext/test_name_error_extension.rb +48 -0
  29. data/test/edit_distance/{jaro_winkler_test.rb → test_jaro_winkler.rb} +2 -2
  30. data/test/fixtures/mini_dir.yml +15 -0
  31. data/test/fixtures/rspec_dir.yml +112 -0
  32. data/test/helper.rb +29 -0
  33. data/test/spell_checking/{class_name_check_test.rb → test_class_name_check.rb} +12 -10
  34. data/test/spell_checking/{key_name_check_test.rb → test_key_name_check.rb} +18 -8
  35. data/test/spell_checking/{method_name_check_test.rb → test_method_name_check.rb} +17 -15
  36. data/test/spell_checking/{uncorrectable_name_check_test.rb → test_uncorrectable_name_check.rb} +3 -3
  37. data/test/spell_checking/{variable_name_check_test.rb → test_variable_name_check.rb} +18 -16
  38. data/test/{spell_checker_test.rb → test_spell_checker.rb} +2 -2
  39. data/test/test_tree_spell_checker.rb +173 -0
  40. data/test/test_verbose_formatter.rb +21 -0
  41. data/test/tree_spell/change_word.rb +61 -0
  42. data/test/tree_spell/human_typo.rb +89 -0
  43. data/test/tree_spell/test_change_word.rb +38 -0
  44. data/test/tree_spell/test_explore.rb +128 -0
  45. data/test/tree_spell/test_human_typo.rb +24 -0
  46. metadata +47 -58
  47. data/.travis.yml +0 -23
  48. data/test/core_ext/name_error_extension_test.rb +0 -51
  49. data/test/experimental/initializer_name_correction_test.rb +0 -15
  50. data/test/experimental/method_name_checker_test.rb +0 -13
  51. data/test/test_helper.rb +0 -13
  52. data/test/verbose_formatter_test.rb +0 -22
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require_relative '../helper'
2
2
 
3
3
  module ACRONYM
4
4
  end
@@ -27,44 +27,46 @@ class Book
27
27
  end
28
28
  end
29
29
 
30
- class ClassNameCheckTest < Minitest::Test
30
+ class ClassNameCheckTest < Test::Unit::TestCase
31
+ include DidYouMean::TestHelper
32
+
31
33
  def test_corrections
32
- error = assert_raises(NameError) { ::Bo0k }
34
+ error = assert_raise(NameError) { ::Bo0k }
33
35
  assert_correction "Book", error.corrections
34
36
  end
35
37
 
36
38
  def test_corrections_include_case_specific_class_name
37
- error = assert_raises(NameError) { ::Acronym }
39
+ error = assert_raise(NameError) { ::Acronym }
38
40
  assert_correction "ACRONYM", error.corrections
39
41
  end
40
42
 
41
43
  def test_corrections_include_top_level_class_name
42
- error = assert_raises(NameError) { Project.bo0k }
44
+ error = assert_raise(NameError) { Project.bo0k }
43
45
  assert_correction "Book", error.corrections
44
46
  end
45
47
 
46
48
  def test_names_in_corrections_have_namespaces
47
- error = assert_raises(NameError) { ::Book::TableofContents }
49
+ error = assert_raise(NameError) { ::Book::TableofContents }
48
50
  assert_correction "Book::TableOfContents", error.corrections
49
51
  end
50
52
 
51
53
  def test_corrections_candidates_for_names_in_upper_level_scopes
52
- error = assert_raises(NameError) { Book::Page.tableof_contents }
54
+ error = assert_raise(NameError) { Book::Page.tableof_contents }
53
55
  assert_correction "Book::TableOfContents", error.corrections
54
56
  end
55
57
 
56
58
  def test_corrections_should_work_from_within_instance_method
57
- error = assert_raises(NameError) { ::Book.new.tableof_contents }
59
+ error = assert_raise(NameError) { ::Book.new.tableof_contents }
58
60
  assert_correction "Book::TableOfContents", error.corrections
59
61
  end
60
62
 
61
63
  def test_corrections_should_work_from_within_instance_method_on_nested_class
62
- error = assert_raises(NameError) { ::Book::Page.new.tableof_contents }
64
+ error = assert_raise(NameError) { ::Book::Page.new.tableof_contents }
63
65
  assert_correction "Book::TableOfContents", error.corrections
64
66
  end
65
67
 
66
68
  def test_does_not_suggest_user_input
67
- error = assert_raises(NameError) { ::Book::Cover }
69
+ error = assert_raise(NameError) { ::Book::Cover }
68
70
 
69
71
  # This is a weird require, but in a multi-threaded condition, a constant may
70
72
  # be loaded between when a NameError occurred and when the spell checker
@@ -1,14 +1,16 @@
1
- require "test_helper"
1
+ require_relative '../helper'
2
+
3
+ class KeyNameCheckTest < Test::Unit::TestCase
4
+ include DidYouMean::TestHelper
2
5
 
3
- class KeyNameCheckTest < Minitest::Test
4
6
  def test_corrects_hash_key_name_with_fetch
5
7
  hash = { "foo" => 1, bar: 2 }
6
8
 
7
- error = assert_raises(KeyError) { hash.fetch(:bax) }
9
+ error = assert_raise(KeyError) { hash.fetch(:bax) }
8
10
  assert_correction ":bar", error.corrections
9
11
  assert_match "Did you mean? :bar", error.to_s
10
12
 
11
- error = assert_raises(KeyError) { hash.fetch("fooo") }
13
+ error = assert_raise(KeyError) { hash.fetch("fooo") }
12
14
  assert_correction %("foo"), error.corrections
13
15
  assert_match %(Did you mean? "foo"), error.to_s
14
16
  end
@@ -16,17 +18,25 @@ class KeyNameCheckTest < Minitest::Test
16
18
  def test_corrects_hash_key_name_with_fetch_values
17
19
  hash = { "foo" => 1, bar: 2 }
18
20
 
19
- error = assert_raises(KeyError) { hash.fetch_values("foo", :bar, :bax) }
21
+ error = assert_raise(KeyError) { hash.fetch_values("foo", :bar, :bax) }
20
22
  assert_correction ":bar", error.corrections
21
23
  assert_match "Did you mean? :bar", error.to_s
22
24
 
23
- error = assert_raises(KeyError) { hash.fetch_values("foo", :bar, "fooo") }
25
+ error = assert_raise(KeyError) { hash.fetch_values("foo", :bar, "fooo") }
24
26
  assert_correction %("foo"), error.corrections
25
27
  assert_match %(Did you mean? "foo"), error.to_s
26
28
  end
27
29
 
30
+ def test_correct_symbolized_hash_keys_with_string_value
31
+ hash = { foo_1: 1, bar_2: 2 }
32
+
33
+ error = assert_raise(KeyError) { hash.fetch('foo_1') }
34
+ assert_correction %(:foo_1), error.corrections
35
+ assert_match %(Did you mean? :foo_1), error.to_s
36
+ end
37
+
28
38
  def test_corrects_sprintf_key_name
29
- error = assert_raises(KeyError) { sprintf("%<foo>d", {fooo: 1}) }
39
+ error = assert_raise(KeyError) { sprintf("%<foo>d", {fooo: 1}) }
30
40
  assert_correction ":fooo", error.corrections
31
41
  assert_match "Did you mean? :fooo", error.to_s
32
42
  end
@@ -34,7 +44,7 @@ class KeyNameCheckTest < Minitest::Test
34
44
  def test_corrects_env_key_name
35
45
  ENV["FOO"] = "1"
36
46
  ENV["BAR"] = "2"
37
- error = assert_raises(KeyError) { ENV.fetch("BAX") }
47
+ error = assert_raise(KeyError) { ENV.fetch("BAX") }
38
48
  assert_correction %("BAR"), error.corrections
39
49
  assert_match %(Did you mean? "BAR"), error.to_s
40
50
  ensure
@@ -1,6 +1,8 @@
1
- require 'test_helper'
1
+ require_relative '../helper'
2
+
3
+ class MethodNameCheckTest < Test::Unit::TestCase
4
+ include DidYouMean::TestHelper
2
5
 
3
- class MethodNameCheckTest < Minitest::Test
4
6
  class User
5
7
  def friends; end
6
8
  def first_name; end
@@ -36,50 +38,50 @@ class MethodNameCheckTest < Minitest::Test
36
38
  end
37
39
 
38
40
  def test_corrections_include_instance_method
39
- error = assert_raises(NoMethodError){ @user.flrst_name }
41
+ error = assert_raise(NoMethodError){ @user.flrst_name }
40
42
 
41
43
  assert_correction :first_name, error.corrections
42
44
  assert_match "Did you mean? first_name", error.to_s
43
45
  end
44
46
 
45
47
  def test_corrections_include_private_method
46
- error = assert_raises(NoMethodError){ @user.friend }
48
+ error = assert_raise(NoMethodError){ @user.friend }
47
49
 
48
50
  assert_correction :friends, error.corrections
49
51
  assert_match "Did you mean? friends", error.to_s
50
52
  end
51
53
 
52
54
  def test_corrections_include_method_from_module
53
- error = assert_raises(NoMethodError){ @user.fr0m_module }
55
+ error = assert_raise(NoMethodError){ @user.fr0m_module }
54
56
 
55
57
  assert_correction :from_module, error.corrections
56
58
  assert_match "Did you mean? from_module", error.to_s
57
59
  end
58
60
 
59
61
  def test_corrections_include_class_method
60
- error = assert_raises(NoMethodError){ User.l0ad }
62
+ error = assert_raise(NoMethodError){ User.l0ad }
61
63
 
62
64
  assert_correction :load, error.corrections
63
65
  assert_match "Did you mean? load", error.to_s
64
66
  end
65
67
 
66
68
  def test_private_methods_should_not_be_suggested
67
- error = assert_raises(NoMethodError){ User.new.the_protected_method }
69
+ error = assert_raise(NoMethodError){ User.new.the_protected_method }
68
70
  refute_includes error.corrections, :the_protected_method
69
71
 
70
- error = assert_raises(NoMethodError){ User.new.the_private_method }
72
+ error = assert_raise(NoMethodError){ User.new.the_private_method }
71
73
  refute_includes error.corrections, :the_private_method
72
74
  end
73
75
 
74
76
  def test_corrections_when_private_method_is_called_with_args
75
- error = assert_raises(NoMethodError){ @user.call_incorrect_private_method }
77
+ error = assert_raise(NoMethodError){ @user.call_incorrect_private_method }
76
78
 
77
79
  assert_correction :raise, error.corrections
78
80
  assert_match "Did you mean? raise", error.to_s
79
81
  end
80
82
 
81
83
  def test_exclude_methods_on_nil
82
- error = assert_raises(NoMethodError){ nil.map }
84
+ error = assert_raise(NoMethodError){ nil.map }
83
85
  assert_empty error.corrections
84
86
  end
85
87
 
@@ -87,14 +89,14 @@ class MethodNameCheckTest < Minitest::Test
87
89
  def nil.empty?
88
90
  end
89
91
 
90
- error = assert_raises(NoMethodError){ nil.empty }
92
+ error = assert_raise(NoMethodError){ nil.empty }
91
93
  assert_correction :empty?, error.corrections
92
94
  ensure
93
95
  NilClass.class_eval { undef empty? }
94
96
  end
95
97
 
96
98
  def test_does_not_append_suggestions_twice
97
- error = assert_raises NoMethodError do
99
+ error = assert_raise NoMethodError do
98
100
  begin
99
101
  @user.firstname
100
102
  rescue NoMethodError => e
@@ -106,7 +108,7 @@ class MethodNameCheckTest < Minitest::Test
106
108
  end
107
109
 
108
110
  def test_does_not_append_suggestions_three_times
109
- error = assert_raises NoMethodError do
111
+ error = assert_raise NoMethodError do
110
112
  begin
111
113
  @user.raise_no_method_error
112
114
  rescue NoMethodError => e
@@ -118,7 +120,7 @@ class MethodNameCheckTest < Minitest::Test
118
120
  end
119
121
 
120
122
  def test_suggests_corrections_on_nested_error
121
- error = assert_raises NoMethodError do
123
+ error = assert_raise NoMethodError do
122
124
  begin
123
125
  @user.firstname
124
126
  rescue NoMethodError
@@ -130,7 +132,7 @@ class MethodNameCheckTest < Minitest::Test
130
132
  end
131
133
 
132
134
  def test_suggests_yield
133
- error = assert_raises(NoMethodError) { yeild(1) }
135
+ error = assert_raise(NoMethodError) { yeild(1) }
134
136
 
135
137
  assert_correction :yield, error.corrections
136
138
  assert_match "Did you mean? yield", error.to_s
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require_relative '../helper'
2
2
 
3
- class UncorrectableNameCheckTest < Minitest::Test
3
+ class UncorrectableNameCheckTest < Test::Unit::TestCase
4
4
  class FirstNameError < NameError; end
5
5
 
6
6
  def setup
7
- @error = assert_raises(FirstNameError) do
7
+ @error = assert_raise(FirstNameError) do
8
8
  raise FirstNameError, "Other name error"
9
9
  end
10
10
  end
@@ -1,6 +1,8 @@
1
- require 'test_helper'
1
+ require_relative '../helper'
2
+
3
+ class VariableNameCheckTest < Test::Unit::TestCase
4
+ include DidYouMean::TestHelper
2
5
 
3
- class VariableNameCheckTest < Minitest::Test
4
6
  class User
5
7
  def initialize
6
8
  @email_address = 'email_address@address.net'
@@ -27,7 +29,7 @@ class VariableNameCheckTest < Minitest::Test
27
29
  end
28
30
 
29
31
  def test_corrections_include_instance_method
30
- error = assert_raises(NameError) do
32
+ error = assert_raise(NameError) do
31
33
  @user.instance_eval { flrst_name }
32
34
  end
33
35
 
@@ -41,7 +43,7 @@ class VariableNameCheckTest < Minitest::Test
41
43
  end
42
44
 
43
45
  def test_corrections_include_method_from_module
44
- error = assert_raises(NameError) do
46
+ error = assert_raise(NameError) do
45
47
  @user.instance_eval { fr0m_module }
46
48
  end
47
49
 
@@ -52,7 +54,7 @@ class VariableNameCheckTest < Minitest::Test
52
54
  def test_corrections_include_local_variable_name
53
55
  if RUBY_ENGINE != "jruby"
54
56
  person = person = nil
55
- error = (eprson rescue $!) # Do not use @assert_raises here as it changes a scope.
57
+ error = (eprson rescue $!) # Do not use @assert_raise here as it changes a scope.
56
58
 
57
59
  assert_correction :person, error.corrections
58
60
  assert_match "Did you mean? person", error.to_s
@@ -60,21 +62,21 @@ class VariableNameCheckTest < Minitest::Test
60
62
  end
61
63
 
62
64
  def test_corrections_include_ruby_predefined_objects
63
- some_var = nil
65
+ some_var = some_var = nil
64
66
 
65
- false_error = assert_raises(NameError) do
67
+ false_error = assert_raise(NameError) do
66
68
  some_var = fals
67
69
  end
68
70
 
69
- true_error = assert_raises(NameError) do
71
+ true_error = assert_raise(NameError) do
70
72
  some_var = treu
71
73
  end
72
74
 
73
- nil_error = assert_raises(NameError) do
75
+ nil_error = assert_raise(NameError) do
74
76
  some_var = nul
75
77
  end
76
78
 
77
- file_error = assert_raises(NameError) do
79
+ file_error = assert_raise(NameError) do
78
80
  __FIEL__
79
81
  end
80
82
 
@@ -92,21 +94,21 @@ class VariableNameCheckTest < Minitest::Test
92
94
  end
93
95
 
94
96
  def test_suggests_yield
95
- error = assert_raises(NameError) { yeild }
97
+ error = assert_raise(NameError) { yeild }
96
98
 
97
99
  assert_correction :yield, error.corrections
98
100
  assert_match "Did you mean? yield", error.to_s
99
101
  end
100
102
 
101
103
  def test_corrections_include_instance_variable_name
102
- error = assert_raises(NameError){ @user.to_s }
104
+ error = assert_raise(NameError){ @user.to_s }
103
105
 
104
106
  assert_correction :@email_address, error.corrections
105
107
  assert_match "Did you mean? @email_address", error.to_s
106
108
  end
107
109
 
108
110
  def test_corrections_include_private_method
109
- error = assert_raises(NameError) do
111
+ error = assert_raise(NameError) do
110
112
  @user.instance_eval { cia_code_name }
111
113
  end
112
114
 
@@ -117,7 +119,7 @@ class VariableNameCheckTest < Minitest::Test
117
119
  @@does_exist = true
118
120
 
119
121
  def test_corrections_include_class_variable_name
120
- error = assert_raises(NameError){ @@doesnt_exist }
122
+ error = assert_raise(NameError){ @@doesnt_exist }
121
123
 
122
124
  assert_correction :@@does_exist, error.corrections
123
125
  assert_match "Did you mean? @@does_exist", error.to_s
@@ -125,14 +127,14 @@ class VariableNameCheckTest < Minitest::Test
125
127
 
126
128
  def test_struct_name_error
127
129
  value = Struct.new(:does_exist).new
128
- error = assert_raises(NameError){ value[:doesnt_exist] }
130
+ error = assert_raise(NameError){ value[:doesnt_exist] }
129
131
 
130
132
  assert_correction [:does_exist, :does_exist=], error.corrections
131
133
  assert_match "Did you mean? does_exist", error.to_s
132
134
  end
133
135
 
134
136
  def test_exclude_typical_incorrect_suggestions
135
- error = assert_raises(NameError){ foo }
137
+ error = assert_raise(NameError){ foo }
136
138
  assert_empty error.corrections
137
139
  end
138
140
  end
@@ -1,6 +1,6 @@
1
- require 'test_helper'
1
+ require_relative './helper'
2
2
 
3
- class SpellCheckerTest < Minitest::Test
3
+ class SpellCheckerTest < Test::Unit::TestCase
4
4
  def test_spell_checker_corrects_mistypes
5
5
  assert_spell 'foo', input: 'doo', dictionary: ['foo', 'fork']
6
6
  assert_spell 'email', input: 'meail', dictionary: ['email', 'fail', 'eval']
@@ -0,0 +1,173 @@
1
+ require 'set'
2
+ require 'yaml'
3
+
4
+ require_relative './helper'
5
+
6
+ class TreeSpellCheckerTest < Test::Unit::TestCase
7
+ MINI_DIRECTORIES = YAML.load_file(File.expand_path('fixtures/mini_dir.yml', __dir__))
8
+ RSPEC_DIRECTORIES = YAML.load_file(File.expand_path('fixtures/rspec_dir.yml', __dir__))
9
+
10
+ def setup
11
+ @dictionary =
12
+ %w(
13
+ spec/models/concerns/vixen_spec.rb
14
+ spec/models/concerns/abcd_spec.rb
15
+ spec/models/concerns/vixenus_spec.rb
16
+ spec/models/concerns/efgh_spec.rb
17
+ spec/modals/confirms/abcd_spec.rb
18
+ spec/modals/confirms/efgh_spec.rb
19
+ spec/models/gafafa_spec.rb
20
+ spec/models/gfsga_spec.rb
21
+ spec/controllers/vixen_controller_spec.rb
22
+ )
23
+ @test_str = 'spek/modeks/confirns/viken_spec.rb'
24
+ @tsp = DidYouMean::TreeSpellChecker.new(dictionary: @dictionary)
25
+ end
26
+
27
+ def test_corrupt_root
28
+ word = 'test/verbose_formatter_test.rb'
29
+ word_error = 'btets/cverbose_formatter_etst.rb suggestions'
30
+ tsp = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES)
31
+ s = tsp.correct(word_error).first
32
+ assert_match s, word
33
+ end
34
+
35
+ def test_leafless_state
36
+ tsp = DidYouMean::TreeSpellChecker.new(dictionary: @dictionary.push('spec/features'))
37
+ word = 'spec/modals/confirms/efgh_spec.rb'
38
+ word_error = 'spec/modals/confirXX/efgh_spec.rb'
39
+ s = tsp.correct(word_error).first
40
+ assert_equal s, word
41
+ s = tsp.correct('spec/featuresXX')
42
+ assert_equal 'spec/features', s.first
43
+ end
44
+
45
+ def test_rake_dictionary
46
+ dict = %w(parallel:prepare parallel:create parallel:rake parallel:migrate)
47
+ word_error = 'parallel:preprare'
48
+ tsp = DidYouMean::TreeSpellChecker.new(dictionary: dict, separator: ':')
49
+ s = tsp.correct(word_error).first
50
+ assert_match s, 'parallel:prepare'
51
+ end
52
+
53
+ def test_special_words_mini
54
+ tsp = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES)
55
+ special_words_mini.each do |word, word_error|
56
+ s = tsp.correct(word_error).first
57
+ assert_match s, word
58
+ end
59
+ end
60
+
61
+ def test_special_words_rspec
62
+ tsp = DidYouMean::TreeSpellChecker.new(dictionary: RSPEC_DIRECTORIES)
63
+ special_words_rspec.each do |word, word_error|
64
+ s = tsp.correct(word_error)
65
+ assert_match s.first, word
66
+ end
67
+ end
68
+
69
+ def special_words_rspec
70
+ [
71
+ ['spec/rspec/core/formatters/exception_presenter_spec.rb','spec/rspec/core/formatters/eception_presenter_spec.rb'],
72
+ ['spec/rspec/core/ordering_spec.rb', 'spec/spec/core/odrering_spec.rb'],
73
+ ['spec/rspec/core/metadata_spec.rb', 'spec/rspec/core/metadata_spe.crb'],
74
+ ['spec/support/mathn_integration_support.rb', 'spec/support/mathn_itegrtion_support.rb']
75
+ ]
76
+ end
77
+
78
+ def special_words_mini
79
+ [
80
+ ['test/fixtures/book.rb', 'test/fixture/book.rb'],
81
+ ['test/fixtures/book.rb', 'test/fixture/book.rb'],
82
+ ['test/edit_distance/jaro_winkler_test.rb', 'test/edit_distace/jaro_winkler_test.rb'],
83
+ ['test/edit_distance/jaro_winkler_test.rb', 'teste/dit_distane/jaro_winkler_test.rb'],
84
+ ['test/fixtures/book.rb', 'test/fixturWes/book.rb'],
85
+ ['test/test_helper.rb', 'tes!t/test_helper.rb'],
86
+ ['test/fixtures/book.rb', 'test/hfixtures/book.rb'],
87
+ ['test/edit_distance/jaro_winkler_test.rb', 'test/eidt_distance/jaro_winkler_test.@rb'],
88
+ ['test/spell_checker_test.rb', 'test/spell_checke@r_test.rb'],
89
+ ['test/tree_spell_human_typo_test.rb', 'testt/ree_spell_human_typo_test.rb'],
90
+ ['test/spell_checking/variable_name_check_test.rb', 'test/spell_checking/vriabl_ename_check_test.rb'],
91
+ ['test/spell_checking/key_name_check_test.rb', 'tesit/spell_checking/key_name_choeck_test.rb'],
92
+ ['test/edit_distance/jaro_winkler_test.rb', 'test/edit_distance/jaro_winkler_tuest.rb']
93
+ ]
94
+ end
95
+
96
+ def test_file_in_root
97
+ word = 'test/spell_checker_test.rb'
98
+ word_error = 'test/spell_checker_test.r'
99
+ suggestions = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES).correct word_error
100
+ assert_equal word, suggestions.first
101
+ end
102
+
103
+ def test_no_plausible_states
104
+ word_error = 'testspell_checker_test.rb'
105
+ suggestions = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES).correct word_error
106
+ assert_equal [], suggestions
107
+ end
108
+
109
+ def test_no_plausible_states_with_augmentation
110
+ word_error = 'testspell_checker_test.rb'
111
+ suggestions = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES).correct word_error
112
+ assert_equal [], suggestions
113
+ suggestions = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES, augment: true).correct word_error
114
+ assert_equal 'test/spell_checker_test.rb', suggestions.first
115
+ end
116
+
117
+ def test_no_idea_with_augmentation
118
+ word_error = 'test/spell_checking/key_name.rb'
119
+ suggestions = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES).correct word_error
120
+ assert_equal [], suggestions
121
+ suggestions = DidYouMean::TreeSpellChecker.new(dictionary: MINI_DIRECTORIES, augment: true).correct word_error
122
+ assert_equal 'test/spell_checking/key_name_check_test.rb', suggestions.first
123
+ end
124
+
125
+ def test_works_out_suggestions
126
+ exp = ['spec/models/concerns/vixen_spec.rb',
127
+ 'spec/models/concerns/vixenus_spec.rb']
128
+ suggestions = @tsp.correct(@test_str)
129
+ assert_equal suggestions.to_set, exp.to_set
130
+ end
131
+
132
+ def test_works_when_input_is_correct
133
+ correct_input = 'spec/models/concerns/vixenus_spec.rb'
134
+ suggestions = @tsp.correct correct_input
135
+ assert_equal suggestions.first, correct_input
136
+ end
137
+
138
+ def test_find_out_leaves_in_a_path
139
+ path = 'spec/modals/confirms'
140
+ names = @tsp.send(:find_leaves, path)
141
+ assert_equal names.to_set, %w(abcd_spec.rb efgh_spec.rb).to_set
142
+ end
143
+
144
+ def test_works_out_nodes
145
+ exp_paths = ['spec/models/concerns',
146
+ 'spec/models/confirms',
147
+ 'spec/modals/concerns',
148
+ 'spec/modals/confirms',
149
+ 'spec/controllers/concerns',
150
+ 'spec/controllers/confirms'].to_set
151
+ states = @tsp.send(:parse_dimensions)
152
+ nodes = states[0].product(*states[1..-1])
153
+ paths = @tsp.send(:possible_paths, nodes)
154
+ assert_equal paths.to_set, exp_paths.to_set
155
+ end
156
+
157
+ def test_works_out_state_space
158
+ suggestions = @tsp.send(:plausible_dimensions, @test_str)
159
+ assert_equal suggestions, [["spec"], ["models", "modals"], ["confirms", "concerns"]]
160
+ end
161
+
162
+ def test_parses_dictionary
163
+ states = @tsp.send(:parse_dimensions)
164
+ assert_equal states, [["spec"], ["models", "modals", "controllers"], ["concerns", "confirms"]]
165
+ end
166
+
167
+ def test_parses_elementary_dictionary
168
+ dictionary = ['spec/models/user_spec.rb', 'spec/services/account_spec.rb']
169
+ tsp = DidYouMean::TreeSpellChecker.new(dictionary: dictionary)
170
+ states = tsp.send(:parse_dimensions)
171
+ assert_equal states, [['spec'], ['models', 'services']]
172
+ end
173
+ end