backports 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.6"
4
+ - "1.8.7"
5
+ - "1.9.2"
6
+ - "1.9.3"
7
+ - "2.0.0"
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - rbx-18mode
11
+ - rbx-19mode
12
+
13
+ bundle exec rake test
data/README.rdoc CHANGED
@@ -67,6 +67,7 @@ Additionally, the following Ruby 1.9 features have been backported:
67
67
 
68
68
  * Enumerable
69
69
  * +each_with_object+
70
+ * +each_with_index+ (with arguments)
70
71
 
71
72
  * Enumerator
72
73
  * +new+ (with block)
@@ -57,17 +57,6 @@ module Enumerable
57
57
  ary
58
58
  end unless method_defined? :drop_while
59
59
 
60
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
61
- if instance_method(:each_with_index).arity.zero?
62
- def each_with_index_with_optional_args_and_block(*args)
63
- return to_enum(:each_with_index, *args) unless block_given?
64
- idx = 0
65
- each(*args) { |o| yield(o, idx); idx += 1 }
66
- self
67
- end
68
- Backports.alias_method_chain self, :each_with_index, :optional_args_and_block
69
- end
70
-
71
60
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
72
61
  def find_index(obj = Backports::Undefined)
73
62
  if obj != Backports::Undefined
@@ -1,7 +1,7 @@
1
1
  class Regexp
2
2
  # Standard in Ruby 1.8.7+. See official documentation[http://www.ruby-doc.org/core-1.8.7/classes/Regexp.html]
3
- class << self
4
- unless (union(%w(a b)) rescue false)
3
+ unless (union(%w(a b)) rescue false)
4
+ class << self
5
5
  def union_with_array_argument(*arg)
6
6
  return union_without_array_argument(*arg) unless arg.size == 1
7
7
  union_without_array_argument(*arg.first)
@@ -9,4 +9,4 @@ class Regexp
9
9
  Backports.alias_method_chain self, :union, :array_argument
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -79,7 +79,7 @@ class String
79
79
  end unless method_defined? :start_with?
80
80
 
81
81
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
82
- unless ("abc".upto("def", true) rescue false)
82
+ unless ("abc".upto("def", true){} rescue false)
83
83
  def upto_with_exclusive(to, excl=false)
84
84
  return upto_without_exclusive(to){|s| yield s} if block_given? && !excl
85
85
  enum = Range.new(self, to, excl).to_enum
@@ -1,8 +1,19 @@
1
1
  module Enumerable
2
- # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
2
+ # Standard in Ruby 1.9.1. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
3
3
  def each_with_object(memo)
4
4
  return to_enum(:each_with_object, memo) unless block_given?
5
5
  each {|obj| yield obj, memo}
6
6
  memo
7
7
  end unless method_defined? :each_with_object
8
- end
8
+
9
+ # Standard in Ruby 1.9.1. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
10
+ if instance_method(:each_with_index).arity.zero?
11
+ def each_with_index_with_optional_args_and_block(*args)
12
+ return to_enum(:each_with_index, *args) unless block_given?
13
+ idx = 0
14
+ each(*args) { |o| yield(o, idx); idx += 1 }
15
+ self
16
+ end
17
+ Backports.alias_method_chain self, :each_with_index, :optional_args_and_block
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  module Math
2
- class << self
2
+ unless (log(2, 2) rescue false)
3
3
  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
4
- unless (log(2, 2) rescue false)
4
+ class << self
5
5
  def log_with_optional_base(numeric, base = Backports::Undefined)
6
6
  if base.equal?(Backports::Undefined)
7
7
  # Math.log(n) in 1.9.1 no longer accepts string arguments as it
@@ -15,11 +15,11 @@ module Math
15
15
  end
16
16
  end
17
17
  Backports.alias_method_chain self, :log, :optional_base
18
- end
19
18
 
20
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
21
- def log2(numeric)
22
- log(numeric, 2)
23
- end unless method_defined? :log2
19
+ # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
20
+ def log2(numeric)
21
+ log(numeric, 2)
22
+ end unless method_defined? :log2
23
+ end
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  end
@@ -14,24 +14,24 @@ module Kernel
14
14
  end
15
15
  end
16
16
 
17
- require 'matrix'
17
+ require 'set'
18
18
  require File.expand_path(File.dirname(__FILE__) + "/test_helper")
19
19
 
20
20
  class StdLibLoadingTest < Test::Unit::TestCase
21
21
  def test_load_correctly_after_requiring_backports
22
- path = File.expand_path("../../lib/backports/1.9.2/stdlib/set.rb", __FILE__)
22
+ path = File.expand_path("../../lib/backports/1.9.2/stdlib/matrix.rb", __FILE__)
23
23
  assert_equal false, $LOADED_FEATURES.include?(path)
24
- assert_equal true, require('set')
25
- assert_equal true, $bogus.include?("set")
24
+ assert_equal true, require('matrix')
25
+ assert_equal true, $bogus.include?("matrix")
26
26
  assert_equal true, $LOADED_FEATURES.include?(path)
27
- assert_equal false, require('set')
27
+ assert_equal false, require('matrix')
28
28
  end
29
29
 
30
30
  def test_load_correctly_before_requiring_backports_test
31
- assert_equal true, $bogus.include?("matrix")
32
- path = File.expand_path("../../lib/backports/1.9.2/stdlib/matrix.rb", __FILE__)
31
+ assert_equal true, $bogus.include?("set")
32
+ path = File.expand_path("../../lib/backports/1.9.2/stdlib/set.rb", __FILE__)
33
33
  assert_equal true, $LOADED_FEATURES.include?(path)
34
- assert_equal false, require('matrix')
34
+ assert_equal false, require('set')
35
35
  end
36
36
 
37
37
  def test_not_interfere_for_libraries_without_backports_test
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+
3
+ class TestBackport < Test::Unit::TestCase
4
+
5
+ def class_signature(klass)
6
+ Hash[
7
+ klass.instance_methods.map{|m| [m, klass.instance_method(m)] } +
8
+ klass.methods.map{|m| [".#{m}", klass.method(m) ]}
9
+ ]
10
+ end
11
+
12
+ CLASSES = [Array, Binding, Dir, Enumerable, Fixnum, Float, GC,
13
+ Hash, Integer, IO, Kernel, Math, MatchData, Method, Module, Numeric,
14
+ ObjectSpace, Proc, Process, Range, Regexp, String, Struct, Symbol] +
15
+ [ENV, ARGF].map{|obj| class << obj; self; end }
16
+
17
+ case RUBY_VERSION
18
+ when '1.8.6'
19
+ when '1.8.7'
20
+ CLASSES << Enumerable::Enumerator
21
+ else
22
+ CLASSES << Enumerator
23
+ end
24
+
25
+ def digest
26
+ Hash[
27
+ CLASSES.map { |klass| [klass, class_signature(klass)] }
28
+ ]
29
+ end
30
+
31
+ def digest_delta(before, after)
32
+ delta = {}
33
+ before.each do |klass, methods|
34
+ compare = after[klass]
35
+ d = methods.map do |name, unbound|
36
+ name unless unbound == compare[name]
37
+ end
38
+ d.compact!
39
+ delta[klass] = d unless d.empty?
40
+ end
41
+ delta unless delta.empty?
42
+ end
43
+
44
+ def test_backports_wont_override_unnecessarily
45
+ before = digest
46
+ require "./lib/backports/#{RUBY_VERSION}"
47
+ after = digest
48
+ assert_nil digest_delta(before, after)
49
+ end
50
+ end
51
+
data/test/test_lazy.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # This is copied & modified from MRI
2
2
  require 'test/unit'
3
3
  #require_relative 'envutil'
4
+ require './lib/backports'
4
5
 
5
6
  class TestLazyEnumerator < Test::Unit::TestCase
6
7
  class Step
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -22,6 +22,7 @@ files:
22
22
  - .document
23
23
  - .gitignore
24
24
  - .irbrc
25
+ - .travis.yml
25
26
  - CHANGELOG.rdoc
26
27
  - LICENSE.txt
27
28
  - README.rdoc
@@ -129,6 +130,7 @@ files:
129
130
  - lib/backports/version.rb
130
131
  - test/README
131
132
  - test/std_lib_loading_test.rb
133
+ - test/test__me_first.rb
132
134
  - test/test_helper.rb
133
135
  - test/test_lazy.rb
134
136
  - test/test_socket_interaction.rb
@@ -159,7 +161,7 @@ summary: Backports of Ruby features for older Ruby.
159
161
  test_files:
160
162
  - test/README
161
163
  - test/std_lib_loading_test.rb
164
+ - test/test__me_first.rb
162
165
  - test/test_helper.rb
163
166
  - test/test_lazy.rb
164
167
  - test/test_socket_interaction.rb
165
- has_rdoc: