summaryrefslogtreecommitdiff
path: root/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/did_you_mean/spell_checking/test_pattern_key_name_check.rb')
-rw-r--r--test/did_you_mean/spell_checking/test_pattern_key_name_check.rb20
1 files changed, 20 insertions, 0 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..10f973802b
--- /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", get_message(error)
+ end
+end