2017-02-09 11:12:00 -05:00
|
|
|
# frozen_string_literal: true
|
2012-11-29 22:35:01 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'abbrev'
|
|
|
|
|
|
|
|
class TestAbbrev < Test::Unit::TestCase
|
|
|
|
def test_abbrev
|
2012-11-29 22:56:25 -05:00
|
|
|
words = %w[summer winter win ruby rules]
|
2012-11-29 22:35:01 -05:00
|
|
|
|
|
|
|
assert_equal({
|
|
|
|
"rub" => "ruby",
|
|
|
|
"ruby" => "ruby",
|
|
|
|
"rul" => "rules",
|
|
|
|
"rule" => "rules",
|
|
|
|
"rules" => "rules",
|
|
|
|
"s" => "summer",
|
|
|
|
"su" => "summer",
|
|
|
|
"sum" => "summer",
|
|
|
|
"summ" => "summer",
|
|
|
|
"summe" => "summer",
|
|
|
|
"summer" => "summer",
|
2012-11-29 22:56:25 -05:00
|
|
|
"win" => "win",
|
2012-11-29 22:35:01 -05:00
|
|
|
"wint" => "winter",
|
|
|
|
"winte" => "winter",
|
|
|
|
"winter" => "winter",
|
|
|
|
}, words.abbrev)
|
|
|
|
|
|
|
|
assert_equal({
|
|
|
|
"rub" => "ruby",
|
|
|
|
"ruby" => "ruby",
|
|
|
|
"rul" => "rules",
|
|
|
|
"rule" => "rules",
|
|
|
|
"rules" => "rules",
|
|
|
|
}, words.abbrev('ru'))
|
|
|
|
|
|
|
|
assert_equal words.abbrev, Abbrev.abbrev(words)
|
|
|
|
assert_equal words.abbrev('ru'), Abbrev.abbrev(words, 'ru')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_abbrev_lf
|
2012-11-29 22:56:28 -05:00
|
|
|
words = ["abc", "abc\nd", "de"]
|
|
|
|
|
2012-11-29 22:35:01 -05:00
|
|
|
assert_equal({
|
|
|
|
"abc" => "abc",
|
|
|
|
"abc\n" => "abc\nd",
|
|
|
|
"abc\nd" => "abc\nd",
|
|
|
|
"d" => "de",
|
|
|
|
"de" => "de",
|
2012-11-29 22:56:28 -05:00
|
|
|
}, words.abbrev)
|
|
|
|
|
|
|
|
assert_equal({
|
|
|
|
"d" => "de",
|
|
|
|
"de" => "de",
|
|
|
|
}, words.abbrev('d'))
|
2012-11-29 22:35:01 -05:00
|
|
|
end
|
|
|
|
end
|