diff options
author | Yuki Nishijima <[email protected]> | 2021-10-22 20:35:40 -0400 |
---|---|---|
committer | Yuki Nishijima <[email protected]> | 2021-10-22 20:35:40 -0400 |
commit | e22d293e06966733e71a7fd9725eee06c03d0177 (patch) | |
tree | 2bc200dd8e8314a7d596669ae859e7f3b8a9353e /test | |
parent | f80069820e1f7d44ef9c385254d498468a352021 (diff) |
Sync did_you_mean
Diffstat (limited to 'test')
-rw-r--r-- | test/did_you_mean/spell_checking/test_pattern_key_name_check.rb | 20 | ||||
-rw-r--r-- | test/did_you_mean/test_spell_checker.rb | 1 | ||||
-rw-r--r-- | test/did_you_mean/test_verbose_formatter.rb | 38 |
3 files changed, 21 insertions, 38 deletions
diff --git a/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb b/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb new file mode 100644 index 0000000000..2b0752a56a --- /dev/null +++ b/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb @@ -0,0 +1,20 @@ +require_relative '../helper' + +return if !defined?(::NoMatchingPatternKeyError) + +class PatternKeyNameCheckTest < Test::Unit::TestCase + include DidYouMean::TestHelper + + def test_corrects_hash_key_name_with_single_pattern_match + error = assert_raise(NoMatchingPatternKeyError) do + eval(<<~RUBY, binding, __FILE__, __LINE__) + hash = {foo: 1, bar: 2, baz: 3} + hash => {fooo:} + fooo = 1 # suppress "unused variable: fooo" warning + RUBY + end + + assert_correction ":foo", error.corrections + assert_match "Did you mean? :foo", error.to_s + end +end diff --git a/test/did_you_mean/test_spell_checker.rb b/test/did_you_mean/test_spell_checker.rb index 98460b4d94..8445380de3 100644 --- a/test/did_you_mean/test_spell_checker.rb +++ b/test/did_you_mean/test_spell_checker.rb @@ -10,6 +10,7 @@ class SpellCheckerTest < Test::Unit::TestCase assert_spell 'eval', input: 'veal', dictionary: ['email', 'fail', 'eval'] assert_spell 'sub!', input: 'suv!', dictionary: ['sub', 'gsub', 'sub!'] assert_spell 'sub', input: 'suv', dictionary: ['sub', 'gsub', 'sub!'] + assert_spell 'Foo', input: 'FOo', dictionary: ['Foo', 'FOo'] assert_spell %w(gsub! gsub), input: 'gsuv!', dictionary: %w(sub gsub gsub!) assert_spell %w(sub! sub gsub!), input: 'ssub!', dictionary: %w(sub sub! gsub gsub!) diff --git a/test/did_you_mean/test_verbose_formatter.rb b/test/did_you_mean/test_verbose_formatter.rb deleted file mode 100644 index 411f175180..0000000000 --- a/test/did_you_mean/test_verbose_formatter.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative './helper' - -class VerboseFormatterTest < Test::Unit::TestCase - class ErrorHighlightDummyFormatter - def message_for(spot) - "" - end - end - - def setup - require_relative File.join(DidYouMean::TestHelper.root, 'verbose') - - DidYouMean.formatter = DidYouMean::VerboseFormatter.new - - if defined?(ErrorHighlight) - @error_highlight_old_formatter = ErrorHighlight.formatter - ErrorHighlight.formatter = ErrorHighlightDummyFormatter.new - end - end - - def teardown - DidYouMean.formatter = DidYouMean::PlainFormatter.new - - if defined?(ErrorHighlight) - ErrorHighlight.formatter = @error_highlight_old_formatter - end - end - - def test_message - @error = assert_raise(NoMethodError){ 1.zeor? } - - assert_match <<~MESSAGE.strip, @error.message - undefined method `zeor?' for 1:Integer - - Did you mean? zero? - MESSAGE - end -end |