opal-activesupport 0.2.0 → 0.3.0

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -0
  3. data/Rakefile +9 -2
  4. data/lib/opal/activesupport/version.rb +1 -1
  5. data/opal-activesupport.gemspec +1 -1
  6. data/opal/active_support/core_ext/array.rb +2 -0
  7. data/opal/active_support/core_ext/array/grouping.rb +99 -0
  8. data/opal/active_support/core_ext/array/wrap.rb +45 -0
  9. data/opal/active_support/core_ext/module.rb +2 -0
  10. data/opal/active_support/core_ext/module/delegation.rb +64 -0
  11. data/opal/active_support/core_ext/module/introspection.rb +62 -0
  12. data/test/abstract_unit.rb +46 -0
  13. data/test/core_ext/array_ext_test.rb +471 -0
  14. data/test/core_ext/blank_test.rb +24 -0
  15. data/{spec/core_ext/class/attribute_spec.rb → test/core_ext/class/attribute_test.rb} +16 -20
  16. data/test/core_ext/kernel_test.rb +124 -0
  17. data/test/core_ext/module/remove_method_test.rb +29 -0
  18. data/test/core_ext/module_test.rb +439 -0
  19. data/{spec/core_ext/numeric_spec.rb → test/core_ext/numeric_ext_test.rb} +110 -116
  20. data/test/core_ext/object_and_class_ext_test.rb +183 -0
  21. data/test/core_ext/string_ext_test.rb +628 -0
  22. data/{spec → test}/empty_bool.rb +0 -0
  23. data/{spec → test}/inflector_test_cases.rb +0 -0
  24. data/test/minitest/autorun.rb +29 -0
  25. metadata +39 -30
  26. data/spec/core_ext/array/extract_options_spec.rb +0 -49
  27. data/spec/core_ext/kernel_spec.rb +0 -9
  28. data/spec/core_ext/module/remove_method_spec.rb +0 -29
  29. data/spec/core_ext/object/blank_spec.rb +0 -40
  30. data/spec/core_ext/object/try_spec.rb +0 -102
  31. data/spec/core_ext/string_spec.rb +0 -71
  32. data/spec/spec_helper.rb +0 -26
@@ -1,13 +1,15 @@
1
- require 'spec_helper'
2
- # require 'active_support/time'
1
+ require 'abstract_unit'
2
+ require 'active_support/time'
3
3
  require 'active_support/core_ext/numeric'
4
4
  require 'active_support/core_ext/integer'
5
5
 
6
- describe 'Numeric' do
7
- before do
8
- # @now = Time.local(2005,2,10,15,30,45)
9
- @now = Time.mktime(2005,2,10,15,30,45)
10
- # @dtnow = DateTime.civil(2005,2,10,15,30,45)
6
+ class DateTime < Date
7
+ end unless defined? DateTime
8
+
9
+ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase
10
+ def setup
11
+ @now = Time.local(2005,2,10,15,30,45)
12
+ @dtnow = DateTime.civil(2005,2,10,15,30,45)
11
13
  @seconds = {
12
14
  1.minute => 60,
13
15
  10.minutes => 600,
@@ -17,126 +19,118 @@ describe 'Numeric' do
17
19
  }
18
20
  end
19
21
 
20
- it 'has time units' do
22
+ def test_units
21
23
  @seconds.each do |actual, expected|
22
- actual.should == expected
24
+ assert_equal expected, actual
23
25
  end
24
26
  end
25
27
 
26
- it 'has intervals' do
28
+ def test_intervals
27
29
  @seconds.values.each do |seconds|
28
30
  assert_equal seconds.since(@now), @now + seconds
29
31
  assert_equal seconds.until(@now), @now - seconds
30
32
  end
31
33
  end
34
+
35
+ # # Test intervals based from Time.now
36
+ # def test_now
37
+ # @seconds.values.each do |seconds|
38
+ # now = Time.now
39
+ # assert seconds.ago >= now - seconds
40
+ # now = Time.now
41
+ # assert seconds.from_now >= now + seconds
42
+ # end
43
+ # end
44
+ #
45
+ # def test_irregular_durations
46
+ # assert_equal @now.advance(:days => 3000), 3000.days.since(@now)
47
+ # assert_equal @now.advance(:months => 1), 1.month.since(@now)
48
+ # assert_equal @now.advance(:months => -1), 1.month.until(@now)
49
+ # assert_equal @now.advance(:years => 20), 20.years.since(@now)
50
+ # assert_equal @dtnow.advance(:days => 3000), 3000.days.since(@dtnow)
51
+ # assert_equal @dtnow.advance(:months => 1), 1.month.since(@dtnow)
52
+ # assert_equal @dtnow.advance(:months => -1), 1.month.until(@dtnow)
53
+ # assert_equal @dtnow.advance(:years => 20), 20.years.since(@dtnow)
54
+ # end
55
+ #
56
+ # def test_duration_addition
57
+ # assert_equal @now.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@now)
58
+ # assert_equal @now.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@now)
59
+ # assert_equal @now.advance(:years => 2), (4.years - 2.years).since(@now)
60
+ # assert_equal @dtnow.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@dtnow)
61
+ # assert_equal @dtnow.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@dtnow)
62
+ # assert_equal @dtnow.advance(:years => 2), (4.years - 2.years).since(@dtnow)
63
+ # end
64
+ #
65
+ # def test_time_plus_duration
66
+ # assert_equal @now + 8, @now + 8.seconds
67
+ # assert_equal @now + 22.9, @now + 22.9.seconds
68
+ # assert_equal @now.advance(:days => 15), @now + 15.days
69
+ # assert_equal @now.advance(:months => 1), @now + 1.month
70
+ # assert_equal @dtnow.since(8), @dtnow + 8.seconds
71
+ # assert_equal @dtnow.since(22.9), @dtnow + 22.9.seconds
72
+ # assert_equal @dtnow.advance(:days => 15), @dtnow + 15.days
73
+ # assert_equal @dtnow.advance(:months => 1), @dtnow + 1.month
74
+ # end
75
+ #
76
+ # def test_chaining_duration_operations
77
+ # assert_equal @now.advance(:days => 2).advance(:months => -3), @now + 2.days - 3.months
78
+ # assert_equal @now.advance(:days => 1).advance(:months => 2), @now + 1.day + 2.months
79
+ # assert_equal @dtnow.advance(:days => 2).advance(:months => -3), @dtnow + 2.days - 3.months
80
+ # assert_equal @dtnow.advance(:days => 1).advance(:months => 2), @dtnow + 1.day + 2.months
81
+ # end
82
+ #
83
+ # def test_duration_after_convertion_is_no_longer_accurate
84
+ # assert_equal 30.days.to_i.since(@now), 1.month.to_i.since(@now)
85
+ # assert_equal 365.25.days.to_f.since(@now), 1.year.to_f.since(@now)
86
+ # assert_equal 30.days.to_i.since(@dtnow), 1.month.to_i.since(@dtnow)
87
+ # assert_equal 365.25.days.to_f.since(@dtnow), 1.year.to_f.since(@dtnow)
88
+ # end
89
+ #
90
+ # def test_add_one_year_to_leap_day
91
+ # assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10) + 1.year
92
+ # assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10) + 1.year
93
+ # end
94
+ #
95
+ # def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set
96
+ # Time.zone = nil
97
+ # with_env_tz 'US/Eastern' do
98
+ # Time.stubs(:now).returns Time.local(2000)
99
+ # # since
100
+ # assert_equal false, 5.since.is_a?(ActiveSupport::TimeWithZone)
101
+ # assert_equal Time.local(2000,1,1,0,0,5), 5.since
102
+ # # ago
103
+ # assert_equal false, 5.ago.is_a?(ActiveSupport::TimeWithZone)
104
+ # assert_equal Time.local(1999,12,31,23,59,55), 5.ago
105
+ # end
106
+ # end
107
+ #
108
+ # def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
109
+ # Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
110
+ # with_env_tz 'US/Eastern' do
111
+ # Time.stubs(:now).returns Time.local(2000)
112
+ # # since
113
+ # assert_equal true, 5.since.is_a?(ActiveSupport::TimeWithZone)
114
+ # assert_equal Time.utc(2000,1,1,0,0,5), 5.since.time
115
+ # assert_equal 'Eastern Time (US & Canada)', 5.since.time_zone.name
116
+ # # ago
117
+ # assert_equal true, 5.ago.is_a?(ActiveSupport::TimeWithZone)
118
+ # assert_equal Time.utc(1999,12,31,23,59,55), 5.ago.time
119
+ # assert_equal 'Eastern Time (US & Canada)', 5.ago.time_zone.name
120
+ # end
121
+ # ensure
122
+ # Time.zone = nil
123
+ # end
124
+ #
125
+ # protected
126
+ # def with_env_tz(new_tz = 'US/Eastern')
127
+ # old_tz, ENV['TZ'] = ENV['TZ'], new_tz
128
+ # yield
129
+ # ensure
130
+ # old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
131
+ # end
32
132
  end
33
133
 
34
- # def test_intervals
35
- # @seconds.values.each do |seconds|
36
- # assert_equal seconds.since(@now), @now + seconds
37
- # assert_equal seconds.until(@now), @now - seconds
38
- # end
39
- # end
40
- #
41
- # # Test intervals based from Time.now
42
- # def test_now
43
- # @seconds.values.each do |seconds|
44
- # now = Time.now
45
- # assert seconds.ago >= now - seconds
46
- # now = Time.now
47
- # assert seconds.from_now >= now + seconds
48
- # end
49
- # end
50
- #
51
- # def test_irregular_durations
52
- # assert_equal @now.advance(:days => 3000), 3000.days.since(@now)
53
- # assert_equal @now.advance(:months => 1), 1.month.since(@now)
54
- # assert_equal @now.advance(:months => -1), 1.month.until(@now)
55
- # assert_equal @now.advance(:years => 20), 20.years.since(@now)
56
- # assert_equal @dtnow.advance(:days => 3000), 3000.days.since(@dtnow)
57
- # assert_equal @dtnow.advance(:months => 1), 1.month.since(@dtnow)
58
- # assert_equal @dtnow.advance(:months => -1), 1.month.until(@dtnow)
59
- # assert_equal @dtnow.advance(:years => 20), 20.years.since(@dtnow)
60
- # end
61
- #
62
- # def test_duration_addition
63
- # assert_equal @now.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@now)
64
- # assert_equal @now.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@now)
65
- # assert_equal @now.advance(:years => 2), (4.years - 2.years).since(@now)
66
- # assert_equal @dtnow.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@dtnow)
67
- # assert_equal @dtnow.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@dtnow)
68
- # assert_equal @dtnow.advance(:years => 2), (4.years - 2.years).since(@dtnow)
69
- # end
70
- #
71
- # def test_time_plus_duration
72
- # assert_equal @now + 8, @now + 8.seconds
73
- # assert_equal @now + 22.9, @now + 22.9.seconds
74
- # assert_equal @now.advance(:days => 15), @now + 15.days
75
- # assert_equal @now.advance(:months => 1), @now + 1.month
76
- # assert_equal @dtnow.since(8), @dtnow + 8.seconds
77
- # assert_equal @dtnow.since(22.9), @dtnow + 22.9.seconds
78
- # assert_equal @dtnow.advance(:days => 15), @dtnow + 15.days
79
- # assert_equal @dtnow.advance(:months => 1), @dtnow + 1.month
80
- # end
81
- #
82
- # def test_chaining_duration_operations
83
- # assert_equal @now.advance(:days => 2).advance(:months => -3), @now + 2.days - 3.months
84
- # assert_equal @now.advance(:days => 1).advance(:months => 2), @now + 1.day + 2.months
85
- # assert_equal @dtnow.advance(:days => 2).advance(:months => -3), @dtnow + 2.days - 3.months
86
- # assert_equal @dtnow.advance(:days => 1).advance(:months => 2), @dtnow + 1.day + 2.months
87
- # end
88
- #
89
- # def test_duration_after_convertion_is_no_longer_accurate
90
- # assert_equal 30.days.to_i.since(@now), 1.month.to_i.since(@now)
91
- # assert_equal 365.25.days.to_f.since(@now), 1.year.to_f.since(@now)
92
- # assert_equal 30.days.to_i.since(@dtnow), 1.month.to_i.since(@dtnow)
93
- # assert_equal 365.25.days.to_f.since(@dtnow), 1.year.to_f.since(@dtnow)
94
- # end
95
- #
96
- # def test_add_one_year_to_leap_day
97
- # assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10) + 1.year
98
- # assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10) + 1.year
99
- # end
100
- #
101
- # def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set
102
- # Time.zone = nil
103
- # with_env_tz 'US/Eastern' do
104
- # Time.stubs(:now).returns Time.local(2000)
105
- # # since
106
- # assert_equal false, 5.since.is_a?(ActiveSupport::TimeWithZone)
107
- # assert_equal Time.local(2000,1,1,0,0,5), 5.since
108
- # # ago
109
- # assert_equal false, 5.ago.is_a?(ActiveSupport::TimeWithZone)
110
- # assert_equal Time.local(1999,12,31,23,59,55), 5.ago
111
- # end
112
- # end
113
- #
114
- # def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set
115
- # Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
116
- # with_env_tz 'US/Eastern' do
117
- # Time.stubs(:now).returns Time.local(2000)
118
- # # since
119
- # assert_equal true, 5.since.is_a?(ActiveSupport::TimeWithZone)
120
- # assert_equal Time.utc(2000,1,1,0,0,5), 5.since.time
121
- # assert_equal 'Eastern Time (US & Canada)', 5.since.time_zone.name
122
- # # ago
123
- # assert_equal true, 5.ago.is_a?(ActiveSupport::TimeWithZone)
124
- # assert_equal Time.utc(1999,12,31,23,59,55), 5.ago.time
125
- # assert_equal 'Eastern Time (US & Canada)', 5.ago.time_zone.name
126
- # end
127
- # ensure
128
- # Time.zone = nil
129
- # end
130
- #
131
- # protected
132
- # def with_env_tz(new_tz = 'US/Eastern')
133
- # old_tz, ENV['TZ'] = ENV['TZ'], new_tz
134
- # yield
135
- # ensure
136
- # old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
137
- # end
138
- # end
139
- #
140
134
  # class NumericExtDateTest < ActiveSupport::TestCase
141
135
  # def setup
142
136
  # @today = Date.today
@@ -0,0 +1,183 @@
1
+ require 'abstract_unit'
2
+ require 'active_support/time'
3
+ require 'active_support/core_ext/object'
4
+ # require 'active_support/core_ext/class/subclasses'
5
+ #
6
+ # class ClassA; end
7
+ # class ClassB < ClassA; end
8
+ # class ClassC < ClassB; end
9
+ # class ClassD < ClassA; end
10
+ #
11
+ # class ClassI; end
12
+ # class ClassJ < ClassI; end
13
+ #
14
+ # class ClassK
15
+ # end
16
+ # module Nested
17
+ # class << self
18
+ # def on_const_missing(&callback)
19
+ # @on_const_missing = callback
20
+ # end
21
+ # private
22
+ # def const_missing(mod_id)
23
+ # @on_const_missing[mod_id] if @on_const_missing
24
+ # super
25
+ # end
26
+ # end
27
+ # class ClassL < ClassK
28
+ # end
29
+ # end
30
+ #
31
+ # class ObjectTests < ActiveSupport::TestCase
32
+ # class DuckTime
33
+ # def acts_like_time?
34
+ # true
35
+ # end
36
+ # end
37
+ #
38
+ # def test_duck_typing
39
+ # object = Object.new
40
+ # time = Time.now
41
+ # date = Date.today
42
+ # dt = DateTime.new
43
+ # duck = DuckTime.new
44
+ #
45
+ # assert !object.acts_like?(:time)
46
+ # assert !object.acts_like?(:date)
47
+ #
48
+ # assert time.acts_like?(:time)
49
+ # assert !time.acts_like?(:date)
50
+ #
51
+ # assert !date.acts_like?(:time)
52
+ # assert date.acts_like?(:date)
53
+ #
54
+ # assert dt.acts_like?(:time)
55
+ # assert dt.acts_like?(:date)
56
+ #
57
+ # assert duck.acts_like?(:time)
58
+ # assert !duck.acts_like?(:date)
59
+ # end
60
+ # end
61
+ #
62
+ # class ObjectInstanceVariableTest < ActiveSupport::TestCase
63
+ # def setup
64
+ # @source, @dest = Object.new, Object.new
65
+ # @source.instance_variable_set(:@bar, 'bar')
66
+ # @source.instance_variable_set(:@baz, 'baz')
67
+ # end
68
+ #
69
+ # def test_instance_variable_names
70
+ # assert_equal %w(@bar @baz), @source.instance_variable_names.sort
71
+ # end
72
+ #
73
+ # def test_instance_values
74
+ # object = Object.new
75
+ # object.instance_variable_set :@a, 1
76
+ # object.instance_variable_set :@b, 2
77
+ # assert_equal({'a' => 1, 'b' => 2}, object.instance_values)
78
+ # end
79
+ #
80
+ # def test_instance_exec_passes_arguments_to_block
81
+ # assert_equal %w(hello goodbye), 'hello'.instance_exec('goodbye') { |v| [self, v] }
82
+ # end
83
+ #
84
+ # def test_instance_exec_with_frozen_obj
85
+ # assert_equal %w(olleh goodbye), 'hello'.freeze.instance_exec('goodbye') { |v| [reverse, v] }
86
+ # end
87
+ #
88
+ # def test_instance_exec_nested
89
+ # assert_equal %w(goodbye olleh bar), 'hello'.instance_exec('goodbye') { |arg|
90
+ # [arg] + instance_exec('bar') { |v| [reverse, v] } }
91
+ # end
92
+ # end
93
+
94
+ class ObjectTryTest < ActiveSupport::TestCase
95
+ def setup
96
+ @string = "Hello"
97
+ end
98
+
99
+ def test_nonexisting_method
100
+ method = :undefined_method
101
+ assert !@string.respond_to?(method)
102
+ assert_nil @string.try(method)
103
+ end
104
+
105
+ def test_nonexisting_method_with_arguments
106
+ method = :undefined_method
107
+ assert !@string.respond_to?(method)
108
+ assert_nil @string.try(method, 'llo', 'y')
109
+ end
110
+
111
+ def test_nonexisting_method_bang
112
+ method = :undefined_method
113
+ assert !@string.respond_to?(method)
114
+ assert_raise(NoMethodError) { @string.try!(method) }
115
+ end
116
+
117
+ def test_nonexisting_method_with_arguments_bang
118
+ method = :undefined_method
119
+ assert !@string.respond_to?(method)
120
+ assert_raise(NoMethodError) { @string.try!(method, 'llo', 'y') }
121
+ end
122
+
123
+ def test_try_only_block_bang
124
+ assert_equal @string.reverse, @string.try! { |s| s.reverse }
125
+ end
126
+
127
+ def test_valid_method
128
+ assert_equal 5, @string.try(:size)
129
+ end
130
+
131
+ def test_argument_forwarding
132
+ assert_equal 'Hey', @string.try(:sub, 'llo', 'y')
133
+ end
134
+
135
+ def test_block_forwarding
136
+ assert_equal 'Hey', @string.try(:sub, 'llo') { |match| 'y' }
137
+ end
138
+
139
+ def test_nil_to_type
140
+ assert_nil nil.try(:to_s)
141
+ assert_nil nil.try(:to_i)
142
+ end
143
+
144
+ def test_false_try
145
+ assert_equal 'false', false.try(:to_s)
146
+ end
147
+
148
+ def test_try_only_block
149
+ assert_equal @string.reverse, @string.try { |s| s.reverse }
150
+ end
151
+
152
+ def test_try_only_block_nil
153
+ ran = false
154
+ nil.try { ran = true }
155
+ assert_equal false, ran
156
+ end
157
+
158
+ # Opal doesn't support private methods
159
+ # def test_try_with_private_method_bang
160
+ # klass = Class.new do
161
+ # private
162
+ #
163
+ # def private_method
164
+ # 'private method'
165
+ # end
166
+ # end
167
+ #
168
+ # assert_raise(NoMethodError) { klass.new.try!(:private_method) }
169
+ # end
170
+
171
+ # Opal doesn't support private methods
172
+ # def test_try_with_private_method
173
+ # klass = Class.new do
174
+ # private
175
+ #
176
+ # def private_method
177
+ # 'private method'
178
+ # end
179
+ # end
180
+ #
181
+ # assert_nil klass.new.try(:private_method)
182
+ # end
183
+ end
@@ -0,0 +1,628 @@
1
+ # encoding: utf-8
2
+ require 'date'
3
+ require 'abstract_unit'
4
+ require 'inflector_test_cases'
5
+ # require 'constantize_test_cases'
6
+
7
+ require 'active_support/inflector'
8
+ require 'active_support/core_ext/string'
9
+ require 'active_support/time'
10
+ # require 'active_support/core_ext/string/strip'
11
+ # require 'active_support/core_ext/string/output_safety'
12
+ # require 'active_support/core_ext/string/indent'
13
+
14
+ module Ace
15
+ module Base
16
+ class Case
17
+ end
18
+ end
19
+ end
20
+
21
+ class StringInflectionsTest < ActiveSupport::TestCase
22
+ include InflectorTestCases
23
+ # include ConstantizeTestCases
24
+
25
+ # def test_strip_heredoc_on_an_empty_string
26
+ # assert_equal '', ''.strip_heredoc
27
+ # end
28
+ #
29
+ # def test_strip_heredoc_on_a_string_with_no_lines
30
+ # assert_equal 'x', 'x'.strip_heredoc
31
+ # assert_equal 'x', ' x'.strip_heredoc
32
+ # end
33
+ #
34
+ # def test_strip_heredoc_on_a_heredoc_with_no_margin
35
+ # assert_equal "foo\nbar", "foo\nbar".strip_heredoc
36
+ # assert_equal "foo\n bar", "foo\n bar".strip_heredoc
37
+ # end
38
+ #
39
+ # def test_strip_heredoc_on_a_regular_indented_heredoc
40
+ # assert_equal "foo\n bar\nbaz\n", <<-EOS.strip_heredoc
41
+ # foo
42
+ # bar
43
+ # baz
44
+ # EOS
45
+ # end
46
+ #
47
+ # def test_strip_heredoc_on_a_regular_indented_heredoc_with_blank_lines
48
+ # assert_equal "foo\n bar\n\nbaz\n", <<-EOS.strip_heredoc
49
+ # foo
50
+ # bar
51
+ #
52
+ # baz
53
+ # EOS
54
+ # end
55
+ #
56
+ # def test_pluralize
57
+ # SingularToPlural.each do |singular, plural|
58
+ # assert_equal(plural, singular.pluralize)
59
+ # end
60
+ #
61
+ # assert_equal("plurals", "plurals".pluralize)
62
+ #
63
+ # assert_equal("blargles", "blargle".pluralize(0))
64
+ # assert_equal("blargle", "blargle".pluralize(1))
65
+ # assert_equal("blargles", "blargle".pluralize(2))
66
+ # end
67
+ #
68
+ # def test_singularize
69
+ # SingularToPlural.each do |singular, plural|
70
+ # assert_equal(singular, plural.singularize)
71
+ # end
72
+ # end
73
+ #
74
+ # def test_titleize
75
+ # MixtureToTitleCase.each do |before, titleized|
76
+ # assert_equal(titleized, before.titleize)
77
+ # end
78
+ # end
79
+
80
+ def test_camelize
81
+ CamelToUnderscore.each do |camel, underscore|
82
+ assert_equal(camel, underscore.camelize)
83
+ end
84
+ end
85
+
86
+ def test_camelize_lower
87
+ assert_equal('capital', 'Capital'.camelize(:lower))
88
+ end
89
+
90
+ def test_dasherize
91
+ UnderscoresToDashes.each do |underscored, dasherized|
92
+ assert_equal(dasherized, underscored.dasherize)
93
+ end
94
+ end
95
+
96
+ def test_underscore
97
+ CamelToUnderscore.each do |camel, underscore|
98
+ assert_equal(underscore, camel.underscore)
99
+ end
100
+
101
+ assert_equal "html_tidy", "HTMLTidy".underscore
102
+ assert_equal "html_tidy_generator", "HTMLTidyGenerator".underscore
103
+ end
104
+
105
+ def test_underscore_to_lower_camel
106
+ UnderscoreToLowerCamel.each do |underscored, lower_camel|
107
+ assert_equal(lower_camel, underscored.camelize(:lower))
108
+ end
109
+ end
110
+
111
+ def test_demodulize
112
+ assert_equal "Account", "MyApplication::Billing::Account".demodulize
113
+ end
114
+
115
+ # def test_deconstantize
116
+ # assert_equal "MyApplication::Billing", "MyApplication::Billing::Account".deconstantize
117
+ # end
118
+ #
119
+ # def test_foreign_key
120
+ # ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key|
121
+ # assert_equal(foreign_key, klass.foreign_key)
122
+ # end
123
+ #
124
+ # ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key|
125
+ # assert_equal(foreign_key, klass.foreign_key(false))
126
+ # end
127
+ # end
128
+ #
129
+ # def test_tableize
130
+ # ClassNameToTableName.each do |class_name, table_name|
131
+ # assert_equal(table_name, class_name.tableize)
132
+ # end
133
+ # end
134
+ #
135
+ # def test_classify
136
+ # ClassNameToTableName.each do |class_name, table_name|
137
+ # assert_equal(class_name, table_name.classify)
138
+ # end
139
+ # end
140
+ #
141
+ # def test_string_parameterized_normal
142
+ # StringToParameterized.each do |normal, slugged|
143
+ # assert_equal(normal.parameterize, slugged)
144
+ # end
145
+ # end
146
+ #
147
+ # def test_string_parameterized_no_separator
148
+ # StringToParameterizeWithNoSeparator.each do |normal, slugged|
149
+ # assert_equal(normal.parameterize(''), slugged)
150
+ # end
151
+ # end
152
+ #
153
+ # def test_string_parameterized_underscore
154
+ # StringToParameterizeWithUnderscore.each do |normal, slugged|
155
+ # assert_equal(normal.parameterize('_'), slugged)
156
+ # end
157
+ # end
158
+ #
159
+ # def test_humanize
160
+ # UnderscoreToHuman.each do |underscore, human|
161
+ # assert_equal(human, underscore.humanize)
162
+ # end
163
+ # end
164
+ #
165
+ # def test_ord
166
+ # assert_equal 97, 'a'.ord
167
+ # assert_equal 97, 'abc'.ord
168
+ # end
169
+ #
170
+ # def test_access
171
+ # s = "hello"
172
+ # assert_equal "h", s.at(0)
173
+ #
174
+ # assert_equal "llo", s.from(2)
175
+ # assert_equal "hel", s.to(2)
176
+ #
177
+ # assert_equal "h", s.first
178
+ # assert_equal "he", s.first(2)
179
+ # assert_equal "", s.first(0)
180
+ #
181
+ # assert_equal "o", s.last
182
+ # assert_equal "llo", s.last(3)
183
+ # assert_equal "hello", s.last(10)
184
+ # assert_equal "", s.last(0)
185
+ #
186
+ # assert_equal 'x', 'x'.first
187
+ # assert_equal 'x', 'x'.first(4)
188
+ #
189
+ # assert_equal 'x', 'x'.last
190
+ # assert_equal 'x', 'x'.last(4)
191
+ # end
192
+ #
193
+ # def test_access_returns_a_real_string
194
+ # hash = {}
195
+ # hash["h"] = true
196
+ # hash["hello123".at(0)] = true
197
+ # assert_equal %w(h), hash.keys
198
+ #
199
+ # hash = {}
200
+ # hash["llo"] = true
201
+ # hash["hello".from(2)] = true
202
+ # assert_equal %w(llo), hash.keys
203
+ #
204
+ # hash = {}
205
+ # hash["hel"] = true
206
+ # hash["hello".to(2)] = true
207
+ # assert_equal %w(hel), hash.keys
208
+ #
209
+ # hash = {}
210
+ # hash["hello"] = true
211
+ # hash["123hello".last(5)] = true
212
+ # assert_equal %w(hello), hash.keys
213
+ #
214
+ # hash = {}
215
+ # hash["hello"] = true
216
+ # hash["hello123".first(5)] = true
217
+ # assert_equal %w(hello), hash.keys
218
+ # end
219
+ #
220
+ # def test_starts_ends_with_alias
221
+ # s = "hello"
222
+ # assert s.starts_with?('h')
223
+ # assert s.starts_with?('hel')
224
+ # assert !s.starts_with?('el')
225
+ #
226
+ # assert s.ends_with?('o')
227
+ # assert s.ends_with?('lo')
228
+ # assert !s.ends_with?('el')
229
+ # end
230
+ #
231
+ # def test_string_squish
232
+ # original = %{\u180E\u180E A string surrounded by unicode mongolian vowel separators,
233
+ # with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u180E\u180E}
234
+ #
235
+ # expected = "A string surrounded by unicode mongolian vowel separators, " +
236
+ # "with tabs( ), newlines( ), unicode nextlines( ) and many spaces( )."
237
+ #
238
+ # # Make sure squish returns what we expect:
239
+ # assert_equal original.squish, expected
240
+ # # But doesn't modify the original string:
241
+ # assert_not_equal original, expected
242
+ #
243
+ # # Make sure squish! returns what we expect:
244
+ # assert_equal original.squish!, expected
245
+ # # And changes the original string:
246
+ # assert_equal original, expected
247
+ # end
248
+ #
249
+ # def test_string_inquiry
250
+ # assert "production".inquiry.production?
251
+ # assert !"production".inquiry.development?
252
+ # end
253
+ #
254
+ # def test_truncate
255
+ # assert_equal "Hello World!", "Hello World!".truncate(12)
256
+ # assert_equal "Hello Wor...", "Hello World!!".truncate(12)
257
+ # end
258
+ #
259
+ # def test_truncate_with_omission_and_seperator
260
+ # assert_equal "Hello[...]", "Hello World!".truncate(10, :omission => "[...]")
261
+ # assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => ' ')
262
+ # assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => ' ')
263
+ # assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ')
264
+ # end
265
+ #
266
+ # def test_truncate_with_omission_and_regexp_seperator
267
+ # assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => /\s/)
268
+ # assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => /\s/)
269
+ # assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => /\s/)
270
+ # end
271
+ #
272
+ # def test_truncate_multibyte
273
+ # assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8),
274
+ # "\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(Encoding::UTF_8).truncate(10)
275
+ # end
276
+ #
277
+ # def test_truncate_should_not_be_html_safe
278
+ # assert !"Hello World!".truncate(12).html_safe?
279
+ # end
280
+ #
281
+ # def test_constantize
282
+ # run_constantize_tests_on do |string|
283
+ # string.constantize
284
+ # end
285
+ # end
286
+ #
287
+ # def test_safe_constantize
288
+ # run_safe_constantize_tests_on do |string|
289
+ # string.safe_constantize
290
+ # end
291
+ # end
292
+ end
293
+
294
+ # class StringConversionsTest < ActiveSupport::TestCase
295
+ # def test_string_to_time
296
+ # with_env_tz "Europe/Moscow" do
297
+ # assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:utc)
298
+ # assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time
299
+ # assert_equal Time.utc(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time(:utc)
300
+ # assert_equal Time.local(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time
301
+ # assert_equal Time.utc(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:utc)
302
+ # assert_equal Time.local(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time
303
+ # assert_equal Time.local(2011, 2, 27, 18, 50), "2011-02-27 13:50 -0100".to_time
304
+ # assert_equal Time.utc(2011, 2, 27, 23, 50), "2011-02-27 22:50 -0100".to_time(:utc)
305
+ # assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 14:50 -0500".to_time
306
+ # assert_nil "".to_time
307
+ # end
308
+ # end
309
+ #
310
+ # def test_string_to_time_utc_offset
311
+ # with_env_tz "US/Eastern" do
312
+ # assert_equal 0, "2005-02-27 23:50".to_time(:utc).utc_offset
313
+ # assert_equal(-18000, "2005-02-27 23:50".to_time.utc_offset)
314
+ # assert_equal 0, "2005-02-27 22:50 -0100".to_time(:utc).utc_offset
315
+ # assert_equal(-18000, "2005-02-27 22:50 -0100".to_time.utc_offset)
316
+ # end
317
+ # end
318
+ #
319
+ # def test_partial_string_to_time
320
+ # with_env_tz "Europe/Moscow" do
321
+ # now = Time.now
322
+ # assert_equal Time.local(now.year, now.month, now.day, 23, 50), "23:50".to_time
323
+ # assert_equal Time.utc(now.year, now.month, now.day, 23, 50), "23:50".to_time(:utc)
324
+ # assert_equal Time.local(now.year, now.month, now.day, 18, 50), "13:50 -0100".to_time
325
+ # assert_equal Time.utc(now.year, now.month, now.day, 23, 50), "22:50 -0100".to_time(:utc)
326
+ # end
327
+ # end
328
+ #
329
+ # def test_string_to_datetime
330
+ # assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime
331
+ # assert_equal 0, "2039-02-27 23:50".to_datetime.offset # use UTC offset
332
+ # assert_equal ::Date::ITALY, "2039-02-27 23:50".to_datetime.start # use Ruby's default start value
333
+ # assert_equal DateTime.civil(2039, 2, 27, 23, 50, 19 + Rational(275038, 1000000), "-04:00"), "2039-02-27T23:50:19.275038-04:00".to_datetime
334
+ # assert_nil "".to_datetime
335
+ # end
336
+ #
337
+ # def test_partial_string_to_datetime
338
+ # now = DateTime.now
339
+ # assert_equal DateTime.civil(now.year, now.month, now.day, 23, 50), "23:50".to_datetime
340
+ # assert_equal DateTime.civil(now.year, now.month, now.day, 23, 50, 0, "-04:00"), "23:50 -0400".to_datetime
341
+ # end
342
+ #
343
+ # def test_string_to_date
344
+ # assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date
345
+ # assert_nil "".to_date
346
+ # assert_equal Date.new(Date.today.year, 2, 3), "Feb 3rd".to_date
347
+ # end
348
+ #
349
+ # protected
350
+ # def with_env_tz(new_tz = 'US/Eastern')
351
+ # old_tz, ENV['TZ'] = ENV['TZ'], new_tz
352
+ # yield
353
+ # ensure
354
+ # old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
355
+ # end
356
+ # end
357
+ #
358
+ # class StringBehaviourTest < ActiveSupport::TestCase
359
+ # def test_acts_like_string
360
+ # assert 'Bambi'.acts_like_string?
361
+ # end
362
+ # end
363
+ #
364
+ # class CoreExtStringMultibyteTest < ActiveSupport::TestCase
365
+ # UTF8_STRING = 'こにちわ'
366
+ # ASCII_STRING = 'ohayo'.encode('US-ASCII')
367
+ # EUC_JP_STRING = 'さよなら'.encode('EUC-JP')
368
+ # INVALID_UTF8_STRING = "\270\236\010\210\245"
369
+ #
370
+ # def test_core_ext_adds_mb_chars
371
+ # assert_respond_to UTF8_STRING, :mb_chars
372
+ # end
373
+ #
374
+ # def test_string_should_recognize_utf8_strings
375
+ # assert UTF8_STRING.is_utf8?
376
+ # assert ASCII_STRING.is_utf8?
377
+ # assert !EUC_JP_STRING.is_utf8?
378
+ # assert !INVALID_UTF8_STRING.is_utf8?
379
+ # end
380
+ #
381
+ # def test_mb_chars_returns_instance_of_proxy_class
382
+ # assert_kind_of ActiveSupport::Multibyte.proxy_class, UTF8_STRING.mb_chars
383
+ # end
384
+ # end
385
+ #
386
+ # class OutputSafetyTest < ActiveSupport::TestCase
387
+ # def setup
388
+ # @string = "hello"
389
+ # @object = Class.new(Object) do
390
+ # def to_s
391
+ # "other"
392
+ # end
393
+ # end.new
394
+ # end
395
+ #
396
+ # test "A string is unsafe by default" do
397
+ # assert !@string.html_safe?
398
+ # end
399
+ #
400
+ # test "A string can be marked safe" do
401
+ # string = @string.html_safe
402
+ # assert string.html_safe?
403
+ # end
404
+ #
405
+ # test "Marking a string safe returns the string" do
406
+ # assert_equal @string, @string.html_safe
407
+ # end
408
+ #
409
+ # test "A fixnum is safe by default" do
410
+ # assert 5.html_safe?
411
+ # end
412
+ #
413
+ # test "a float is safe by default" do
414
+ # assert 5.7.html_safe?
415
+ # end
416
+ #
417
+ # test "An object is unsafe by default" do
418
+ # assert !@object.html_safe?
419
+ # end
420
+ #
421
+ # test "Adding an object to a safe string returns a safe string" do
422
+ # string = @string.html_safe
423
+ # string << @object
424
+ #
425
+ # assert_equal "helloother", string
426
+ # assert string.html_safe?
427
+ # end
428
+ #
429
+ # test "Adding a safe string to another safe string returns a safe string" do
430
+ # @other_string = "other".html_safe
431
+ # string = @string.html_safe
432
+ # @combination = @other_string + string
433
+ #
434
+ # assert_equal "otherhello", @combination
435
+ # assert @combination.html_safe?
436
+ # end
437
+ #
438
+ # test "Adding an unsafe string to a safe string escapes it and returns a safe string" do
439
+ # @other_string = "other".html_safe
440
+ # @combination = @other_string + "<foo>"
441
+ # @other_combination = @string + "<foo>"
442
+ #
443
+ # assert_equal "other&lt;foo&gt;", @combination
444
+ # assert_equal "hello<foo>", @other_combination
445
+ #
446
+ # assert @combination.html_safe?
447
+ # assert !@other_combination.html_safe?
448
+ # end
449
+ #
450
+ # test "Concatting safe onto unsafe yields unsafe" do
451
+ # @other_string = "other"
452
+ #
453
+ # string = @string.html_safe
454
+ # @other_string.concat(string)
455
+ # assert !@other_string.html_safe?
456
+ # end
457
+ #
458
+ # test "Concatting unsafe onto safe yields escaped safe" do
459
+ # @other_string = "other".html_safe
460
+ # string = @other_string.concat("<foo>")
461
+ # assert_equal "other&lt;foo&gt;", string
462
+ # assert string.html_safe?
463
+ # end
464
+ #
465
+ # test "Concatting safe onto safe yields safe" do
466
+ # @other_string = "other".html_safe
467
+ # string = @string.html_safe
468
+ #
469
+ # @other_string.concat(string)
470
+ # assert @other_string.html_safe?
471
+ # end
472
+ #
473
+ # test "Concatting safe onto unsafe with << yields unsafe" do
474
+ # @other_string = "other"
475
+ # string = @string.html_safe
476
+ #
477
+ # @other_string << string
478
+ # assert !@other_string.html_safe?
479
+ # end
480
+ #
481
+ # test "Concatting unsafe onto safe with << yields escaped safe" do
482
+ # @other_string = "other".html_safe
483
+ # string = @other_string << "<foo>"
484
+ # assert_equal "other&lt;foo&gt;", string
485
+ # assert string.html_safe?
486
+ # end
487
+ #
488
+ # test "Concatting safe onto safe with << yields safe" do
489
+ # @other_string = "other".html_safe
490
+ # string = @string.html_safe
491
+ #
492
+ # @other_string << string
493
+ # assert @other_string.html_safe?
494
+ # end
495
+ #
496
+ # test "Concatting safe onto unsafe with % yields unsafe" do
497
+ # @other_string = "other%s"
498
+ # string = @string.html_safe
499
+ #
500
+ # @other_string = @other_string % string
501
+ # assert !@other_string.html_safe?
502
+ # end
503
+ #
504
+ # test "Concatting unsafe onto safe with % yields escaped safe" do
505
+ # @other_string = "other%s".html_safe
506
+ # string = @other_string % "<foo>"
507
+ #
508
+ # assert_equal "other&lt;foo&gt;", string
509
+ # assert string.html_safe?
510
+ # end
511
+ #
512
+ # test "Concatting safe onto safe with % yields safe" do
513
+ # @other_string = "other%s".html_safe
514
+ # string = @string.html_safe
515
+ #
516
+ # @other_string = @other_string % string
517
+ # assert @other_string.html_safe?
518
+ # end
519
+ #
520
+ # test "Concatting with % doesn't modify a string" do
521
+ # @other_string = ["<p>", "<b>", "<h1>"]
522
+ # _ = "%s %s %s".html_safe % @other_string
523
+ #
524
+ # assert_equal ["<p>", "<b>", "<h1>"], @other_string
525
+ # end
526
+ #
527
+ # test "Concatting a fixnum to safe always yields safe" do
528
+ # string = @string.html_safe
529
+ # string = string.concat(13)
530
+ # assert_equal "hello".concat(13), string
531
+ # assert string.html_safe?
532
+ # end
533
+ #
534
+ # test 'emits normal string yaml' do
535
+ # assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1)
536
+ # end
537
+ #
538
+ # test 'knows whether it is encoding aware' do
539
+ # assert_deprecated do
540
+ # assert 'ruby'.encoding_aware?
541
+ # end
542
+ # end
543
+ #
544
+ # test "call to_param returns a normal string" do
545
+ # string = @string.html_safe
546
+ # assert string.html_safe?
547
+ # assert !string.to_param.html_safe?
548
+ # end
549
+ #
550
+ # test "ERB::Util.html_escape should escape unsafe characters" do
551
+ # string = '<>&"\''
552
+ # expected = '&lt;&gt;&amp;&quot;&#39;'
553
+ # assert_equal expected, ERB::Util.html_escape(string)
554
+ # end
555
+ #
556
+ # test "ERB::Util.html_escape should correctly handle invalid UTF-8 strings" do
557
+ # string = [192, 60].pack('CC')
558
+ # expected = 192.chr + "&lt;"
559
+ # assert_equal expected, ERB::Util.html_escape(string)
560
+ # end
561
+ #
562
+ # test "ERB::Util.html_escape should not escape safe strings" do
563
+ # string = "<b>hello</b>".html_safe
564
+ # assert_equal string, ERB::Util.html_escape(string)
565
+ # end
566
+ # end
567
+ #
568
+ # class StringExcludeTest < ActiveSupport::TestCase
569
+ # test 'inverse of #include' do
570
+ # assert_equal false, 'foo'.exclude?('o')
571
+ # assert_equal true, 'foo'.exclude?('p')
572
+ # end
573
+ # end
574
+ #
575
+ # class StringIndentTest < ActiveSupport::TestCase
576
+ # test 'does not indent strings that only contain newlines (edge cases)' do
577
+ # ['', "\n", "\n" * 7].each do |str|
578
+ # assert_nil str.indent!(8)
579
+ # assert_equal str, str.indent(8)
580
+ # assert_equal str, str.indent(1, "\t")
581
+ # end
582
+ # end
583
+ #
584
+ # test "by default, indents with spaces if the existing indentation uses them" do
585
+ # assert_equal " foo\n bar", "foo\n bar".indent(4)
586
+ # end
587
+ #
588
+ # test "by default, indents with tabs if the existing indentation uses them" do
589
+ # assert_equal "\tfoo\n\t\t\bar", "foo\n\t\bar".indent(1)
590
+ # end
591
+ #
592
+ # test "by default, indents with spaces as a fallback if there is no indentation" do
593
+ # assert_equal " foo\n bar\n baz", "foo\nbar\nbaz".indent(3)
594
+ # end
595
+ #
596
+ # # Nothing is said about existing indentation that mixes spaces and tabs, so
597
+ # # there is nothing to test.
598
+ #
599
+ # test 'uses the indent char if passed' do
600
+ # assert_equal <<EXPECTED, <<ACTUAL.indent(4, '.')
601
+ # .... def some_method(x, y)
602
+ # .... some_code
603
+ # .... end
604
+ # EXPECTED
605
+ # def some_method(x, y)
606
+ # some_code
607
+ # end
608
+ # ACTUAL
609
+ #
610
+ # assert_equal <<EXPECTED, <<ACTUAL.indent(2, '&nbsp;')
611
+ # &nbsp;&nbsp;&nbsp;&nbsp;def some_method(x, y)
612
+ # &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;some_code
613
+ # &nbsp;&nbsp;&nbsp;&nbsp;end
614
+ # EXPECTED
615
+ # &nbsp;&nbsp;def some_method(x, y)
616
+ # &nbsp;&nbsp;&nbsp;&nbsp;some_code
617
+ # &nbsp;&nbsp;end
618
+ # ACTUAL
619
+ # end
620
+ #
621
+ # test "does not indent blank lines by default" do
622
+ # assert_equal " foo\n\n bar", "foo\n\nbar".indent(1)
623
+ # end
624
+ #
625
+ # test 'indents blank lines if told so' do
626
+ # assert_equal " foo\n \n bar", "foo\n\nbar".indent(1, nil, true)
627
+ # end
628
+ # end