gorillib 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +49 -0
- data/.rspec +2 -0
- data/CHANGELOG.textile +49 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +36 -0
- data/README.textile +6 -1
- data/Rakefile +42 -9
- data/VERSION +1 -1
- data/gorillib.gemspec +110 -73
- data/lib/gorillib/array/deep_compact.rb +3 -12
- data/lib/gorillib/datetime/#flat.rb# +30 -0
- data/lib/gorillib/datetime/flat.rb +2 -10
- data/lib/gorillib/datetime/parse.rb +3 -1
- data/lib/gorillib/enumerable/sum.rb +37 -35
- data/lib/gorillib/hash/deep_compact.rb +3 -13
- data/lib/gorillib/logger/log.rb +1 -1
- data/lib/gorillib/numeric/clamp.rb +9 -0
- data/lib/gorillib/object/try.rb +10 -0
- data/lib/gorillib/object/try_dup.rb +44 -0
- data/lib/gorillib/string/human.rb +1 -3
- data/lib/gorillib/string/truncate.rb +2 -2
- data/spec/array/compact_blank_spec.rb +37 -0
- data/spec/array/extract_options_spec.rb +47 -0
- data/spec/datetime/flat_spec.rb +38 -0
- data/spec/datetime/parse_spec.rb +48 -0
- data/spec/enumerable/sum_spec.rb +56 -0
- data/spec/hash/compact_spec.rb +70 -0
- data/spec/hash/deep_compact_spec.rb +37 -0
- data/spec/hash/deep_merge_spec.rb +117 -0
- data/spec/hash/keys_spec.rb +111 -0
- data/spec/hash/reverse_merge_spec.rb +25 -0
- data/spec/hash/slice_spec.rb +43 -0
- data/spec/hash/zip_spec.rb +31 -0
- data/spec/logger/log_spec.rb +31 -0
- data/spec/metaprogramming/aliasing_spec.rb +177 -0
- data/spec/metaprogramming/cattr_accessor_spec.rb +41 -0
- data/spec/metaprogramming/class_attribute_spec.rb +75 -0
- data/spec/metaprogramming/delegation_spec.rb +166 -0
- data/spec/metaprogramming/mattr_accessor_spec.rb +44 -0
- data/spec/metaprogramming/singleton_class_spec.rb +9 -0
- data/spec/{numeric_spec.rb → numeric/clamp_spec.rb} +2 -2
- data/spec/object/blank_spec.rb +93 -0
- data/spec/object/try_dup_spec.rb +47 -0
- data/spec/object/try_spec.rb +20 -0
- data/spec/spec_helper.rb +13 -8
- data/spec/string/constantize_spec.rb +56 -0
- data/spec/string/human_spec.rb +66 -0
- data/spec/string/inflections_spec.rb +74 -0
- data/{test → spec}/string/inflector_test_cases.rb +0 -0
- data/spec/string/truncate_spec.rb +42 -0
- data/spec/support/kcode_test_helper.rb +16 -0
- metadata +209 -96
- data/.document +0 -5
- data/fiddle/hubahuba.rb +0 -62
- data/spec/blank_spec.rb +0 -86
- data/spec/deep_compact_spec.rb +0 -36
- data/spec/gorillib_spec.rb +0 -7
- data/spec/rcov.opts +0 -6
- data/spec/spec.opts +0 -4
- data/spec/spec_tasks.rake +0 -15
- data/test/abstract_unit.rb +0 -25
- data/test/array/compact_blank_test.rb +0 -33
- data/test/array/extract_options_test.rb +0 -39
- data/test/datetime/flat_test.rb +0 -0
- data/test/datetime/parse_test.rb +0 -0
- data/test/enumerable/sum_test.rb +0 -50
- data/test/hash/compact_test.rb +0 -38
- data/test/hash/deep_merge_test.rb +0 -30
- data/test/hash/keys_test.rb +0 -110
- data/test/hash/reverse_merge_test.rb +0 -20
- data/test/hash/slice_test.rb +0 -47
- data/test/hash/zip_test.rb +0 -0
- data/test/logger/log_test.rb +0 -0
- data/test/metaprogramming/aliasing_test.rb +0 -188
- data/test/metaprogramming/cattr_accessor_test.rb +0 -38
- data/test/metaprogramming/class_attribute_test.rb +0 -73
- data/test/metaprogramming/delegation_test.rb +0 -166
- data/test/metaprogramming/mattr_accessor_test.rb +0 -40
- data/test/metaprogramming/singleton_class_test.rb +0 -9
- data/test/object/blank_test.rb +0 -22
- data/test/string/constantize_test.rb +0 -30
- data/test/string/human_test.rb +0 -65
- data/test/string/inflections_test.rb +0 -57
- data/test/string/truncate_test.rb +0 -37
@@ -1,166 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
2
|
-
require 'gorillib/delegation'
|
3
|
-
|
4
|
-
module One
|
5
|
-
Constant1 = "Hello World"
|
6
|
-
Constant2 = "What\'s up?"
|
7
|
-
end
|
8
|
-
|
9
|
-
class Ab
|
10
|
-
include One
|
11
|
-
Constant1 = "Hello World" # Will have different object id than One::Constant1
|
12
|
-
Constant3 = "Goodbye World"
|
13
|
-
end
|
14
|
-
|
15
|
-
module Xy
|
16
|
-
class Bc
|
17
|
-
include One
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module Yz
|
22
|
-
module Zy
|
23
|
-
class Cd
|
24
|
-
include One
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
Somewhere = Struct.new(:street, :city)
|
30
|
-
|
31
|
-
Someone = Struct.new(:name, :place) do
|
32
|
-
delegate :street, :city, :to_f, :to => :place
|
33
|
-
delegate :upcase, :to => "place.city"
|
34
|
-
end
|
35
|
-
|
36
|
-
Invoice = Struct.new(:client) do
|
37
|
-
delegate :street, :city, :name, :to => :client, :prefix => true
|
38
|
-
delegate :street, :city, :name, :to => :client, :prefix => :customer
|
39
|
-
end
|
40
|
-
|
41
|
-
Project = Struct.new(:description, :person) do
|
42
|
-
delegate :name, :to => :person, :allow_nil => true
|
43
|
-
delegate :to_f, :to => :description, :allow_nil => true
|
44
|
-
end
|
45
|
-
|
46
|
-
Developer = Struct.new(:client) do
|
47
|
-
delegate :name, :to => :client, :prefix => nil
|
48
|
-
end
|
49
|
-
|
50
|
-
Tester = Struct.new(:client) do
|
51
|
-
delegate :name, :to => :client, :prefix => false
|
52
|
-
end
|
53
|
-
|
54
|
-
class Name
|
55
|
-
delegate :upcase, :to => :@full_name
|
56
|
-
|
57
|
-
def initialize(first, last)
|
58
|
-
@full_name = "#{first} #{last}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class ModuleTest < Test::Unit::TestCase
|
63
|
-
def setup
|
64
|
-
@david = Someone.new("David", Somewhere.new("Paulina", "Chicago"))
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_delegation_to_methods
|
68
|
-
assert_equal "Paulina", @david.street
|
69
|
-
assert_equal "Chicago", @david.city
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_delegation_down_hierarchy
|
73
|
-
assert_equal "CHICAGO", @david.upcase
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_delegation_to_instance_variable
|
77
|
-
david = Name.new("David", "Hansson")
|
78
|
-
assert_equal "DAVID HANSSON", david.upcase
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_missing_delegation_target
|
82
|
-
assert_raise(ArgumentError) do
|
83
|
-
Name.send :delegate, :nowhere
|
84
|
-
end
|
85
|
-
assert_raise(ArgumentError) do
|
86
|
-
Name.send :delegate, :noplace, :tos => :hollywood
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_delegation_prefix
|
91
|
-
invoice = Invoice.new(@david)
|
92
|
-
assert_equal invoice.client_name, "David"
|
93
|
-
assert_equal invoice.client_street, "Paulina"
|
94
|
-
assert_equal invoice.client_city, "Chicago"
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_delegation_custom_prefix
|
98
|
-
invoice = Invoice.new(@david)
|
99
|
-
assert_equal invoice.customer_name, "David"
|
100
|
-
assert_equal invoice.customer_street, "Paulina"
|
101
|
-
assert_equal invoice.customer_city, "Chicago"
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_delegation_prefix_with_nil_or_false
|
105
|
-
assert_equal Developer.new(@david).name, "David"
|
106
|
-
assert_equal Tester.new(@david).name, "David"
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_delegation_prefix_with_instance_variable
|
110
|
-
assert_raise ArgumentError do
|
111
|
-
Class.new do
|
112
|
-
def initialize(client)
|
113
|
-
@client = client
|
114
|
-
end
|
115
|
-
delegate :name, :address, :to => :@client, :prefix => true
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_delegation_with_allow_nil
|
121
|
-
rails = Project.new("Rails", Someone.new("David"))
|
122
|
-
assert_equal rails.name, "David"
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_delegation_with_allow_nil_and_nil_value
|
126
|
-
rails = Project.new("Rails")
|
127
|
-
assert_nil rails.name
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_delegation_with_allow_nil_and_nil_value_and_prefix
|
131
|
-
Project.class_eval do
|
132
|
-
delegate :name, :to => :person, :allow_nil => true, :prefix => true
|
133
|
-
end
|
134
|
-
rails = Project.new("Rails")
|
135
|
-
assert_nil rails.person_name
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_delegation_without_allow_nil_and_nil_value
|
139
|
-
david = Someone.new("David")
|
140
|
-
assert_raise(RuntimeError) { david.street }
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_delegation_to_method_that_exists_on_nil
|
144
|
-
nil_person = Someone.new(nil)
|
145
|
-
assert_equal 0.0, nil_person.to_f
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_delegation_to_method_that_exists_on_nil_when_allowing_nil
|
149
|
-
nil_project = Project.new(nil)
|
150
|
-
assert_equal 0.0, nil_project.to_f
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_delegation_does_not_raise_error_when_removing_singleton_instance_methods
|
154
|
-
parent = Class.new do
|
155
|
-
def self.parent_method; end
|
156
|
-
end
|
157
|
-
|
158
|
-
assert_nothing_raised do
|
159
|
-
Class.new(parent) do
|
160
|
-
class << self
|
161
|
-
delegate :parent_method, :to => :superclass
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
2
|
-
require 'gorillib/metaprogramming/cattr_accessor'
|
3
|
-
|
4
|
-
class ModuleAttributeAccessorTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
m = @module = Module.new do
|
7
|
-
mattr_accessor :foo
|
8
|
-
mattr_accessor :bar, :instance_writer => false
|
9
|
-
mattr_reader :shaq, :instance_reader => false
|
10
|
-
end
|
11
|
-
@class = Class.new
|
12
|
-
@class.instance_eval { include m }
|
13
|
-
@object = @class.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_use_mattr_default
|
17
|
-
assert_nil @module.foo
|
18
|
-
assert_nil @object.foo
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_set_mattr_value
|
22
|
-
@module.foo = :test
|
23
|
-
assert_equal :test, @object.foo
|
24
|
-
|
25
|
-
@object.foo = :test2
|
26
|
-
assert_equal :test2, @module.foo
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_not_create_instance_writer
|
30
|
-
assert_respond_to @module, :foo
|
31
|
-
assert_respond_to @module, :foo=
|
32
|
-
assert_respond_to @object, :bar
|
33
|
-
assert !@object.respond_to?(:bar=)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_not_create_instance_reader
|
37
|
-
assert_respond_to @module, :shaq
|
38
|
-
assert !@object.respond_to?(:shaq)
|
39
|
-
end
|
40
|
-
end
|
data/test/object/blank_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
2
|
-
require 'gorillib/object/blank'
|
3
|
-
|
4
|
-
class BlankTest < Test::Unit::TestCase
|
5
|
-
BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ]
|
6
|
-
NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ]
|
7
|
-
|
8
|
-
def test_blank
|
9
|
-
BLANK.each { |v| assert v.blank?, "#{v.inspect} should be blank" }
|
10
|
-
NOT.each { |v| assert !v.blank?, "#{v.inspect} should not be blank" }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_present
|
14
|
-
BLANK.each { |v| assert !v.present?, "#{v.inspect} should not be present" }
|
15
|
-
NOT.each { |v| assert v.present?, "#{v.inspect} should be present" }
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_presence
|
19
|
-
BLANK.each { |v| assert_equal nil, v.presence, "#{v.inspect}.presence should return nil" }
|
20
|
-
NOT.each { |v| assert_equal v, v.presence, "#{v.inspect}.presence should return self" }
|
21
|
-
end
|
22
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
2
|
-
require File.dirname(__FILE__)+'/inflector_test_cases'
|
3
|
-
require 'gorillib/string/constantize'
|
4
|
-
|
5
|
-
module Ace
|
6
|
-
module Base
|
7
|
-
class Case
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
class InflectorTest < Test::Unit::TestCase
|
14
|
-
include InflectorTestCases
|
15
|
-
|
16
|
-
def test_constantize
|
17
|
-
assert_nothing_raised{ assert_equal Ace::Base::Case, "Ace::Base::Case".constantize }
|
18
|
-
assert_nothing_raised{ assert_equal Ace::Base::Case, "::Ace::Base::Case".constantize }
|
19
|
-
assert_nothing_raised{ assert_equal InflectorTest, "InflectorTest".constantize }
|
20
|
-
assert_nothing_raised{ assert_equal InflectorTest, "::InflectorTest".constantize }
|
21
|
-
assert_raise(NameError){ "UnknownClass" .constantize }
|
22
|
-
assert_raise(NameError){ "An invalid string".constantize }
|
23
|
-
assert_raise(NameError){ "InvalidClass\n" .constantize }
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_constantize_does_lexical_lookup
|
27
|
-
assert_raise(NameError) { "Ace::Base::InflectorTest".constantize }
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/string/human_test.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
2
|
-
require File.dirname(__FILE__)+'/inflector_test_cases'
|
3
|
-
require 'gorillib/string/human'
|
4
|
-
|
5
|
-
class InflectorTest < Test::Unit::TestCase
|
6
|
-
include InflectorTestCases
|
7
|
-
|
8
|
-
def test_titleize
|
9
|
-
MixtureToTitleCase.each do |before, titleized|
|
10
|
-
assert_equal(titleized, before.titleize)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
MixtureToTitleCase.each do |before, titleized|
|
15
|
-
define_method "test_titleize_#{before}" do
|
16
|
-
assert_equal(titleized, before.titleize )
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_humanize
|
21
|
-
UnderscoreToHuman.each do |underscored, human|
|
22
|
-
assert_equal(human, underscored.humanize )
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class ArrayExtToSentenceTests < Test::Unit::TestCase
|
28
|
-
def test_plain_array_to_sentence
|
29
|
-
assert_equal "", [].to_sentence
|
30
|
-
assert_equal "one", ['one'].to_sentence
|
31
|
-
assert_equal "one and two", ['one', 'two'].to_sentence
|
32
|
-
assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_to_sentence_with_words_connector
|
36
|
-
assert_equal "one two, and three", ['one', 'two', 'three'].to_sentence(:words_connector => ' ')
|
37
|
-
assert_equal "one & two, and three", ['one', 'two', 'three'].to_sentence(:words_connector => ' & ')
|
38
|
-
assert_equal "onetwo, and three", ['one', 'two', 'three'].to_sentence(:words_connector => nil)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_to_sentence_with_last_word_connector
|
42
|
-
assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ', and also ')
|
43
|
-
assert_equal "one, twothree", ['one', 'two', 'three'].to_sentence(:last_word_connector => nil)
|
44
|
-
assert_equal "one, two three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ' ')
|
45
|
-
assert_equal "one, two and three", ['one', 'two', 'three'].to_sentence(:last_word_connector => ' and ')
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_two_elements
|
49
|
-
assert_equal "one and two", ['one', 'two'].to_sentence
|
50
|
-
assert_equal "one two", ['one', 'two'].to_sentence(:two_words_connector => ' ')
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_one_element
|
54
|
-
assert_equal "one", ['one'].to_sentence
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_one_element_not_same_object
|
58
|
-
elements = ["one"]
|
59
|
-
assert_not_equal elements[0].object_id, elements.to_sentence.object_id
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_one_non_string_element
|
63
|
-
assert_equal '1', [1].to_sentence
|
64
|
-
end
|
65
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
2
|
-
require 'gorillib/string/inflections'
|
3
|
-
require File.dirname(__FILE__)+'/inflector_test_cases'
|
4
|
-
|
5
|
-
class InflectorTest < Test::Unit::TestCase
|
6
|
-
include InflectorTestCases
|
7
|
-
|
8
|
-
def test_camelize
|
9
|
-
CamelToUnderscore.each do |cameled, underscored|
|
10
|
-
assert_equal(cameled, underscored.camelize)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_camelize_with_lower_downcases_the_first_letter
|
15
|
-
assert_equal('capital', 'Capital'.camelize(:lower))
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_snakeize
|
19
|
-
UnderscoreToLowerCamel.each do |underscored, snaked|
|
20
|
-
assert_equal(snaked, underscored.snakeize)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_underscore_to_lower_camel
|
25
|
-
UnderscoreToLowerCamel.each do |underscored, lower_cameled|
|
26
|
-
assert_equal(lower_cameled, underscored.camelize(:lower))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_underscore
|
31
|
-
CamelToUnderscore.each do |cameled, underscored|
|
32
|
-
assert_equal(underscored, cameled.underscore)
|
33
|
-
end
|
34
|
-
CamelToUnderscoreWithoutReverse.each do |cameled, underscored|
|
35
|
-
assert_equal(underscored, cameled.underscore)
|
36
|
-
end
|
37
|
-
assert_equal "html_tidy", "HTMLTidy".underscore
|
38
|
-
assert_equal "html_tidy_generator", "HTMLTidyGenerator".underscore
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_camelize_with_module
|
42
|
-
CamelWithModuleToUnderscoreWithSlash.each do |cameled, underscored|
|
43
|
-
assert_equal(cameled, underscored.camelize)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_underscore_with_slashes
|
48
|
-
CamelWithModuleToUnderscoreWithSlash.each do |cameled, underscored|
|
49
|
-
assert_equal(underscored, cameled.underscore)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_demodulize
|
54
|
-
assert_equal "Account", "MyApplication::Billing::Account".demodulize
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.dirname(__FILE__)+'/../abstract_unit'
|
3
|
-
require File.dirname(__FILE__)+'/inflector_test_cases'
|
4
|
-
require 'gorillib/string/truncate'
|
5
|
-
|
6
|
-
class StringInflectionsTest < Test::Unit::TestCase
|
7
|
-
include InflectorTestCases
|
8
|
-
|
9
|
-
def test_truncate
|
10
|
-
assert_equal "Hello World!", "Hello World!".truncate(12)
|
11
|
-
assert_equal "Hello Wor...", "Hello World!!".truncate(12)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_truncate_with_omission_and_seperator
|
15
|
-
assert_equal "Hello[...]", "Hello World!".truncate(10, :omission => "[...]")
|
16
|
-
assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => ' ')
|
17
|
-
assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => ' ')
|
18
|
-
assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ')
|
19
|
-
end
|
20
|
-
|
21
|
-
if RUBY_VERSION < '1.9.0'
|
22
|
-
def test_truncate_multibyte
|
23
|
-
with_kcode 'none' do
|
24
|
-
assert_equal "\354\225\210\353\205\225\355...", "\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224".truncate(10)
|
25
|
-
end
|
26
|
-
with_kcode 'u' do
|
27
|
-
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
|
28
|
-
"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".truncate(10)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
else
|
32
|
-
def test_truncate_multibyte
|
33
|
-
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
|
34
|
-
"\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8').truncate(10)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|