motion_blender-support 0.2.7

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 (182) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +4 -0
  5. data/HACKS.md +7 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +359 -0
  8. data/Rakefile +14 -0
  9. data/app/app_delegate.rb +5 -0
  10. data/examples/Inflector/.gitignore +16 -0
  11. data/examples/Inflector/Gemfile +5 -0
  12. data/examples/Inflector/Rakefile +13 -0
  13. data/examples/Inflector/app/app_delegate.rb +8 -0
  14. data/examples/Inflector/app/inflections.rb +5 -0
  15. data/examples/Inflector/app/inflector_view_controller.rb +109 -0
  16. data/examples/Inflector/app/words_view_controller.rb +101 -0
  17. data/examples/Inflector/resources/Default-568h@2x.png +0 -0
  18. data/examples/Inflector/spec/main_spec.rb +9 -0
  19. data/lib/motion-support/callbacks.rb +8 -0
  20. data/lib/motion-support/concern.rb +4 -0
  21. data/lib/motion-support/core_ext/array.rb +10 -0
  22. data/lib/motion-support/core_ext/class.rb +5 -0
  23. data/lib/motion-support/core_ext/hash.rb +13 -0
  24. data/lib/motion-support/core_ext/integer.rb +6 -0
  25. data/lib/motion-support/core_ext/module.rb +11 -0
  26. data/lib/motion-support/core_ext/numeric.rb +6 -0
  27. data/lib/motion-support/core_ext/object.rb +12 -0
  28. data/lib/motion-support/core_ext/range.rb +5 -0
  29. data/lib/motion-support/core_ext/string.rb +13 -0
  30. data/lib/motion-support/core_ext/time.rb +16 -0
  31. data/lib/motion-support/core_ext.rb +13 -0
  32. data/lib/motion-support/inflector.rb +8 -0
  33. data/lib/motion-support.rb +81 -0
  34. data/motion/_stdlib/array.rb +13 -0
  35. data/motion/_stdlib/cgi.rb +22 -0
  36. data/motion/_stdlib/date.rb +81 -0
  37. data/motion/_stdlib/enumerable.rb +9 -0
  38. data/motion/_stdlib/time.rb +19 -0
  39. data/motion/callbacks.rb +511 -0
  40. data/motion/concern.rb +122 -0
  41. data/motion/core_ext/array/access.rb +28 -0
  42. data/motion/core_ext/array/conversions.rb +86 -0
  43. data/motion/core_ext/array/extract_options.rb +11 -0
  44. data/motion/core_ext/array/grouping.rb +99 -0
  45. data/motion/core_ext/array/prepend_and_append.rb +7 -0
  46. data/motion/core_ext/array/wrap.rb +45 -0
  47. data/motion/core_ext/array.rb +19 -0
  48. data/motion/core_ext/class/attribute.rb +119 -0
  49. data/motion/core_ext/class/attribute_accessors.rb +168 -0
  50. data/motion/core_ext/date/acts_like.rb +8 -0
  51. data/motion/core_ext/date/calculations.rb +117 -0
  52. data/motion/core_ext/date/conversions.rb +56 -0
  53. data/motion/core_ext/date_and_time/calculations.rb +232 -0
  54. data/motion/core_ext/enumerable.rb +90 -0
  55. data/motion/core_ext/hash/deep_delete_if.rb +23 -0
  56. data/motion/core_ext/hash/deep_merge.rb +27 -0
  57. data/motion/core_ext/hash/except.rb +15 -0
  58. data/motion/core_ext/hash/indifferent_access.rb +19 -0
  59. data/motion/core_ext/hash/keys.rb +150 -0
  60. data/motion/core_ext/hash/reverse_merge.rb +22 -0
  61. data/motion/core_ext/hash/slice.rb +40 -0
  62. data/motion/core_ext/integer/inflections.rb +27 -0
  63. data/motion/core_ext/integer/multiple.rb +10 -0
  64. data/motion/core_ext/integer/time.rb +41 -0
  65. data/motion/core_ext/kernel/singleton_class.rb +6 -0
  66. data/motion/core_ext/metaclass.rb +8 -0
  67. data/motion/core_ext/module/aliasing.rb +69 -0
  68. data/motion/core_ext/module/anonymous.rb +19 -0
  69. data/motion/core_ext/module/attr_internal.rb +38 -0
  70. data/motion/core_ext/module/attribute_accessors.rb +64 -0
  71. data/motion/core_ext/module/delegation.rb +175 -0
  72. data/motion/core_ext/module/introspection.rb +60 -0
  73. data/motion/core_ext/module/reachable.rb +5 -0
  74. data/motion/core_ext/module/remove_method.rb +12 -0
  75. data/motion/core_ext/ns_dictionary.rb +14 -0
  76. data/motion/core_ext/ns_string.rb +14 -0
  77. data/motion/core_ext/numeric/bytes.rb +44 -0
  78. data/motion/core_ext/numeric/conversions.rb +49 -0
  79. data/motion/core_ext/numeric/time.rb +75 -0
  80. data/motion/core_ext/object/acts_like.rb +10 -0
  81. data/motion/core_ext/object/blank.rb +105 -0
  82. data/motion/core_ext/object/deep_dup.rb +44 -0
  83. data/motion/core_ext/object/duplicable.rb +87 -0
  84. data/motion/core_ext/object/inclusion.rb +15 -0
  85. data/motion/core_ext/object/instance_variables.rb +28 -0
  86. data/motion/core_ext/object/to_param.rb +58 -0
  87. data/motion/core_ext/object/to_query.rb +26 -0
  88. data/motion/core_ext/object/try.rb +78 -0
  89. data/motion/core_ext/range/include_range.rb +23 -0
  90. data/motion/core_ext/range/overlaps.rb +8 -0
  91. data/motion/core_ext/regexp.rb +5 -0
  92. data/motion/core_ext/string/access.rb +104 -0
  93. data/motion/core_ext/string/behavior.rb +6 -0
  94. data/motion/core_ext/string/exclude.rb +11 -0
  95. data/motion/core_ext/string/filters.rb +55 -0
  96. data/motion/core_ext/string/indent.rb +43 -0
  97. data/motion/core_ext/string/inflections.rb +178 -0
  98. data/motion/core_ext/string/starts_ends_with.rb +4 -0
  99. data/motion/core_ext/string/strip.rb +24 -0
  100. data/motion/core_ext/time/acts_like.rb +8 -0
  101. data/motion/core_ext/time/calculations.rb +215 -0
  102. data/motion/core_ext/time/conversions.rb +52 -0
  103. data/motion/descendants_tracker.rb +50 -0
  104. data/motion/duration.rb +104 -0
  105. data/motion/hash_with_indifferent_access.rb +253 -0
  106. data/motion/inflections.rb +67 -0
  107. data/motion/inflector/inflections.rb +203 -0
  108. data/motion/inflector/methods.rb +321 -0
  109. data/motion/logger.rb +47 -0
  110. data/motion/number_helper.rb +54 -0
  111. data/motion/version.rb +3 -0
  112. data/motion_blender-support.gemspec +21 -0
  113. data/spec/motion-support/_helpers/constantize_test_cases.rb +75 -0
  114. data/spec/motion-support/_helpers/inflector_test_cases.rb +270 -0
  115. data/spec/motion-support/callback_spec.rb +702 -0
  116. data/spec/motion-support/concern_spec.rb +93 -0
  117. data/spec/motion-support/core_ext/array/access_spec.rb +29 -0
  118. data/spec/motion-support/core_ext/array/conversion_spec.rb +60 -0
  119. data/spec/motion-support/core_ext/array/extract_options_spec.rb +15 -0
  120. data/spec/motion-support/core_ext/array/grouping_spec.rb +85 -0
  121. data/spec/motion-support/core_ext/array/prepend_and_append_spec.rb +25 -0
  122. data/spec/motion-support/core_ext/array/wrap_spec.rb +19 -0
  123. data/spec/motion-support/core_ext/array_spec.rb +16 -0
  124. data/spec/motion-support/core_ext/class/attribute_accessor_spec.rb +127 -0
  125. data/spec/motion-support/core_ext/class/attribute_spec.rb +92 -0
  126. data/spec/motion-support/core_ext/date/acts_like_spec.rb +11 -0
  127. data/spec/motion-support/core_ext/date/calculation_spec.rb +186 -0
  128. data/spec/motion-support/core_ext/date/conversion_spec.rb +18 -0
  129. data/spec/motion-support/core_ext/date_and_time/calculation_spec.rb +336 -0
  130. data/spec/motion-support/core_ext/enumerable_spec.rb +130 -0
  131. data/spec/motion-support/core_ext/hash/deep_delete_if_spec.rb +19 -0
  132. data/spec/motion-support/core_ext/hash/deep_merge_spec.rb +32 -0
  133. data/spec/motion-support/core_ext/hash/except_spec.rb +43 -0
  134. data/spec/motion-support/core_ext/hash/key_spec.rb +236 -0
  135. data/spec/motion-support/core_ext/hash/reverse_merge_spec.rb +26 -0
  136. data/spec/motion-support/core_ext/hash/slice_spec.rb +61 -0
  137. data/spec/motion-support/core_ext/integer/inflection_spec.rb +23 -0
  138. data/spec/motion-support/core_ext/integer/multiple_spec.rb +19 -0
  139. data/spec/motion-support/core_ext/kernel/singleton_class_spec.rb +9 -0
  140. data/spec/motion-support/core_ext/metaclass_spec.rb +9 -0
  141. data/spec/motion-support/core_ext/module/aliasing_spec.rb +143 -0
  142. data/spec/motion-support/core_ext/module/anonymous_spec.rb +29 -0
  143. data/spec/motion-support/core_ext/module/attr_internal_spec.rb +104 -0
  144. data/spec/motion-support/core_ext/module/attribute_accessor_spec.rb +86 -0
  145. data/spec/motion-support/core_ext/module/delegation_spec.rb +136 -0
  146. data/spec/motion-support/core_ext/module/introspection_spec.rb +70 -0
  147. data/spec/motion-support/core_ext/module/reachable_spec.rb +61 -0
  148. data/spec/motion-support/core_ext/module/remove_method_spec.rb +25 -0
  149. data/spec/motion-support/core_ext/numeric/bytes_spec.rb +43 -0
  150. data/spec/motion-support/core_ext/numeric/conversions_spec.rb +40 -0
  151. data/spec/motion-support/core_ext/object/acts_like_spec.rb +21 -0
  152. data/spec/motion-support/core_ext/object/blank_spec.rb +54 -0
  153. data/spec/motion-support/core_ext/object/deep_dup_spec.rb +54 -0
  154. data/spec/motion-support/core_ext/object/duplicable_spec.rb +31 -0
  155. data/spec/motion-support/core_ext/object/inclusion_spec.rb +34 -0
  156. data/spec/motion-support/core_ext/object/instance_variable_spec.rb +19 -0
  157. data/spec/motion-support/core_ext/object/to_param_spec.rb +75 -0
  158. data/spec/motion-support/core_ext/object/to_query_spec.rb +37 -0
  159. data/spec/motion-support/core_ext/object/try_spec.rb +92 -0
  160. data/spec/motion-support/core_ext/range/include_range_spec.rb +31 -0
  161. data/spec/motion-support/core_ext/range/overlap_spec.rb +43 -0
  162. data/spec/motion-support/core_ext/regexp_spec.rb +7 -0
  163. data/spec/motion-support/core_ext/string/access_spec.rb +53 -0
  164. data/spec/motion-support/core_ext/string/behavior_spec.rb +7 -0
  165. data/spec/motion-support/core_ext/string/exclude_spec.rb +8 -0
  166. data/spec/motion-support/core_ext/string/filter_spec.rb +49 -0
  167. data/spec/motion-support/core_ext/string/indent_spec.rb +56 -0
  168. data/spec/motion-support/core_ext/string/inflection_spec.rb +142 -0
  169. data/spec/motion-support/core_ext/string/starts_end_with_spec.rb +14 -0
  170. data/spec/motion-support/core_ext/string/strip_spec.rb +34 -0
  171. data/spec/motion-support/core_ext/string_spec.rb +88 -0
  172. data/spec/motion-support/core_ext/time/acts_like_spec.rb +11 -0
  173. data/spec/motion-support/core_ext/time/calculation_spec.rb +201 -0
  174. data/spec/motion-support/core_ext/time/conversion_spec.rb +53 -0
  175. data/spec/motion-support/descendants_tracker_spec.rb +58 -0
  176. data/spec/motion-support/duration_spec.rb +107 -0
  177. data/spec/motion-support/hash_with_indifferent_access_spec.rb +605 -0
  178. data/spec/motion-support/inflector_spec.rb +504 -0
  179. data/spec/motion-support/ns_dictionary_spec.rb +89 -0
  180. data/spec/motion-support/ns_string_spec.rb +182 -0
  181. data/spec/motion-support/number_helper_spec.rb +55 -0
  182. metadata +352 -0
@@ -0,0 +1,31 @@
1
+ describe "duplicable?" do
2
+ before do
3
+ @raise_dup = [nil, false, true, :symbol, 1, 2.3, 5.seconds, BigDecimal.new('4.56')]
4
+ @yes = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new]
5
+ @no = []
6
+ end
7
+
8
+ it "should return false for non-duplicable objects" do
9
+ (@raise_dup + @no).each do |v|
10
+ v.should.not.be.duplicable
11
+ end
12
+ end
13
+
14
+ it "should return true for duplicable objects" do
15
+ @yes.each do |v|
16
+ v.should.be.duplicable
17
+ end
18
+ end
19
+
20
+ it "should not raise when dupping duplicable objects" do
21
+ (@yes + @no).each do |v|
22
+ lambda { v.dup }.should.not.raise
23
+ end
24
+ end
25
+
26
+ it "should raise when dupping non-duplicable objects" do
27
+ @raise_dup.each do |v|
28
+ lambda { v.dup }.should.raise TypeError
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ class LifeUniverseAndEverything
2
+ def include?(obj)
3
+ obj == 42
4
+ end
5
+ end
6
+
7
+
8
+ describe 'array' do
9
+ describe "in?" do
10
+ it "should support arrays" do
11
+ 1.in?([1,2,3]).should == true
12
+ 0.in?([1,2,3]).should == false
13
+ end
14
+
15
+ it "should support hashes" do
16
+ :a.in?({a:1,b:2,c:3}).should == true
17
+ 1.in?({a:1,b:2,c:3}).should == false
18
+ end
19
+
20
+ it "should support ranges" do
21
+ 1.in?(1..3).should == true
22
+ 0.in?(1..3).should == false
23
+ end
24
+
25
+ it "should support strings" do
26
+ 'a'.in?("apple").should == true
27
+ end
28
+
29
+ it "should support anything that implements `include?`" do
30
+ 42.in?(LifeUniverseAndEverything.new).should == true
31
+ 0.in?(LifeUniverseAndEverything.new).should == false
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ describe "Object" do
2
+ before do
3
+ @source = Object.new
4
+ @source.instance_variable_set(:@bar, 'bar')
5
+ @source.instance_variable_set(:@baz, 'baz')
6
+ end
7
+
8
+ describe "instance_variable_names" do
9
+ it "should return all instance variable names" do
10
+ @source.instance_variable_names.sort.should == %w(@bar @baz)
11
+ end
12
+ end
13
+
14
+ describe "instance_values" do
15
+ it "should return the values of all instance variables as a hash" do
16
+ @source.instance_values.should == {'bar' => 'bar', 'baz' => 'baz'}
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ class ArrayToParam < String
2
+ def to_param
3
+ "#{self}1"
4
+ end
5
+ end
6
+
7
+ class HashToParam < String
8
+ def to_param
9
+ "#{self}-1"
10
+ end
11
+ end
12
+
13
+ describe "to_param" do
14
+ describe "object" do
15
+ it "should delegate to to_s" do
16
+ foo = Object.new
17
+ def foo.to_s; 'foo' end
18
+ foo.to_param.should == 'foo'
19
+ end
20
+ end
21
+
22
+ describe "nil" do
23
+ it "should return self" do
24
+ nil.to_param.should == nil
25
+ end
26
+ end
27
+
28
+ describe "true, false" do
29
+ it "should return self" do
30
+ true.to_param.should == true
31
+ false.to_param.should == false
32
+ end
33
+ end
34
+
35
+ describe "array" do
36
+ it "should convert string array" do
37
+ %w().to_param.should == ''
38
+ %w(hello world).to_param.should == 'hello/world'
39
+ %w(hello 10).to_param.should == 'hello/10'
40
+ end
41
+
42
+ it "should convert number array" do
43
+ [10, 20].to_param.should == '10/20'
44
+ end
45
+
46
+ it "should convert custom object array" do
47
+ [ArrayToParam.new('custom'), ArrayToParam.new('param')].to_param.should == 'custom1/param1'
48
+ end
49
+ end
50
+
51
+ describe "hash" do
52
+ it "should convert a string hash" do
53
+ {}.to_param.should == ''
54
+ { :hello => "world" }.to_param.should == 'hello=world'
55
+ { "hello" => 10 }.to_param.should == 'hello=10'
56
+ {:hello => "world", "say_bye" => true}.to_param.should == 'hello=world&say_bye=true'
57
+ end
58
+
59
+ it "should convert a number hash" do
60
+ {10 => 20, 30 => 40, 50 => 60}.to_param.should == '10=20&30=40&50=60'
61
+ end
62
+
63
+ it "should convert an object hash" do
64
+ {HashToParam.new('custom') => HashToParam.new('param'), HashToParam.new('custom2') => HashToParam.new('param2')}.to_param.should == 'custom-1=param-1&custom2-1=param2-1'
65
+ end
66
+
67
+ it "should escape keys and values" do
68
+ { 'param 1' => 'A string with / characters & that should be ? escaped' }.to_param.should == 'param+1=A+string+with+%2F+characters+%26+that+should+be+%3F+escaped'
69
+ end
70
+
71
+ it "should order keys in ascending order" do
72
+ Hash[*%w(b 1 c 0 a 2)].to_param.should == 'a=2&b=1&c=0'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,37 @@
1
+ class Should
2
+ def equal_query(query)
3
+ @object.to_query.split('&').should == query.split('&')
4
+ end
5
+ end
6
+
7
+ describe "to_query" do
8
+ it "should do a simple converion" do
9
+ { :a => 10 }.should.equal_query 'a=10'
10
+ end
11
+
12
+ it "should escape for CGI" do
13
+ { 'a:b' => 'c d' }.should.equal_query 'a%3Ab=c+d'
14
+ end
15
+
16
+ it "should work with nil parameter value" do
17
+ empty = Object.new
18
+ def empty.to_param; nil end
19
+ { 'a' => empty }.should.equal_query 'a='
20
+ end
21
+
22
+ it "should do a nested conversion" do
23
+ { :person => Hash[:login, 'seckar', :name, 'Nicholas'] }.should.equal_query 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas'
24
+ end
25
+
26
+ it "should do a multiply nested query" do
27
+ Hash[:account, {:person => {:id => 20}}, :person, {:id => 10}].should.equal_query 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10'
28
+ end
29
+
30
+ it "should work with array values" do
31
+ { :person => {:id => [10, 20]} }.should.equal_query 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20'
32
+ end
33
+
34
+ it "should not sort array values" do
35
+ { :person => {:id => [20, 10]} }.should.equal_query 'person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10'
36
+ end
37
+ end
@@ -0,0 +1,92 @@
1
+ describe "Object" do
2
+ before do
3
+ @string = "Hello"
4
+ end
5
+
6
+ describe "try" do
7
+ it "should return nil for nonexisting method" do
8
+ method = :undefined_method
9
+ @string.should.not.respond_to method
10
+ @string.try(method).should.be.nil
11
+ end
12
+
13
+ it "should return nil for nonexisting method with arguments" do
14
+ method = :undefined_method
15
+ @string.should.not.respond_to method
16
+ @string.try(method, 'llo', 'y').should.be.nil
17
+ end
18
+
19
+ it "should delegate to existing method" do
20
+ @string.try(:size).should == 5
21
+ end
22
+
23
+ it "should forward arguments to existing method" do
24
+ @string.try(:sub, 'llo', 'y').should == 'Hey'
25
+ end
26
+
27
+ it "should forward block to existing method" do
28
+ @string.try(:sub, 'llo') { |match| 'y' }.should == 'Hey'
29
+ end
30
+
31
+ it "should return nil when called on nil even if method is defined on nil" do
32
+ nil.try(:to_s).should.be.nil
33
+ nil.try(:to_i).should.be.nil
34
+ end
35
+
36
+ it "should work as expected on false" do
37
+ false.try(:to_s).should == 'false'
38
+ end
39
+
40
+ it "should pass existing receiver to block" do
41
+ @string.try { |s| s.reverse }.should == @string.reverse
42
+ end
43
+
44
+ it "should not pass nil to block" do
45
+ ran = false
46
+ nil.try { ran = true }
47
+ ran.should == false
48
+ end
49
+
50
+ it "should not call private method" do
51
+ klass = Class.new do
52
+ private
53
+
54
+ def private_method
55
+ 'private method'
56
+ end
57
+ end
58
+
59
+ klass.new.try(:private_method).should == nil
60
+ end
61
+ end
62
+
63
+ describe "try!" do
64
+ it "should raise error for nonexisting method" do
65
+ method = :undefined_method
66
+ @string.should.not.respond_to method
67
+ lambda { @string.try!(method) }.should.raise NoMethodError
68
+ end
69
+
70
+ it "should raise error for nonexisting method with arguments" do
71
+ method = :undefined_method
72
+ @string.should.not.respond_to method
73
+ lambda { @string.try!(method, 'llo', 'y') }.should.raise NoMethodError
74
+ end
75
+
76
+ it "should pass existing receiver to block" do
77
+ @string.try! { |s| s.reverse }.should == @string.reverse
78
+ end
79
+
80
+ it "should raise error when calling private method" do
81
+ klass = Class.new do
82
+ private
83
+
84
+ def private_method
85
+ 'private method'
86
+ end
87
+ end
88
+
89
+ lambda { klass.new.try!(:private_method) }.should.raise NoMethodError
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,31 @@
1
+ describe "Range" do
2
+ describe "include?" do
3
+ it "should should include identical inclusive" do
4
+ (1..10).should.include(1..10)
5
+ end
6
+
7
+ it "should should include identical exclusive" do
8
+ (1...10).should.include(1...10)
9
+ end
10
+
11
+ it "should should include other with exlusive end" do
12
+ (1..10).should.include(1...10)
13
+ end
14
+
15
+ it "should exclusive end should not include identical with inclusive end" do
16
+ (1...10).should.not.include(1..10)
17
+ end
18
+
19
+ it "should should not include overlapping first" do
20
+ (2..8).should.not.include(1..3)
21
+ end
22
+
23
+ it "should should not include overlapping last" do
24
+ (2..8).should.not.include(5..9)
25
+ end
26
+
27
+ it "should should include identical exclusive with floats" do
28
+ (1.0...10.0).should.include(1.0...10.0)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ describe "Range" do
2
+ describe "overlaps?" do
3
+ it "should overlaps last inclusive" do
4
+ (1..5).overlaps?(5..10).should.be.true
5
+ end
6
+
7
+ it "should overlaps last exclusive" do
8
+ (1...5).overlaps?(5..10).should.be.false
9
+ end
10
+
11
+ it "should overlaps first inclusive" do
12
+ (5..10).overlaps?(1..5).should.be.true
13
+ end
14
+
15
+ it "should overlaps first exclusive" do
16
+ (5..10).overlaps?(1...5).should.be.false
17
+ end
18
+
19
+ it "should should compare identical inclusive" do
20
+ ((1..10) === (1..10)).should.be.true
21
+ end
22
+
23
+ it "should should compare identical exclusive" do
24
+ ((1...10) === (1...10)).should.be.true
25
+ end
26
+
27
+ it "should should compare other with exlusive end" do
28
+ ((1..10) === (1...10)).should.be.true
29
+ end
30
+
31
+ it "should overlaps on time" do
32
+ time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
33
+ time_range_2 = Time.utc(2005, 12, 10, 17, 00)..Time.utc(2005, 12, 10, 18, 00)
34
+ time_range_1.overlaps?(time_range_2).should.be.true
35
+ end
36
+
37
+ it "should no overlaps on time" do
38
+ time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
39
+ time_range_2 = Time.utc(2005, 12, 10, 17, 31)..Time.utc(2005, 12, 10, 18, 00)
40
+ time_range_1.overlaps?(time_range_2).should.be.false
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ describe "Regexp" do
2
+ it "should find out if regexp is multiline" do
3
+ //m.multiline?.should.be.true
4
+ //.multiline?.should.be.false
5
+ /(?m:)/.multiline?.should.be.false
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ describe "String" do
2
+ describe "access" do
3
+ it "should access" do
4
+ s = "hello"
5
+ s.at(0).should == "h"
6
+
7
+ s.from(2).should == "llo"
8
+ s.to(2).should == "hel"
9
+
10
+ s.first.should == "h"
11
+ s.first(2).should == "he"
12
+ s.first(0).should == ""
13
+
14
+ s.last.should == "o"
15
+ s.last(3).should == "llo"
16
+ s.last(10).should == "hello"
17
+ s.last(0).should == ""
18
+
19
+ 'x'.first.should == 'x'
20
+ 'x'.first(4).should == 'x'
21
+
22
+ 'x'.last.should == 'x'
23
+ 'x'.last(4).should == 'x'
24
+ end
25
+
26
+ it "should access returns a real string" do
27
+ hash = {}
28
+ hash["h"] = true
29
+ hash["hello123".at(0)] = true
30
+ hash.keys.should == %w(h)
31
+
32
+ hash = {}
33
+ hash["llo"] = true
34
+ hash["hello".from(2)] = true
35
+ hash.keys.should == %w(llo)
36
+
37
+ hash = {}
38
+ hash["hel"] = true
39
+ hash["hello".to(2)] = true
40
+ hash.keys.should == %w(hel)
41
+
42
+ hash = {}
43
+ hash["hello"] = true
44
+ hash["123hello".last(5)] = true
45
+ hash.keys.should == %w(hello)
46
+
47
+ hash = {}
48
+ hash["hello"] = true
49
+ hash["hello123".first(5)] = true
50
+ hash.keys.should == %w(hello)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ describe "String" do
2
+ describe "behavior" do
3
+ it "should acts like string" do
4
+ 'Bambi'.acts_like_string?.should == true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ describe "String" do
2
+ describe "exclude?" do
3
+ it "should be the inverse of #include" do
4
+ 'foo'.exclude?('o').should.be.false
5
+ 'foo'.exclude?('p').should.be.true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+ describe "String" do
2
+ describe "filters" do
3
+ describe "squish" do
4
+ before do
5
+ @original = %{\u180E\u180E A string surrounded by unicode mongolian vowel separators,
6
+ with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u180E\u180E}
7
+ @original.gsub!(/\u180E/, '') # mongolian vowel separators does not match [[:space:]]
8
+
9
+ @expected = "A string surrounded by unicode mongolian vowel separators, " +
10
+ "with tabs( ), newlines( ), unicode nextlines( ) and many spaces( )."
11
+ end
12
+
13
+ it "should squish string" do
14
+ @original.squish.should == @expected
15
+ @original.should.not == @expected
16
+ end
17
+
18
+ it "should squish! string" do
19
+ @original.squish!.should == @expected
20
+ @original.should == @expected
21
+ end
22
+ end
23
+
24
+ describe "truncate" do
25
+ it "should truncate string" do
26
+ "Hello World!".truncate(12).should == "Hello World!"
27
+ "Hello World!!".truncate(12).should == "Hello Wor..."
28
+ end
29
+
30
+ it "should truncate with omission and seperator" do
31
+ "Hello World!".truncate(10, :omission => "[...]").should == "Hello[...]"
32
+ "Hello Big World!".truncate(13, :omission => "[...]", :separator => ' ').should == "Hello[...]"
33
+ "Hello Big World!".truncate(14, :omission => "[...]", :separator => ' ').should == "Hello Big[...]"
34
+ "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ').should == "Hello Big[...]"
35
+ end
36
+
37
+ it "should truncate with omission and regexp seperator" do
38
+ "Hello Big World!".truncate(13, :omission => "[...]", :separator => /\s/).should == "Hello[...]"
39
+ "Hello Big World!".truncate(14, :omission => "[...]", :separator => /\s/).should == "Hello Big[...]"
40
+ "Hello Big World!".truncate(15, :omission => "[...]", :separator => /\s/).should == "Hello Big[...]"
41
+ end
42
+
43
+ it "should truncate multibyte" do
44
+ "\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).should ==
45
+ "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,56 @@
1
+ describe "String" do
2
+ describe "indent" do
3
+ it "should not indent strings that only contain newlines (edge cases)" do
4
+ ['', "\n", "\n" * 7].each do |str|
5
+ str.indent!(8).should.be.nil
6
+ str.indent(8).should == str
7
+ str.indent(1, "\t").should == str
8
+ end
9
+ end
10
+
11
+ it "should indent by default with spaces if the existing indentation uses them" do
12
+ "foo\n bar".indent(4).should == " foo\n bar"
13
+ end
14
+
15
+ it "should indent by default with tabs if the existing indentation uses them" do
16
+ "foo\n\t\bar".indent(1).should == "\tfoo\n\t\t\bar"
17
+ end
18
+
19
+ it "should indent by default with spaces as a fallback if there is no indentation" do
20
+ "foo\nbar\nbaz".indent(3).should == " foo\n bar\n baz"
21
+ end
22
+
23
+ # Nothing is said about existing indentation that mixes spaces and tabs, so
24
+ # there is nothing to test.
25
+
26
+ it "should use the indent char if passed" do
27
+ <<ACTUAL.indent(4, '.').should == <<EXPECTED
28
+ def some_method(x, y)
29
+ some_code
30
+ end
31
+ ACTUAL
32
+ .... def some_method(x, y)
33
+ .... some_code
34
+ .... end
35
+ EXPECTED
36
+
37
+ <<ACTUAL.indent(2, '&nbsp;').should == <<EXPECTED
38
+ &nbsp;&nbsp;def some_method(x, y)
39
+ &nbsp;&nbsp;&nbsp;&nbsp;some_code
40
+ &nbsp;&nbsp;end
41
+ ACTUAL
42
+ &nbsp;&nbsp;&nbsp;&nbsp;def some_method(x, y)
43
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;some_code
44
+ &nbsp;&nbsp;&nbsp;&nbsp;end
45
+ EXPECTED
46
+ end
47
+
48
+ it "should not indent blank lines by default" do
49
+ "foo\n\nbar".indent(1).should == " foo\n\n bar"
50
+ end
51
+
52
+ it "should indent blank lines if told so" do
53
+ "foo\n\nbar".indent(1, nil, true).should == " foo\n \n bar"
54
+ end
55
+ end
56
+ end