зеркало из https://github.com/github/ruby.git
Use DidYouMean.formatter
Instead of building messages separately.
This commit is contained in:
Родитель
e50b8949fa
Коммит
46fa301e82
|
@ -1777,7 +1777,7 @@ XXX
|
|||
end
|
||||
all_candidates.select! {|cand| cand.is_a?(String) }
|
||||
suggestions = DidYouMean::SpellChecker.new(dictionary: all_candidates).correct(opt)
|
||||
raise InvalidOption.new(opt, "\nDid you mean? #{suggestions.join("\n ")}")
|
||||
raise InvalidOption.new(opt, DidYouMean.formatter.message_for(suggestions))
|
||||
else
|
||||
raise InvalidOption, opt
|
||||
end
|
||||
|
|
|
@ -8,15 +8,26 @@ class TestOptionParser::DidYouMean < TestOptionParser
|
|||
@opt.def_option("--foo", Integer) { |v| @foo = v }
|
||||
@opt.def_option("--bar", Integer) { |v| @bar = v }
|
||||
@opt.def_option("--baz", Integer) { |v| @baz = v }
|
||||
@formatter = ::DidYouMean.formatter
|
||||
end
|
||||
|
||||
def test_did_you_mean
|
||||
assert_raise(OptionParser::InvalidOption) do
|
||||
begin
|
||||
@opt.permute!(%w"--baa")
|
||||
ensure
|
||||
assert_equal("invalid option: --baa\nDid you mean? baz\n bar", $!.message)
|
||||
end
|
||||
def teardown
|
||||
::DidYouMean.formatter = @formatter
|
||||
end
|
||||
|
||||
|
||||
def test_plain
|
||||
::DidYouMean.formatter = ::DidYouMean::PlainFormatter.new
|
||||
assert_raise_with_message(OptionParser::InvalidOption, /invalid option: --baa\nDid you mean\?\s+baz\s+bar\Z/) do
|
||||
@opt.permute!(%w"--baa")
|
||||
end
|
||||
end
|
||||
|
||||
def test_verbose
|
||||
require 'did_you_mean/formatters/verbose_formatter'
|
||||
::DidYouMean.formatter = ::DidYouMean::VerboseFormatter.new
|
||||
assert_raise_with_message(OptionParser::InvalidOption, /invalid option: --baa\n\s+Did you mean\?\s+baz\s+bar\s*\Z/) do
|
||||
@opt.permute!(%w"--baa")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче