* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / test_abbrev.rb
blob67287138aa8f91d68d559a45eac12d35973f6c10
1 # frozen_string_literal: true
2 require 'test/unit'
3 require 'abbrev'
5 class TestAbbrev < Test::Unit::TestCase
6   def test_abbrev
7     words = %w[summer winter win ruby rules]
9     assert_equal({
10         "rub"    => "ruby",
11         "ruby"   => "ruby",
12         "rul"    => "rules",
13         "rule"   => "rules",
14         "rules"  => "rules",
15         "s"      => "summer",
16         "su"     => "summer",
17         "sum"    => "summer",
18         "summ"   => "summer",
19         "summe"  => "summer",
20         "summer" => "summer",
21         "win"    => "win",
22         "wint"   => "winter",
23         "winte"  => "winter",
24         "winter" => "winter",
25       }, words.abbrev)
27     assert_equal({
28         "rub"    => "ruby",
29         "ruby"   => "ruby",
30         "rul"    => "rules",
31         "rule"   => "rules",
32         "rules"  => "rules",
33       }, words.abbrev('ru'))
35     assert_equal words.abbrev,       Abbrev.abbrev(words)
36     assert_equal words.abbrev('ru'), Abbrev.abbrev(words, 'ru')
37   end
39   def test_abbrev_lf
40     words = ["abc", "abc\nd", "de"]
42     assert_equal({
43         "abc"     => "abc",
44         "abc\n"   => "abc\nd",
45         "abc\nd"  => "abc\nd",
46         "d"       => "de",
47         "de"      => "de",
48       }, words.abbrev)
50     assert_equal({
51         "d"       => "de",
52         "de"      => "de",
53       }, words.abbrev('d'))
54   end
55 end