~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/-ext-/string/test_ellipsize.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
require "-test-/string/string"
 
3
 
 
4
class Test_StringEllipsize < Test::Unit::TestCase
 
5
  def setup
 
6
    @foobar = Bug::String.new("foobar")
 
7
  end
 
8
 
 
9
  def assert_equal_with_class(expected, result, *rest)
 
10
    assert_equal(expected.encoding, result.encoding, *rest)
 
11
    assert_equal(expected, result, result.encoding.name)
 
12
    assert_instance_of(Bug::String, result, *rest)
 
13
  end
 
14
 
 
15
  def test_longer
 
16
    assert_equal_with_class("", @foobar.ellipsize(0))
 
17
    assert_equal_with_class(".", @foobar.ellipsize(1))
 
18
    assert_equal_with_class("..", @foobar.ellipsize(2))
 
19
    assert_equal_with_class("...", @foobar.ellipsize(3))
 
20
    assert_equal_with_class("f...", @foobar.ellipsize(4))
 
21
    assert_equal_with_class("fo...", @foobar.ellipsize(5))
 
22
  end
 
23
 
 
24
  def test_shorter
 
25
    assert_same(@foobar, @foobar.ellipsize(6))
 
26
    assert_same(@foobar, @foobar.ellipsize(7))
 
27
  end
 
28
 
 
29
  def test_negative_length
 
30
    assert_raise(IndexError) {@foobar.ellipsize(-1)}
 
31
  end
 
32
 
 
33
  def test_nonascii
 
34
    a = "\u3042"
 
35
    encs = Encoding.list.each do |enc|
 
36
      next if enc.dummy?
 
37
      begin
 
38
        s = a.encode(enc)
 
39
        e = "...".encode(enc)
 
40
      rescue
 
41
      else
 
42
        assert_equal_with_class(s*12+e, Bug::String.new(s*20).ellipsize(15))
 
43
      end
 
44
    end
 
45
  end
 
46
end