backports 3.11.4 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.rdoc +2 -0
  4. data/README.rdoc +28 -7
  5. data/Rakefile +15 -3
  6. data/backports.gemspec +7 -1
  7. data/default.mspec +6 -1
  8. data/lib/backports/1.9.1/string/codepoints.rb +1 -0
  9. data/lib/backports/2.1.0/enumerable/to_h.rb +2 -0
  10. data/lib/backports/2.5.0/string/undump.rb +65 -0
  11. data/lib/backports/2.6.0.rb +3 -0
  12. data/lib/backports/2.6.0/array.rb +3 -0
  13. data/lib/backports/2.6.0/array/difference.rb +5 -0
  14. data/lib/backports/2.6.0/array/to_h.rb +13 -0
  15. data/lib/backports/2.6.0/array/union.rb +5 -0
  16. data/lib/backports/2.6.0/enumerable.rb +3 -0
  17. data/lib/backports/2.6.0/enumerable/chain.rb +47 -0
  18. data/lib/backports/2.6.0/enumerable/to_h.rb +13 -0
  19. data/lib/backports/2.6.0/kernel.rb +3 -0
  20. data/lib/backports/2.6.0/kernel/then.rb +7 -0
  21. data/lib/backports/2.6.rb +2 -0
  22. data/lib/backports/version.rb +1 -1
  23. data/set_version/2.6.0.rb +1 -0
  24. data/spec/tags/1.8.7/core/array/to_h_spec.rb +3 -0
  25. data/spec/tags/1.8.7/core/enumerable/to_h_spec.rb +2 -0
  26. data/spec/tags/1.8.7/core/module/attr_spec.rb +1 -0
  27. data/spec/tags/1.9.1/core/hash/slice_spec.rb +1 -0
  28. data/spec/tags/1.9.1/core/module/attr_spec.rb +1 -0
  29. data/spec/tags/1.9.2/core/array/to_h_spec.rb +3 -0
  30. data/spec/tags/1.9.2/core/enumerable/to_h_spec.rb +2 -0
  31. data/spec/tags/1.9.2/core/hash/slice_spec.rb +1 -0
  32. data/spec/tags/1.9.2/core/kernel/then_spec.rb +1 -0
  33. data/spec/tags/1.9.3/core/hash/slice_spec.rb +1 -0
  34. data/spec/tags/2.0.0/core/array/to_h_spec.rb +3 -0
  35. data/spec/tags/2.0.0/core/enumerable/to_h_spec.rb +2 -0
  36. data/spec/tags/2.0.0/core/hash/slice_spec.rb +1 -0
  37. data/spec/tags/2.0.0/core/module/attr_spec.rb +1 -0
  38. data/spec/tags/2.1.0/core/array/union_spec.rb +1 -0
  39. data/spec/tags/2.1.0/core/hash/slice_spec.rb +1 -0
  40. data/spec/tags/2.1.0/core/module/attr_spec.rb +1 -0
  41. data/spec/tags/2.2.0/core/hash/slice_spec.rb +1 -0
  42. data/spec/tags/2.2.0/core/module/attr_spec.rb +1 -0
  43. data/spec/tags/2.3.0/core/hash/slice_spec.rb +1 -0
  44. data/spec/tags/2.3.0/core/module/attr_spec.rb +1 -0
  45. data/spec/tags/2.4.0/core/hash/slice_spec.rb +1 -0
  46. data/spec/tags/2.4.0/core/module/attr_spec.rb +1 -0
  47. data/test/_backport_guards_test.rb +5 -1
  48. metadata +75 -239
  49. data/spec/tags/1.8.6/core/argf/each_line_spec.rb +0 -6
  50. data/spec/tags/1.8.6/core/argf/each_spec.rb +0 -6
  51. data/spec/tags/1.8.6/core/argf/lines_spec.rb +0 -6
  52. data/spec/tags/1.8.6/core/array/bsearch_index_spec.rb +0 -1
  53. data/spec/tags/1.8.6/core/array/collect_spec.rb +0 -7
  54. data/spec/tags/1.8.6/core/array/rotate_spec.rb +0 -2
  55. data/spec/tags/1.8.6/core/array/uniq_spec.rb +0 -3
  56. data/spec/tags/1.8.6/core/complex/to_r_spec.rb +0 -3
  57. data/spec/tags/1.8.6/core/enumerable/each_entry_spec.rb +0 -1
  58. data/spec/tags/1.8.6/core/enumerator/next_spec.rb +0 -1
  59. data/spec/tags/1.8.6/core/env/to_h_spec.rb +0 -2
  60. data/spec/tags/1.8.6/core/file/join_spec.rb +0 -3
  61. data/spec/tags/1.8.6/core/file/lchmod_spec.rb +0 -2
  62. data/spec/tags/1.8.6/core/file/new_spec.rb +0 -2
  63. data/spec/tags/1.8.6/core/file/open_spec.rb +0 -13
  64. data/spec/tags/1.8.6/core/file/to_path_spec.rb +0 -1
  65. data/spec/tags/1.8.6/core/fixnum/fdiv_spec.rb +0 -1
  66. data/spec/tags/1.8.6/core/gc/stress_spec.rb +0 -2
  67. data/spec/tags/1.8.6/core/hash/assoc_spec.rb +0 -1
  68. data/spec/tags/1.8.6/core/hash/constructor_spec.rb +0 -3
  69. data/spec/tags/1.8.6/core/hash/default_proc_spec.rb +0 -3
  70. data/spec/tags/1.8.6/core/hash/delete_if_spec.rb +0 -1
  71. data/spec/tags/1.8.6/core/hash/each_pair_spec.rb +0 -1
  72. data/spec/tags/1.8.6/core/hash/eql_spec.rb +0 -3
  73. data/spec/tags/1.8.6/core/hash/hash_spec.rb +0 -3
  74. data/spec/tags/1.8.6/core/hash/keep_if_spec.rb +0 -2
  75. data/spec/tags/1.8.6/core/hash/rassoc_spec.rb +0 -1
  76. data/spec/tags/1.8.6/core/hash/reject_spec.rb +0 -2
  77. data/spec/tags/1.8.6/core/hash/select_spec.rb +0 -8
  78. data/spec/tags/1.8.6/core/hash/transform_values_spec.rb +0 -2
  79. data/spec/tags/1.8.6/core/integer/round_spec.rb +0 -2
  80. data/spec/tags/1.8.6/core/io/binread_spec.rb +0 -7
  81. data/spec/tags/1.8.6/core/io/chars_spec.rb +0 -1
  82. data/spec/tags/1.8.6/core/io/each_char_spec.rb +0 -1
  83. data/spec/tags/1.8.6/core/io/lines_spec.rb +0 -1
  84. data/spec/tags/1.8.6/core/io/open_spec.rb +0 -24
  85. data/spec/tags/1.8.6/core/io/ungetbyte_spec.rb +0 -4
  86. data/spec/tags/1.8.6/core/io/write_spec.rb +0 -5
  87. data/spec/tags/1.8.6/core/kernel/__callee___spec.rb +0 -6
  88. data/spec/tags/1.8.6/core/kernel/__method___spec.rb +0 -1
  89. data/spec/tags/1.8.6/core/kernel/define_singleton_method_spec.rb +0 -2
  90. data/spec/tags/1.8.6/core/kernel/public_method_spec.rb +0 -2
  91. data/spec/tags/1.8.6/core/kernel/require_relative_spec.rb +0 -3
  92. data/spec/tags/1.8.6/core/math/log2_spec.rb +0 -6
  93. data/spec/tags/1.8.6/core/math/log_spec.rb +0 -3
  94. data/spec/tags/1.8.6/core/module/class_exec_spec.rb +0 -2
  95. data/spec/tags/1.8.6/core/module/module_exec_spec.rb +0 -2
  96. data/spec/tags/1.8.6/core/numeric/step_spec.rb +0 -12
  97. data/spec/tags/1.8.6/core/proc/curry_spec.rb +0 -4
  98. data/spec/tags/1.8.6/core/range/step_spec.rb +0 -12
  99. data/spec/tags/1.8.6/core/string/getbyte_spec.rb +0 -6
  100. data/spec/tags/1.8.6/core/string/partition_spec.rb +0 -1
  101. data/spec/tags/1.8.6/core/string/prepend_spec.rb +0 -1
  102. data/spec/tags/1.8.6/core/string/rpartition_spec.rb +0 -1
  103. data/spec/tags/1.8.6/core/string/setbyte_spec.rb +0 -5
  104. data/spec/tags/1.8.6/core/string/uplus_spec.rb +0 -1
  105. data/spec/tags/1.8.6/core/string/upto_spec.rb +0 -1
  106. data/spec/tags/1.8.6/core/symbol/capitalize_spec.rb +0 -3
  107. data/spec/tags/1.8.6/core/symbol/comparison_spec.rb +0 -1
  108. data/spec/tags/1.8.6/core/symbol/downcase_spec.rb +0 -2
  109. data/spec/tags/1.8.6/core/symbol/element_reference_spec.rb +0 -4
  110. data/spec/tags/1.8.6/core/symbol/empty_spec.rb +0 -1
  111. data/spec/tags/1.8.6/core/symbol/match_spec.rb +0 -2
  112. data/spec/tags/1.8.6/core/symbol/swapcase_spec.rb +0 -2
  113. data/spec/tags/1.8.6/core/symbol/to_proc_spec.rb +0 -1
  114. data/spec/tags/1.8.6/core/symbol/upcase_spec.rb +0 -1
  115. data/spec/tags/1.8.7/core/array/bsearch_index_spec.rb +0 -1
  116. data/spec/tags/1.8.7/core/array/keep_if_spec.rb +0 -2
  117. data/spec/tags/1.8.7/core/array/rotate_spec.rb +0 -2
  118. data/spec/tags/1.8.7/core/array/select_spec.rb +0 -2
  119. data/spec/tags/1.8.7/core/array/uniq_spec.rb +0 -3
  120. data/spec/tags/1.8.7/core/complex/to_r_spec.rb +0 -3
  121. data/spec/tags/1.8.7/core/enumerable/collect_concat_spec.rb +0 -1
  122. data/spec/tags/1.8.7/core/enumerable/flat_map_spec.rb +0 -1
  123. data/spec/tags/1.8.7/core/env/to_h_spec.rb +0 -2
  124. data/spec/tags/1.8.7/core/file/lchmod_spec.rb +0 -2
  125. data/spec/tags/1.8.7/core/file/new_spec.rb +0 -1
  126. data/spec/tags/1.8.7/core/file/open_spec.rb +0 -5
  127. data/spec/tags/1.8.7/core/file/readlink_spec.rb +0 -6
  128. data/spec/tags/1.8.7/core/file/to_path_spec.rb +0 -1
  129. data/spec/tags/1.8.7/core/hash/assoc_spec.rb +0 -1
  130. data/spec/tags/1.8.7/core/hash/default_proc_spec.rb +0 -3
  131. data/spec/tags/1.8.7/core/hash/keep_if_spec.rb +0 -2
  132. data/spec/tags/1.8.7/core/hash/rassoc_spec.rb +0 -1
  133. data/spec/tags/1.8.7/core/hash/select_spec.rb +0 -1
  134. data/spec/tags/1.8.7/core/hash/transform_values_spec.rb +0 -2
  135. data/spec/tags/1.8.7/core/integer/round_spec.rb +0 -2
  136. data/spec/tags/1.8.7/core/io/binread_spec.rb +0 -7
  137. data/spec/tags/1.8.7/core/io/open_spec.rb +0 -32
  138. data/spec/tags/1.8.7/core/io/ungetbyte_spec.rb +0 -4
  139. data/spec/tags/1.8.7/core/io/write_spec.rb +0 -5
  140. data/spec/tags/1.8.7/core/kernel/__callee___spec.rb +0 -6
  141. data/spec/tags/1.8.7/core/kernel/define_singleton_method_spec.rb +0 -2
  142. data/spec/tags/1.8.7/core/kernel/public_method_spec.rb +0 -1
  143. data/spec/tags/1.8.7/core/kernel/require_relative_spec.rb +0 -3
  144. data/spec/tags/1.8.7/core/math/log2_spec.rb +0 -6
  145. data/spec/tags/1.8.7/core/math/log_spec.rb +0 -3
  146. data/spec/tags/1.8.7/core/module/include_spec.rb +0 -3
  147. data/spec/tags/1.8.7/core/proc/curry_spec.rb +0 -3
  148. data/spec/tags/1.8.7/core/proc/yield_spec.rb +0 -4
  149. data/spec/tags/1.8.7/core/range/size_spec.rb +0 -1
  150. data/spec/tags/1.8.7/core/string/getbyte_spec.rb +0 -5
  151. data/spec/tags/1.8.7/core/string/prepend_spec.rb +0 -1
  152. data/spec/tags/1.8.7/core/string/setbyte_spec.rb +0 -5
  153. data/spec/tags/1.8.7/core/string/uplus_spec.rb +0 -1
  154. data/spec/tags/1.8.7/core/symbol/capitalize_spec.rb +0 -3
  155. data/spec/tags/1.8.7/core/symbol/comparison_spec.rb +0 -1
  156. data/spec/tags/1.8.7/core/symbol/downcase_spec.rb +0 -2
  157. data/spec/tags/1.8.7/core/symbol/element_reference_spec.rb +0 -4
  158. data/spec/tags/1.8.7/core/symbol/empty_spec.rb +0 -1
  159. data/spec/tags/1.8.7/core/symbol/match_spec.rb +0 -2
  160. data/spec/tags/1.8.7/core/symbol/swapcase_spec.rb +0 -2
  161. data/spec/tags/1.8.7/core/symbol/upcase_spec.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 34204ecd79e022cc9d1096bfb9a5fe1258fe288d
4
- data.tar.gz: 8b91a3d894e3d6a7a846a411d133092855cdc360
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODRmY2Q4YmY5NzU5YTM0NzM3NjgwYTBkZWNiNTczM2JiM2FmNWZhYw==
5
+ data.tar.gz: !binary |-
6
+ OWFjNjgyNDQ5ZWM4MDMwYjUyYTUxYWI2MjJlZGQ2NWI1ZmMxOTI1Yg==
5
7
  SHA512:
6
- metadata.gz: da12841604ea64a39db7c6872981ff708180b8e0ad6b2c2185efeff54640cba276bdde9e2f7bad8e97f7b490be00d3c06ed5ea6a55592ba686c981865b0f7975
7
- data.tar.gz: 9d6c0ec16579891f0a6322e6da92316cf74c3e747f3b4de686ed22dd1ed212061fd6ee0d6cd0b6f9bc7640f1424094b7ef14b1c792b3ac9a083512eab184eab2
8
+ metadata.gz: !binary |-
9
+ ZTY4N2YzYzYzY2YzNTkxOWYzNTJmOWQ5ZmU5ZjZjYzA4ZWExNWMwOTMzODI5
10
+ ZmExMGEwNTdmZjk5OTRhMjhmNzMwNzMzYjViYjhhMzg3YWI3MjU5NzNlN2I2
11
+ YTZiZWRiYzVlZTFkNDJmM2FiMjIwZjEwODFmZGUwNzZkMjRlODQ=
12
+ data.tar.gz: !binary |-
13
+ NjI2ZjkzODNhNDZlMTRhYWVhYTkxYjNhYTVjMDQ2NTk0YjI0NzY0Yzg4OTky
14
+ MjRkM2VjNzgxZmUxYzQ4YmMyNWE2MTJiNmM1Njg4MTU1MmQ1YWExMzkyZmU1
15
+ Mzc4MmNmZDE1OTVmZmUzMGE5ODkwOGZmYjAyMWMxZDNmYmQyYjU=
@@ -8,6 +8,8 @@ rvm:
8
8
  - "2.2.0"
9
9
  - "2.3.0"
10
10
  - "2.4.0"
11
+ - "2.5.0"
12
+ - "2.6.0"
11
13
  - ruby-head
12
14
 
13
15
  # matrix:
@@ -1,5 +1,7 @@
1
1
  = Backports --- History
2
2
 
3
+ * From 2.5.0: <tt>String#undump</tt> (Note, much slower performances)
4
+
3
5
  == Version 3.11.0 - December 25th, 2017
4
6
 
5
7
  * New Ruby version 2.5.0
@@ -1,6 +1,6 @@
1
1
  = Backports Library {<img src="https://travis-ci.org/marcandre/backports.svg?branch=master">}[https://travis-ci.org/marcandre/backports] {<img src="https://badge.fury.io/rb/backports.svg" alt="Gem Version" />}[http://badge.fury.io/rb/backports]
2
2
 
3
- Yearning to use some of the new cool features in Ruby 2.5 while using 2.3.x? Have some legacy code in Ruby 1.8 but can't live without `flat_map`?
3
+ Yearning to use some of the new cool features in Ruby 2.6 while using 2.3.x? Have some legacy code in Ruby 1.8 but can't live without `flat_map`?
4
4
 
5
5
  This gem is for you!
6
6
 
@@ -75,6 +75,21 @@ Compatible with Ruby itself, JRuby and Rubinius.
75
75
 
76
76
  = Complete List of backports
77
77
 
78
+ == Ruby 2.6 backports
79
+
80
+ * Array
81
+ * +difference+, +union+
82
+ * +to_h+ (with block)
83
+
84
+ * Enumerable
85
+ * +chain+
86
+ * +to_h+ (with block)
87
+
88
+ * Enumerator::Chain (use Enumerable#chain)
89
+
90
+ * Kernel
91
+ * +then+
92
+
78
93
  == Ruby 2.5 backports
79
94
 
80
95
  * Array
@@ -97,6 +112,7 @@ Compatible with Ruby itself, JRuby and Rubinius.
97
112
  * String
98
113
  * +delete_prefix+, +delete_prefix!+
99
114
  * +delete_suffix+, +delete_suffix!+
115
+ * +undump+
100
116
  * Struct
101
117
  * +new+ (with <code>keyword_init: true</code>)
102
118
 
@@ -111,9 +127,9 @@ Compatible with Ruby itself, JRuby and Rubinius.
111
127
  * +compact+, +compact!+
112
128
  * +transform_values+, +transform_values!+
113
129
  * Regexp
114
- * +match?+ (slow)
130
+ * +match?+
115
131
  * String
116
- * +match?+ (slow)
132
+ * +match?+
117
133
  * FalseClass, Fixnum, Float, NilClass, TrueClass
118
134
  * +dup+
119
135
 
@@ -375,12 +391,17 @@ Thanks for the bug reports and patches, in particular the repeat offenders:
375
391
  * Konstantin Haase ( rkh[https://github.com/rkh])
376
392
  * Roger Pack ( rdp[http://github.com/rdp] )
377
393
 
378
- The best way to submit a patch is to also submit a patch to ruby/spec[https://github.com/ruby/spec] and then a patch to backports that make it pass the spec. To test rubyspec:
394
+ == Contributing
395
+
396
+ The best way to submit a patch is to also submit a patch to ruby/spec[https://github.com/ruby/spec] and then a patch to backports that make it pass the spec.
397
+
398
+ See below to test rubyspec. Note that only features missing from your Ruby version are tested.
379
399
 
380
400
  git submodule init && git submodule update # => pulls rubyspecs
381
- rake spec[array/bsearch] # => tests Array#bsearch
382
- rake spec[array/*] # => tests all backported Array methods
383
- rake spec (or rake spec[*/*]) # => all rubyspecs for backported methods
401
+ bundle install
402
+ bundle exec rake spec[hash/slice] # => tests Hash#slice (must be in Ruby 2.4 or less)
403
+ bundle exec rake spec[hash/*] # => tests all backported Hash methods
404
+ bundle exec rake spec (or rake spec[*/*]) # => all rubyspecs for backported methods
384
405
 
385
406
  Failures that are acceptable are added the to `tags` file.
386
407
 
data/Rakefile CHANGED
@@ -62,9 +62,15 @@ desc "Run specs, where path can be '*/*' (default), 'class/*' or 'class/method'.
62
62
  task :spec, :path, :action do |t, args|
63
63
  args.with_defaults(:path => '*/*', :action => 'ci')
64
64
  specs = SpecRunner.new
65
- mspec_cmds(args[:path], 'frozen_old_spec', args[:action]) do |cmd, path|
66
- specs.run(cmd, path)
65
+
66
+ # Avoid unclear error message by checking if at least one spec exists in the old specs
67
+ has_frozen_spec = !Dir.glob('frozen_old_spec/rubyspec/core/#{path}_spec.rb')
68
+ if has_frozen_spec || RUBY_VERSION < '1.9'
69
+ mspec_cmds(args[:path], 'frozen_old_spec', args[:action]) do |cmd, path|
70
+ specs.run(cmd, path)
71
+ end
67
72
  end
73
+
68
74
  unless RUBY_VERSION < '1.9' # Give up entirely on running new specs in 1.8.x, mainly because of {hash: 'syntax'}
69
75
  mspec_cmds(args[:path], 'spec', args[:action]) do |cmd, path|
70
76
  specs.run(cmd, path)
@@ -128,6 +134,7 @@ IGNORE_IN_19 = %w[
128
134
  2.1.0/enumerable/to_h
129
135
  2.1.0/array/to_h
130
136
  2.1.0/module/include
137
+ 2.2.0/kernel/itself
131
138
  2.5.0/module/define_method
132
139
  2.5.0/module/alias_method
133
140
  2.5.0/module/undef_method
@@ -150,6 +157,10 @@ CLASS_MAP = Hash.new{|k, v| k[v] = v}.merge!(
150
157
  'nil_class' => 'nil'
151
158
  )
152
159
 
160
+ EXTRA_SPECS = {
161
+ 'enumerable/chain' => %w[enumerator/chain/*]
162
+ }
163
+
153
164
  def mspec_cmds(pattern, spec_folder, action='ci')
154
165
  pattern = "lib/backports/*.*.*/#{pattern}.rb"
155
166
  Dir.glob(pattern) do |lib_path|
@@ -166,12 +177,13 @@ def mspec_cmds(pattern, spec_folder, action='ci')
166
177
  deps = [*DEPENDENCIES[version_path]].map{|p| "-r #{p}"}.join(' ')
167
178
  klass, method = path.split('/')
168
179
  path = [CLASS_MAP[klass], method].join('/')
180
+ spec_paths = [path, *EXTRA_SPECS[path]].map {|p| "#{spec_folder}/rubyspec/core/#{p}_spec.rb" }
169
181
  yield %W[mspec #{action}
170
182
  -I lib
171
183
  -r ./set_version/#{version}
172
184
  #{deps}
173
185
  -r backports/#{version_path}
174
- #{spec_folder}/rubyspec/core/#{path}_spec.rb
186
+ #{spec_paths.join(' ')}
175
187
  ].join(' '), path
176
188
  end
177
189
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Backports::VERSION
9
9
  gem.authors = ["Marc-André Lafortune"]
10
10
  gem.email = ["github@marc-andre.ca"]
11
- gem.description = %q{Essential backports that enable many of the nice features of Ruby 1.8.7 up to 2.1.0 for earlier versions.}
11
+ gem.description = %q{Essential backports that enable many of the nice features of Ruby for earlier versions.}
12
12
  gem.summary = %q{Backports of Ruby features for older Ruby.}
13
13
  gem.homepage = "http://github.com/marcandre/backports"
14
14
  gem.license = "MIT"
@@ -17,4 +17,10 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
+
21
+ if gem.respond_to?(:metadata)
22
+ gem.metadata['changelog_uri'] = 'https://github.com/marcandre/backports/blob/master/CHANGELOG.rdoc'
23
+ gem.metadata['source_code_uri'] = 'https://github.com/marcandre/backports'
24
+ gem.metadata['bug_tracker_uri'] = 'https://github.com/marcandre/backports/issues'
25
+ end
20
26
  end
@@ -2,7 +2,12 @@ if (Backports::TARGET_VERSION rescue false) # Conf loaded at different times, no
2
2
  class MSpecScript
3
3
  # The set of substitutions to transform a spec filename
4
4
  # into a tag filename.
5
- set :tags_patterns, [ [%r(rubyspec/), "tags/#{RUBY_VERSION}/"] ]
5
+ main_version = RUBY_VERSION
6
+ unless File.exist?(File.expand_path("../lib/backports/#{main_version}.rb", __FILE__))
7
+ main_version = main_version.sub(/\.\d+$/, '.0')
8
+ end
9
+
10
+ set :tags_patterns, [ [%r(rubyspec/), "tags/#{main_version}/"] ]
6
11
  end
7
12
 
8
13
  SpecGuard.ruby_version_override = Backports::TARGET_VERSION if Backports::TARGET_VERSION > RUBY_VERSION
@@ -3,6 +3,7 @@ unless String.method_defined? :codepoints
3
3
  def codepoints
4
4
  return to_enum(:codepoints) unless block_given?
5
5
  unpack("U*").each{|cp| yield cp}
6
+ self
6
7
  end
7
8
  end
8
9
  end
@@ -1,5 +1,7 @@
1
1
  unless Enumerable.method_defined?(:to_h)
2
2
  require 'backports/tools/arguments'
3
+ require 'backports/1.9.2/enumerable/each_entry'
4
+
3
5
  module Enumerable
4
6
  def to_h(*args)
5
7
  h = {}
@@ -0,0 +1,65 @@
1
+ unless String.method_defined? :undump
2
+ class String
3
+ def undump
4
+ # Making sure to return a String and not a subclass
5
+ string = to_s
6
+ raise 'string contains null byte' if string["\0"]
7
+ raise 'non-ASCII character detected' unless string.ascii_only?
8
+
9
+ #raise '.force_encoding("...") format is not supported by backports' if string.match(/\A".*"\.force_encoding\("[^"]*"\)\z/)
10
+ match = string.match(/\A(".*?"?)(?:\.force_encoding\("([^"]*)"\))?\z/)
11
+ if match
12
+ string = match[1]
13
+ encoding = match[2]
14
+ else
15
+ raise %(invalid dumped string; not wrapped with '"' nor '"...".force_encoding("...")' form)
16
+ end
17
+
18
+ # Ruby 1.9.3 does weird things to encoding during gsub
19
+ encoding ||= string.encoding.to_s
20
+
21
+ # Unescaped have an even number of backslashes in front of them
22
+ # because the double-quote is included, the unescaped quotes are where the size is odd
23
+ nb_unescaped_quote = string.scan(/\\*"/).select { |s| s.size.odd? }.size
24
+
25
+ raise 'unterminated dumped string' if nb_unescaped_quote == 1
26
+
27
+ if string[-1] != '"' || nb_unescaped_quote > 2
28
+ raise %(invalid dumped string; not wrapped with '"' nor '"...".force_encoding("...")' form)
29
+ end
30
+
31
+ string = string[1...-1]
32
+
33
+ if RUBY_VERSION >= '1.9'
34
+ # Look-arounds are not supported in ruby 1.8. Using a string with Regexp avoids the SyntaxError in 1.8.7
35
+ # \xY, \x3Y and finishing with \x
36
+ regex = Regexp.new("(?<!\\)(?:\\\\)*\\x(?![0-9a-f]{2})".gsub('\\', '\\\\\\\\'), Regexp::IGNORECASE)
37
+ raise 'invalid hex escape' if string[regex]
38
+ end
39
+
40
+ # The real #undump ignores the \C, \c and \M escapes
41
+ # Code injection is avoided by:
42
+ # * only allowing \u to have {}, so \\\\#{injection} will not eval the injection
43
+ # * only allowing the first character after the \\ to not be alpha/num/space, so \\\\#@inst_var_access is ignored
44
+ # To reduce the number of calls to eval a little, we wrap everything in a (...)+ so that consecutive escapes are
45
+ # handled at the same time.
46
+ result = string.gsub(/(\\+(u\{[\w ]+\}|[^cCM][\w]*))+/) do |s|
47
+ begin
48
+ eval("\"#{s}\"")
49
+ rescue SyntaxError => e
50
+ raise RuntimeError, e.message, e.backtrace
51
+ end
52
+ end
53
+
54
+ if encoding
55
+ begin
56
+ Encoding.find(encoding)
57
+ rescue ArgumentError
58
+ raise "dumped string has unknown encoding name"
59
+ end
60
+ result = result.force_encoding(encoding)
61
+ end
62
+ result
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ # require this file to load all the backports up to Ruby 2.5
2
+ require 'backports/2.5'
3
+ Backports.require_relative_dir
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def difference(*arrays)
3
+ arrays.inject(Array.new(self), :-)
4
+ end unless method_defined? :difference
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'backports/2.1.0/array/to_h' unless Array.method_defined? :to_h
2
+
3
+ if [[:need, true]].to_h { [:need, false] } [:need]
4
+ require 'backports/tools/alias_method_chain'
5
+
6
+ class Array
7
+ def to_h_with_block(&block)
8
+ receiver = block ? map(&block) : self
9
+ receiver.to_h_without_block
10
+ end
11
+ Backports.alias_method_chain self, :to_h, :block
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def union(*arrays)
3
+ [self, *arrays].inject([], :|)
4
+ end unless method_defined? :union
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,47 @@
1
+ unless Enumerable.method_defined? :chain
2
+ module Enumerable
3
+ def chain(*enums)
4
+ Enumerator::Chain.new(self, *enums)
5
+ end
6
+ end
7
+
8
+ Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # For 1.8.x
9
+
10
+ class Enumerator::Chain < Enumerator
11
+ def initialize(*enums)
12
+ @enums = enums
13
+ @rewindable = -1
14
+ self
15
+ end
16
+
17
+ def each(*args, &block)
18
+ @enums.each_with_index do |enum, i|
19
+ @rewindable = i
20
+ enum.each(*args, &block)
21
+ end
22
+ end
23
+
24
+ def size
25
+ sum = 0
26
+ @enums.each do |enum|
27
+ s = enum.size
28
+ return s if s == nil || s == Float::INFINITY
29
+ sum += s
30
+ end
31
+ sum
32
+ end
33
+
34
+ def inspect
35
+ detail = @enums.map(&:inspect).join(', ')
36
+ "#<Enumerator::Chain: [#{detail}]>"
37
+ end
38
+
39
+ def rewind
40
+ @rewindable.downto(0) do |i|
41
+ enum = @enums[i]
42
+ enum.rewind if enum.respond_to? :rewind
43
+ end
44
+ self
45
+ end
46
+ end unless Enumerator.const_defined? :Chain
47
+ end
@@ -0,0 +1,13 @@
1
+ require 'backports/2.1.0/enumerable/to_h' unless Enumerable.method_defined? :to_h
2
+
3
+ if Enumerable.instance_method(:to_h).bind([[:need, true]]).call { [:need, false] } [:need]
4
+ require 'backports/tools/alias_method_chain'
5
+
6
+ module Enumerable
7
+ def to_h_with_block(*args, &block)
8
+ return to_h_without_block(*args) unless block
9
+ map(*args, &block).to_h_without_block
10
+ end
11
+ Backports.alias_method_chain self, :to_h, :block
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,7 @@
1
+ unless Kernel.method_defined? :then
2
+ require 'backports/2.5.0/kernel/yield_self'
3
+
4
+ module Kernel
5
+ alias_method :then, :yield_self
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ # require this file to load all the backports of Ruby 2.4 and below
2
+ require 'backports/2.6.0'
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.11.4" unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.12.0" unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
3
3
  end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/setter")
@@ -0,0 +1,3 @@
1
+ fails:Array#to_h with block raises ArgumentError if block returns longer or shorter array
2
+ fails:Array#to_h with block raises TypeError if block returns something other than Array
3
+ fails:Array#to_h with block does not coerce returned pair to Array with #to_a
@@ -0,0 +1,2 @@
1
+ fails:Enumerable#to_h with block raises TypeError if block returns something other than Array
2
+ fails:Enumerable#to_h with block does not coerce returned pair to Array with #to_a
@@ -0,0 +1 @@
1
+ fails:Module#attr with a boolean argument emits a warning when $VERBOSE is true
@@ -0,0 +1 @@
1
+ fails:Hash#slice uses the regular Hash#[] method, even on subclasses that override it
@@ -0,0 +1 @@
1
+ fails:Module#attr with a boolean argument emits a warning when $VERBOSE is true
@@ -0,0 +1,3 @@
1
+ fails:Array#to_h with block raises ArgumentError if block returns longer or shorter array
2
+ fails:Array#to_h with block raises TypeError if block returns something other than Array
3
+ fails:Array#to_h with block does not coerce returned pair to Array with #to_a
@@ -0,0 +1,2 @@
1
+ fails:Enumerable#to_h with block raises TypeError if block returns something other than Array
2
+ fails:Enumerable#to_h with block does not coerce returned pair to Array with #to_a
@@ -0,0 +1 @@
1
+ fails:Hash#slice uses the regular Hash#[] method, even on subclasses that override it
@@ -0,0 +1 @@
1
+ fails:Kernel#then returns a sized Enumerator when no block given