File: test_pattern_key_name_check.rb

package info (click to toggle)
ruby-did-you-mean 1.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: ruby: 2,701; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 592 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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