summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rubygems/test_gem_text.rb
blob: e5cfc41e61b96759c97d7a9dc45b373f3e880fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'rubygems/test_case'
require "rubygems/text"

class TestGemText < Gem::TestCase
  include Gem::Text

  def test_format_text
    assert_equal "text to\nwrap",     format_text("text to wrap", 8)
  end

  def test_format_text_indent
    assert_equal "  text to\n  wrap", format_text("text to wrap", 8, 2)
  end

  def test_format_text_none
    assert_equal "text to wrap",      format_text("text to wrap", 40)
  end

  def test_format_text_none_indent
    assert_equal "  text to wrap",    format_text("text to wrap", 40, 2)
  end

  def test_format_text_trailing # for two spaces after .
    text = <<-TEXT
This line is really, really long.  So long, in fact, that it is more than eighty characters long!  The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters.  Without the wrapping, the text might not look good in the RSS feed.
    TEXT

    expected = <<-EXPECTED
This line is really, really long.  So long, in fact, that it is more than
eighty characters long!  The purpose of this line is for testing wrapping
behavior because sometimes people don't wrap their text to eighty characters.
Without the wrapping, the text might not look good in the RSS feed.
    EXPECTED

    assert_equal expected, format_text(text, 78)
  end

  def test_min3
    assert_equal 1, min3(1, 1, 1)
    assert_equal 1, min3(1, 1, 2)
    assert_equal 1, min3(1, 2, 1)
    assert_equal 1, min3(2, 1, 1)
    assert_equal 1, min3(1, 2, 2)
    assert_equal 1, min3(2, 1, 2)
    assert_equal 1, min3(2, 2, 1)
    assert_equal 1, min3(1, 2, 3)
    assert_equal 1, min3(1, 3, 2)
    assert_equal 1, min3(2, 1, 3)
    assert_equal 1, min3(2, 3, 1)
    assert_equal 1, min3(3, 1, 2)
    assert_equal 1, min3(3, 2, 1)
  end

  def test_levenshtein_distance_add
    assert_equal 2, levenshtein_distance("zentest", "zntst")
    assert_equal 2, levenshtein_distance("zntst", "zentest")
  end

  def test_levenshtein_distance_empty
    assert_equal 5, levenshtein_distance("abcde", "")
    assert_equal 5, levenshtein_distance("", "abcde")
  end

  def test_levenshtein_distance_remove
    assert_equal 3, levenshtein_distance("zentest", "zentestxxx")
    assert_equal 3, levenshtein_distance("zentestxxx", "zentest")
  end

  def test_levenshtein_distance_replace
    assert_equal 2, levenshtein_distance("zentest", "ZenTest")
    assert_equal 7, levenshtein_distance("xxxxxxx", "ZenTest")
    assert_equal 7, levenshtein_distance("zentest", "xxxxxxx")
  end
end