Manfred / unichars

A library that wraps Glib2 Unicode manipulation methods to speed up ActiveSupport::Multibyte

This URL has Read+Write access

unichars / test / chars_test.rb
100644 64 lines (51 sloc) 1.677 kb
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
# encoding: utf-8
 
require File.dirname(__FILE__) + '/test_helper'
 
describe "A Chars instance" do
  it "should wrap a string" do
    chars('Wrapped').wrapped_string.should == 'Wrapped'
  end
  
  it "should coerce to a string" do
    chars('Wrapped').to_s.should == 'Wrapped'
  end
  
  it "should cast to a string" do
    chars('Wrapped').to_str.should == 'Wrapped'
  end
  
  it "should delegate undefined methods to the wrapped string" do
    first_letter = chars('Wrapped')[0,1]
    first_letter.should == 'W'
    first_letter.class.should == Chars
  end
  
  it "should delegate undefined bang methods to the wrapped string" do
    spacious = chars(' Spacious! ')
    a = spacious.strip!
    spacious.should == 'Spacious!'
    spacious.class.should == Chars
  end
  
  it "should respond to it's own methods" do
    chars('Wrapped').should.respond_to(:<=>)
  end
  
  it "should respond to the wrapped string's methods" do
    chars('Wrapped').should.respond_to(:strip)
  end
  
  it "should compare to other Chars instances" do
    chars('a').should < chars('b')
    chars('b').should > chars('a')
    chars('a').<=>(chars('b')).should == -1
  end
  
  it "should compare to strings" do
    chars('a').should < 'b'
    chars('b').should > 'a'
    chars('a').<=>('b').should == -1
  end
  
  it "should concatenate itself to other Chars instances" do
    name = chars('Julian') + chars(' ') + chars('Wright')
    name.should == 'Julian Wright'
  end
  
  it "should concatenate itself to strings" do
    name = chars('Julian') + ' ' + 'Wright'
    name.should == 'Julian Wright'
  end
  
  def chars(string)
    Chars.new(string)
  end
end unless active_support_loaded?