/
string_test.rb
49 lines (44 loc) · 1.47 KB
/
string_test.rb
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
# encoding: utf-8
$KCODE = 'u' if RUBY_VERSION < '1.9'
require 'test_helper'
class StringTest < Test::Unit::TestCase
context "String" do
context "#chars" do
should "conform to doc" do
assert_equal ["d", "o", "g"], "dog".chars.to_a
assert_equal ["δ", "o", "g"], "δog".chars.to_a
result = []
"δog".chars.each {|b| result << b }
assert_equal ["δ", "o", "g"], result
end
end
context "#start_with" do
should "conform to doc" do
assert "Apache".start_with?("Apa")
assert "ruby code".start_with?("python", "perl", "ruby")
assert !"hello world".start_with?("world")
end
end
context "#end_with" do
should "conform to doc" do
assert "Apache".end_with?("ache")
assert "ruby code".end_with?("python", "perl", "code")
assert !"hello world".end_with?("hello")
end
end
context "#partition" do
should "conform to doc" do
assert_equal ["THX", "11", "38"], "THX1138".partition("11")
assert_equal ["THX", "11", "38"], "THX1138".partition(/\d\d/)
assert_equal ["THX1138", "", ""], "THX1138".partition("99")
end
end
context "#rpartition" do
should "conform to doc" do
assert_equal ["THX1", "1", "38"], "THX1138".rpartition("1")
assert_equal ["THX1", "13", "8"], "THX1138".rpartition(/1\d/)
assert_equal ["", "", "THX1138"], "THX1138".rpartition("99")
end
end
end
end