Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing obsolete tests and update README

  • Loading branch information...
commit 881cbbd21fe59c2d39e174baaa3511f28eb45fd1 1 parent 84bc1e2
@marcandre authored
View
13 test/README
@@ -0,0 +1,13 @@
+Backports should be run against RubySpec. Check https://github.com/rubyspec/rubyspec for installation instructions.
+
+Use the `--unguarded` option to run all specs, including those of versions higher than the current Ruby. Use the `-r` option to require backports.
+
+For example:
+
+ cd YOUR_PATH_TO/rubyspec
+ rvm use 1.8.7
+ mspec core/range/cover_spec.rb --unguarded -r YOUR_PATH_TO/backports/lib/backports
+
+This will run the specs for Range#cover for Ruby 1.8.7 after loading backports.
+
+You need to check which tests fail to decide if it's OK that they do or not. For example it is to be expected that specs checking for encoding behavior will fail, as backports does not support the Ruby 1.9 encoding functionality.
View
1  test/_README
@@ -1 +0,0 @@
-As backports should be ran against RubySpec, tests should ideally be added to RubySpec instead of here...
View
82 test/array_test.rb
@@ -1,82 +0,0 @@
-require 'test_helper'
-
-class ArrayTest < Test::Unit::TestCase
- context "Array" do
- context "#combination" do
- should "conform to doc" do
- a = [ "a", "b", "c" ]
- assert_equal [["a"], ["b"], ["c"]], a.combination(1).to_a
- assert_equal [["a", "b"], ["a", "c"], ["b", "c"]], a.combination(2).to_a
- assert_equal [["a", "b", "c"]], a.combination(3).to_a
- assert_equal [], a.combination(4).to_a
- end
- end
-
- context "#flatten" do
- should "conform to doc" do
- s = [ 1, 2, 3 ]
- t = [ 4, 5, 6, [7, 8] ]
- a = [ s, t, 9, 10 ]
- assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], a.flatten
- a = [ 1, 2, [3, [4, 5] ] ]
- assert_equal [1, 2, 3, [4, 5]], a.flatten(1)
- end
- end
-
- context "#index" do
- should "conform to doc" do
- a = [ "a", "b", "c" ]
- assert_equal 1, a.index("b")
- assert_equal nil, a.index("z")
- assert_equal 1, a.index{|x|x=="b"}
- end
- end
-
- context "#reverse_each" do
- should "return an enumerator when no block is given" do
- assert_equal [4,3,2], [1,2,3,4].reverse_each.take(3)
- end
- end
-
- context "#pop" do
- should "conform to doc" do
- a = %w{ f r a b j o u s }
- assert_equal "s", a.pop
- assert_equal ["f", "r", "a", "b", "j", "o", "u"] , a
- assert_equal ["j", "o", "u"], a.pop(3)
- assert_equal ["f", "r", "a", "b"] , a
- end
- end
-
- context "#product" do
- should "conform to doc" do
- assert_equal [[1, 3], [1, 4], [2, 3], [2, 4]], [1, 2].product([3, 4])
- assert_equal [[1, 3, 5], [1, 4, 5], [2, 3, 5], [2, 4, 5]], [1, 2].product([3, 4], [5])
- assert_equal [[1], [2]], [1, 2].product
- end
- end
-
- context "#sample" do
- should "conform to doc" do
- assert_equal nil, [].sample
- assert_equal [], [].sample(5)
- assert_equal 42, [42].sample
- assert_equal [42], [42].sample(5)
- a = [ :foo, :bar, 42 ]
- s = a.sample(2)
- assert_equal 2, s.size
- assert_equal 1, (a-s).size
- assert_equal [], a-(0..20).sum{a.sample(2)}
- end
- end
-
- context "#shift" do
- should "conform to doc" do
- args = [ "-m", "-q", "-v", "filename" ]
- assert_equal "-m", args.shift
- assert_equal ["-q", "-v"], args.shift(2)
- assert_equal ["filename"], args
- end
- end
- end
-end
View
71 test/basic_object_test.rb
@@ -1,71 +0,0 @@
-require 'test_helper'
-require 'backports/basic_object'
-
-class BasicObjectTest < Test::Unit::TestCase
- context "BasicObject" do
- should "do it's best to keep stuff undefined" do
- # written in one big test because sequence matters
- # and defining classes / methods can't really be undone
-
- size = BasicObject.instance_methods.size
- assert size <= 7
-
- class Subclass < BasicObject
- def foo
- :bar
- end
- end
-
- assert_equal size + 1, Subclass.instance_methods.size
-
- module ::Kernel
- def bar
- :foo
- end
- end
-
- assert Subclass.method_defined?(:bar) if RUBY_VERSION < '1.9' # for now
-
- class ForceCleanup < Subclass
- end
-
- assert !Subclass.method_defined?(:bar) # should be cleaned up
-
- module SomeExtension
- def foo
- 42
- end
- end
-
- class ::Object
- include SomeExtension
- end
-
- class ForceCleanupAgain < Subclass
- end
-
- # puts BasicObject.instance_methods - BasicObject.instance_methods(false)
- # puts BasicObject.instance_method(:foo).owner
- # puts SomeExtension <= Object
- assert Subclass.method_defined?(:foo) # should not be cleaned up!
- assert !BasicObject.method_defined?(:foo) # but BasicObject should have been cleaned up!
-
- class BasicObject
- def last_case
- 1.0/0
- end
- end
-
- module SomeExtension
- def last_case
- 0
- end
- end
-
- class ForceCleanupForTheLastTime < BasicObject
- end
-
- assert BasicObject.method_defined?(:last_case)
- end
- end
-end
View
20 test/binding_test.rb
@@ -1,20 +0,0 @@
-require 'test_helper'
-
-class BindingTest < Test::Unit::TestCase
- class Demo
- def initialize(n)
- @secret = n
- end
- def get_binding
- return binding()
- end
- end
-
- context "Binding" do
- context "#eval" do
- should "conform to doc" do
- assert_equal 99, Demo.new(99).get_binding.eval("@secret")
- end
- end
- end
-end
View
244 test/enumerable_test.rb
@@ -1,244 +0,0 @@
-require 'test_helper'
-require 'stringio'
-
-class EnumerableTest < Test::Unit::TestCase
- context "Enumerable" do
- context "#count" do
- should "conform to doc" do
- assert_equal 4, (1..4).count
- assert_equal 1, (1..4).count(3)
- assert_equal 2, (1..4).count{|obj| obj > 2 }
- end
- end
-
- context "#cycle" do
- should "conform to doc" do
- assert_equal ["a", "b", "c", "a", "b", "c"], ('a'..'c').cycle(2).to_a
- end
- end
-
- context "#drop" do
- should "conform to doc" do
- assert_equal [5, 8, 13], [ 1, 1, 2, 3, 5, 8, 13 ].drop(4)
- assert_equal [], [ 1, 1, 2, 3, 5, 8, 13 ].drop(99)
- end
-
- should "work with enums" do
- assert_equal [14,15], (10...16).drop(4)
- end
- end
-
- context "#drop_while" do
- should "conform to doc" do
- assert_equal [8, 13], [ 1, 1, 2, 3, 5, 8, 13 ].drop_while {|item| item < 6 }
- end
-
- should "work with enums" do
- assert_equal [14,15], (10...16).drop_while {|item| item < 14}
- end
-
- should "work with extemity cases" do
- assert_equal [10,11,12,13,14,15], (10...16).drop_while {|item| false}
- assert_equal [], (10...16).drop_while {|item| true}
- end
- end
-
- context "#each_cons" do
- should "conform to doc" do
- assert_equal [[1,2],[2,3],[3,4]], (1..4).each_cons(2).to_a
- end
- end
-
- context "#each_slice" do
- should "conform to doc" do
- res = []
- (1..10).each_slice(4){|ar| res << ar}
- assert_equal [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10]], res
- assert_equal [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10]], (1..10).each_slice(4).to_a
- end
- end
-
- context "#each_with_index" do
- should "conform to doc" do
- hash = Hash.new
- %w(cat dog wombat).each_with_index do |item, index|
- hash[item] = index
- end
- assert_equal({"cat"=>0, "wombat"=>2, "dog"=>1}, hash)
- end
-
- should "be ok with arguments and no block" do
- s = StringIO.new("Hello world!")
- assert_equal [["Hello",0], [" wo",1], ["rld!",2]], s.each_with_index("o").to_a
- end
-
- end
-
- context "#each_with_object" do
- should "conform to doc" do
- hash = %w(cat dog wombat).each_with_object({}) do |item, memo|
- memo[item] = item.upcase.reverse
- end
- assert_equal({"cat"=>"TAC", "dog"=>"GOD", "wombat"=>"TABMOW"}, hash)
- end
- end
-
- context "#find" do
- should "not require a block" do
- assert_equal 3, (1..10).find.each {|item| item > 2 }
- end
-
- should "work as expected" do
- assert_equal 3, (1..10).find {|item| item > 2 }
- end
- end
-
- context "#find_index" do
- should "conform to doc" do
- assert_equal 3, %w{ant bat cat dog}.find_index {|item| item =~ /g/ }
- assert_equal nil, %w{ant bat cat dog}.find_index {|item| item =~ /h/ }
- end
-
- should "work for enumerables too" do
- assert_equal 69-42, (42..666).find_index(69)
- end
- end
-
- context "#group_by" do
- should "conform to doc" do
- x = (1..5).group_by{|item| item.even? ? :even : :odd }
- assert_equal({:even => [2,4], :odd => [1,3,5]}, x)
- assert_equal nil, x[:xyz]
- end
- end
-
- context "#inject" do
- should "conform to doc" do
- assert_equal 45, (5..10).inject(0) {|sum, n| sum + n }
- assert_equal 45, (5..10).inject {|sum, n| sum + n }
- assert_equal 45, (5..10).inject(0, :+)
- assert_equal 45, (5..10).inject(:+)
- end
- end
-
- context "#max_by" do
- should "conform to doc" do
- a = %w(albatross dog horse fox)
- assert_equal "albatross" , a.max_by {|item| item.length }
- assert_equal "fox", a.max_by {|item| item.reverse }
- end
- end
-
- context "#min_by" do
- should "conform to doc" do
- a = %w(albatross dog horse fox)
- assert_equal "dog" , a.min_by {|item| item.length }
- assert_equal "horse", a.min_by {|item| item.reverse }
- end
- end
-
- context "#minmax" do
- should "conform to doc" do
- a = %w(albatross dog horse)
- assert_equal ["albatross", "horse"], a.minmax
- assert_equal ["dog", "albatross"], a.minmax {|a,b| a.length <=> b.length }
- end
- end
-
- context "#one" do
- should "conform to doc" do
- assert_equal false, %w{ ant bear cat}.one? {|word| word.length >= 3}
- assert_equal true, %w{ ant bear cat}.one? {|word| word.length >= 4}
- assert_equal true, [ nil, nil, 99 ].one?
- end
- end
-
- context "#reverse_each" do
- should "work as expected" do
- assert_equal [4,3,2], (1..4).reverse_each.take(3)
- end
- end
-
- context "#take" do
- should "conform to doc" do
- assert_equal [1, 2, 3], (1..7).take(3)
- assert_equal [["a", 1], ["b", 2]], { 'a'=>1, 'b'=>2, 'c'=>3 }.take(2)
- end
-
- should "only consume what's needed" do
- assert_equal [], Enumerator.new(nil).take(0)
- assert_raises(NoMethodError) { Enumerator.new(nil).take(1) }
- end
- end
-
- context "#take_while" do
- should "conform to doc" do
- assert_equal [1,2], (1..7).take_while {|item| item < 3 }
- assert_equal [2,4,6], [ 2, 4, 6, 9, 11, 16 ].take_while(&:even?)
- end
-
- should "work with infinite enumerables" do
- assert_equal [1,2], (1..(1/0.0)).take_while {|item| item < 3 }
- end
- end
-
- context "#to_a" do
- should "work with arguments" do
- s = StringIO.new("Hello world!")
- assert_equal ["Hello", " wo", "rld!"], s.to_a("o")
- end
- end
-
- context "#chunk" do
- context "given no argument" do
- should "should chunk correctly even for non-consecutive but similar keys" do
- e = (1..7).chunk{|i| (i/3) % 2}
- assert_equal true, e.is_a?(Enumerator)
- assert_equal [
- [0, [1,2]],
- [1, [3,4,5]],
- [0, [6,7]]], e.to_a
- end
-
- should "should pass two arguments to the block" do
- e = (1..7).chunk{|i| (i/3) % 2}
- e.each do |key, val|
- assert_equal 0, key
- assert_equal [1,2], val
- break
- end
- end
-
- should "handles nil & :_symbol" do
- a = [1,1,nil,1,:_separator, 1, :_singleton, 1]
- e = a.size.times.chunk{|i| a[i]}
- assert_equal [
- [1,[0,1]],
- [1,[3]],
- [1,[5]],
- [:_singleton, [6]],
- [1,[7]]
- ], e.to_a
- end unless RUBY_VERSION > '1.9'
-
- end
-
- context "given an initial_state argument" do
- should "give a new copy" do
- a = []
- e = (1..3).chunk(a) do |i, x|
- assert_equal true, x.empty?
- x << :yo
- :_singleton
- end
- assert_equal [
- [:_singleton, [1]],
- [:_singleton, [2]],
- [:_singleton, [3]]], e.to_a
- end
- end unless RUBY_VERSION > '1.9'
-
- end
-
- end
-end
View
45 test/enumerator_test.rb
@@ -1,45 +0,0 @@
-require 'test_helper'
-
-
-class EnumeratorTest < Test::Unit::TestCase
- context "Enumerator" do
- context "#with_object" do
- should "conform to doc" do
- animals = %w(cat dog wombat).to_enum
- hash = animals.with_object({}).each do |item, memo|
- memo[item] = item.upcase.reverse
- end
- assert_equal({"cat"=>"TAC", "dog"=>"GOD", "wombat"=>"TABMOW"}, hash)
- end
- end
-
- context "#new" do
- should "should accept block" do
- enum = Enumerator.new do |yielder|
- yielder.yield "This syntax is"
- yielder.yield "cool!"
- end
- assert enum.is_a?(Enumerator)
- 2.times do
- assert_equal ["This syntax is", "cool!"], enum.to_a
- end
- end
- end
-
- context "#each" do
- should "should not require block" do
- assert_nothing_raised { [42].to_enum.each }
- assert_equal [42], [42].to_enum.each.to_a
- end
- end
-
- context "#next" do
- should "conform to doc" do
- enum = [10, 20].to_enum
- assert_equal 10, enum.next
- assert_equal 20, enum.next
- assert_raise(StopIteration){ enum.next}
- end
- end
- end
-end
View
26 test/hash_test.rb
@@ -1,26 +0,0 @@
-require 'test_helper'
-
-class HashTest < Test::Unit::TestCase
- context "Hash" do
- should "should be constructible from key value pairs" do
- assert_equal({1 => 2, 3 => 4}, Hash[[[1,2],[3,4]]])
- end
-
- context "#default_proc=" do
- should "conform to doc" do
- h = { :foo => :bar }
- h.default = "Go fish"
- h.default_proc=lambda do |hash, key|
- key + key
- end
- assert_equal :bar, h[:foo]
- assert_equal 4, h[2]
- assert_equal "catcat", h["cat"]
- h.default=nil
- assert_equal nil, h[2]
- assert_equal nil, h["cat"]
- end
- end
- end
-
-end
View
31 test/kernel_test.rb
@@ -1,31 +0,0 @@
-require 'test_helper'
-
-$outside = __callee__
-def fred
- "I'm in #{__callee__.inspect}"
-end
-
-class KernelTest < Test::Unit::TestCase
- context "Kernel" do
- context ".loop" do
- should "catch StopIteration" do
- i = 0
- r = []
- loop do
- r << i
- i += 1
- raise StopIteration if i > 2
- end
- assert_equal [0, 1, 2], r
- end
- end
-
-
- context ".__callee__" do
- should "conform to doc" do
- assert_equal "I'm in :fred", fred
- assert_equal nil, $outside
- end
- end
- end
-end
View
59 test/math_test.rb
@@ -1,59 +0,0 @@
-require 'test_helper'
-
-class MathTest < Test::Unit::TestCase
- context "Math" do
- context ".log" do
- should "accept one argument" do
- assert_nothing_raised(ArgumentError) { Math.log(1) }
- end
-
- should "accept two arguments" do
- assert_nothing_raised(ArgumentError) { Math.log(2, 2) }
- end
-
- should "accept valid arguments" do
- assert_nothing_raised(TypeError) { Math.log(2, 2) }
- assert_nothing_raised(TypeError) { Math.log(2, 2.0) }
- end
-
- should "reject invalid arguments" do
- assert_raises(TypeError) { Math.log(2, nil) }
- assert_raises(TypeError) { Math.log(2, "2") }
- end
-
- should "return the correct value" do
- assert_equal 0.0, Math.log(1)
- assert_equal 1.0, Math.log(Math::E)
- assert_equal 3.0, Math.log(Math::E**3)
- assert_equal 3.0, Math.log(8, 2)
- end
- end
-
- context ".log2" do
- should "be defined" do
- assert_respond_to Math, :log2
- end
-
- should "accept one argument" do
- assert_nothing_raised(ArgumentError) { Math.log2(1) }
- end
-
- should "accept valid arguments" do
- assert_nothing_raised(TypeError) { Math.log2(1) }
- assert_nothing_raised(TypeError) { Math.log2(1.0) }
- end
-
- should "reject invalid arguments" do
- assert_raises(TypeError) { Math.log2(nil) }
- assert_raises(TypeError) { Math.log2("1") }
- end
-
- should "return the correct value" do
- assert_equal 0.0, Math.log2(1)
- assert_equal 1.0, Math.log2(2)
- assert_equal 15.0, Math.log2(32768)
- assert_equal 16.0, Math.log2(65536)
- end
- end
- end
-end
View
73 test/method_test.rb
@@ -1,73 +0,0 @@
-require 'test_helper'
-
-class ArrayTest < Test::Unit::TestCase
-
- context "Method" do
- setup do
- @cat = "cat"
- @bound = @cat.method(:upcase)
- end
-
- context "#name" do
- should "conform to doc" do
- assert_equal "upcase", @bound.name.to_s
- end
- end
-
- context "#owner" do
- should "conform to doc" do
- assert_equal String, @bound.owner
- end
- end
-
- context "#receiver" do
- should "conform to doc" do
- assert @cat === @bound.receiver
- end
- end
-
- context "Unbound" do
- setup do
- @unbound = @bound.unbind
- end
-
- context "#name" do
- should "conform to doc" do
- assert_equal "upcase", @unbound.name.to_s
- end
- end
-
- context "#owner" do
- should "conform to doc" do
- assert_equal String, @unbound.owner
- end
- end
-
- context "bound again" do
- setup do
- @dog = "dog"
- @bound_again = @unbound.bind(@dog)
- end
-
- context "#name" do
- should "conform to doc" do
- assert_equal "upcase", @bound_again.name.to_s
- end
- end
-
- context "#owner" do
- should "conform to doc" do
- assert_equal String, @bound_again.owner
- end
- end
-
- context "#receiver" do
- should "conform to doc" do
- assert @dog === @bound_again.receiver
- end
- end
-
- end
- end
- end
-end
View
20 test/module_test.rb
@@ -1,20 +0,0 @@
-require 'test_helper'
-
-class Thing
-end
-
-class ModuleTest < Test::Unit::TestCase
- context "Module" do
- context "#module_exec" do
- should "conform to doc" do
- name = :new_instance_variable
- Thing.module_exec(name) do |iv_name|
- attr_accessor iv_name
- end
- t = Thing.new
- t.new_instance_variable = "wibble"
- assert_equal "wibble", t.new_instance_variable
- end
- end
- end
-end
View
35 test/object_test.rb
@@ -1,35 +0,0 @@
-require 'test_helper'
-
-class ObjectTest < Test::Unit::TestCase
- class KlassWithSecret
- def initialize
- @secret = 99
- end
- end
- context "Object" do
- context "#instance_exec" do
- should "conform to doc" do
- k = KlassWithSecret.new
- assert_equal 104, k.instance_exec(5) {|x| @secret+x }
- end
- end
-
- context "#define_singleton_method" do
- should "conform to doc" do
- a = "cat"
- a.define_singleton_method(:speak) do
- "miaow"
- end
- assert_equal "miaow", a.speak
-
- KlassWithSecret.class_eval do
- define_method(:one) { "instance method" }
- define_singleton_method(:two) { "class method" }
- end
- t = KlassWithSecret.new
- assert_equal "instance method", t.one
- assert_equal "class method", KlassWithSecret.two
- end
- end
- end
-end
View
116 test/proc_test.rb
@@ -1,116 +0,0 @@
-require 'test_helper'
-
-class ProcTest < Test::Unit::TestCase
- # method names correspond with Ruby docs
- def n(&b) b.lambda? end
- def m() end
-
- class C
- define_method(:d) {}
- define_method(:e, &proc {})
- end
-
- def implicit
- Proc.new
- end
-
- context "Proc" do
- context "#lambda?" do
- context "basic usage" do
- should "conform to docs" do
- assert lambda {}.lambda?
- assert !proc {}.lambda?
- assert !Proc.new {}.lambda?
- end
- end
-
- context "propagation" do
- should "conform to docs" do
- assert lambda(&lambda {}).lambda?
- assert proc(&lambda {}).lambda?
- assert Proc.new(&lambda {}).lambda?
- end
- end
-
- context "blocks passed to methods" do
- should "conform to docs" do
- assert !n { }
- assert n(&lambda {})
- assert !n(&proc {})
- assert !n(&Proc.new {})
- end
-
- should "not break Proc.new" do
- implicit { }
- implicit(&proc {})
- end
- end
-
- context "Method#to_proc" do
- should "conform to docs" do
- assert method(:m).to_proc.lambda?
- assert n(&method(:m))
- assert n(&method(:m).to_proc)
- assert C.new.method(:d).to_proc.lambda?
- assert C.new.method(:e).to_proc.lambda?
- end
- end
- end
-
- context "#curry" do
- context "proc" do
- context "no arguments" do
- should "conform to docs" do
- b = proc { :foo }
- assert_equal :foo, b.curry[]
- end
- end
-
- context "arity > 0" do
- should "conform to docs" do
- b = Proc.new {|x, y, z| (x||0) + (y||0) + (z||0) }
- assert_equal 6, b.curry[1][2][3]
- assert_equal 6, b.curry[1, 2][3, 4]
- assert_equal 6, b.curry(5)[1][2][3][4][5]
- assert_equal 6, b.curry(5)[1, 2][3, 4][5]
- assert_equal 1, b.curry(1)[1]
- end
- end
-
- context "arity < 0" do
- should "conform to docs" do
- b = Proc.new {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
- assert_equal 6, b.curry[1][2][3]
- assert_equal 10, b.curry[1, 2][3, 4]
- assert_equal 15, b.curry(5)[1][2][3][4][5]
- assert_equal 15, b.curry(5)[1, 2][3, 4][5]
- assert_equal 1, b.curry(1)[1]
- end
- end
- end
-
- context "lambda" do
- context "arity > 0" do
- should "conform to docs" do
- b = lambda {|x, y, z| (x||0) + (y||0) + (z||0) }
- assert_equal 6, b.curry[1][2][3]
- assert_raises(ArgumentError) { b.curry[1, 2][3, 4] }
- assert_raises(ArgumentError) { b.curry(5) }
- assert_raises(ArgumentError) { b.curry(1) }
- end
- end
-
- context "arity < 0" do
- should "conform to docs" do
- b = lambda {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
- assert_equal 6, b.curry[1][2][3]
- assert_equal 10, b.curry[1, 2][3, 4]
- assert_equal 15, b.curry(5)[1][2][3][4][5]
- assert_equal 15, b.curry(5)[1, 2][3, 4][5]
- assert_raises(ArgumentError) { b.curry(1) }
- end
- end
- end
- end
- end
-end
View
14 test/regexp_test.rb
@@ -1,14 +0,0 @@
-require 'test_helper'
-
-class RegexpTest < Test::Unit::TestCase
- context "Regexp" do
- context ".union" do
- should "conform to doc" do
- assert_equal /cat/ , Regexp.union("cat")
- assert_equal /cat|dog/ , Regexp.union("cat", "dog")
- assert_equal /cat|dog/ , Regexp.union(%w{ cat dog })
- assert_equal /cat|(?i-mx:dog)/, Regexp.union("cat", /dog/i)
- end
- end
- end
-end
View
60 test/std_lib_loading_test.rb
@@ -1,60 +0,0 @@
-$bogus = []
-
-module Kernel
- def require_with_bogus_extension(lib)
- $bogus << lib
- require_without_bogus_extension(lib)
- end
- alias_method :require_without_bogus_extension, :require
- alias_method :require, :require_with_bogus_extension
-
- if defined? BasicObject and BasicObject.superclass
- BasicObject.send :undef_method, :require
- BasicObject.send :undef_method, :require_with_bogus_extension
- end
-end
-
-require 'matrix'
-require 'test_helper'
-
-
-class StdLibLoadingTest < Test::Unit::TestCase
- context "StdLib" do
- should "load correctly after requiring backports" do
- path = File.expand_path("../../lib/backports/1.9.2/stdlib/set.rb", __FILE__)
- assert_equal false, $LOADED_FEATURES.include?(path)
- assert_equal true, require('set')
- assert_equal true, $bogus.include?("set")
- assert_equal true, $LOADED_FEATURES.include?(path)
- assert_equal false, require('set')
- end
-
- should "load correctly before requiring backports" do
- assert_equal true, $bogus.include?("matrix")
- path = File.expand_path("../../lib/backports/1.9.2/stdlib/matrix.rb", __FILE__)
- assert_equal true, $LOADED_FEATURES.include?(path)
- assert_equal false, require('matrix')
- end
-
- should "not interfere for libraries without backports" do
- assert_equal true, require('dl')
- assert_equal false, require('dl')
- end
-
- if RUBY_VERSION >= "1.9"
- should 'not load "new libraries" when they already exist' do
- path = File.expand_path("../../lib/backports/1.9.1/stdlib_new/prime.rb", __FILE__)
- assert_equal true, require('prime')
- assert_equal false, require('prime')
- assert_equal false, $LOADED_FEATURES.include?(path)
- end
- else
- should "load correctly new libraries" do
- assert_equal false, $LOADED_FEATURES.include?("prime.rb")
- assert_equal true, require('prime')
- assert_equal true, $LOADED_FEATURES.include?("prime.rb")
- assert_equal false, require('prime')
- end
- end
- end
-end
View
74 test/string_test.rb
@@ -1,74 +0,0 @@
-# encoding: utf-8
-$KCODE = 'u' if RUBY_VERSION < '1.9'
-require 'test_helper'
-
-class StringTest < Test::Unit::TestCase
- context "String" do
- context "#ascii_only?" do
- should "conform to doc" do
- assert_equal true, "dog".ascii_only?
- assert_equal false, "δog".ascii_only?
- assert_equal true, "\x00 to \x7f".ascii_only?
- end
- end
-
- context "#chars" do
- should "conform to doc" do
- assert_equal ["d", "o", "g"], "dog".chars.to_a
- assert_equal ["δ", "o", "g"], "δog".chars.to_a
- result = []
- "δog".chars.each {|b| result << b }
- assert_equal ["δ", "o", "g"], result
- end
- end
-
- context "#chr" do
- should "conform to doc" do
- assert_equal "d", "dog".chr
- assert_equal "δ", "δog".chr
- end
- end
-
- context "#codepoints" do
- should "conform to doc" do
- assert_equal [100, 111, 103], "dog".codepoints.to_a
- assert_equal [948, 111, 103], "δog".codepoints.to_a # Note, there is an error in Pragmatics' book
- result = []
- assert_equal "δog", "δog".codepoints.each {|b| result << b }
- assert_equal [948, 111, 103], result
- end
- end
-
- context "#start_with" do
- should "conform to doc" do
- assert "Apache".start_with?("Apa")
- assert "ruby code".start_with?("python", "perl", "ruby")
- assert !"hello world".start_with?("world")
- end
- end
-
- context "#end_with" do
- should "conform to doc" do
- assert "Apache".end_with?("ache")
- assert "ruby code".end_with?("python", "perl", "code")
- assert !"hello world".end_with?("hello")
- end
- end
-
- context "#partition" do
- should "conform to doc" do
- assert_equal ["THX", "11", "38"], "THX1138".partition("11")
- assert_equal ["THX", "11", "38"], "THX1138".partition(/\d\d/)
- assert_equal ["THX1138", "", ""], "THX1138".partition("99")
- end
- end
-
- context "#rpartition" do
- should "conform to doc" do
- assert_equal ["THX1", "1", "38"], "THX1138".rpartition("1")
- assert_equal ["THX1", "13", "8"], "THX1138".rpartition(/1\d/)
- assert_equal ["", "", "THX1138"], "THX1138".rpartition("99")
- end
- end
- end
-end
View
23 test/symbol_test.rb
@@ -1,23 +0,0 @@
-require 'test_helper'
-
-class SymbolTest < Test::Unit::TestCase
- context "Symbol" do
- context "comparison" do
- should "work as expected" do
- assert_equal false, :abc == :def
- assert_equal true, :abc == :abc
- assert_equal false, :abc == "abc"
- assert_equal false, :abc > :def
- assert_equal true, :abc < :def
- assert_raise(ArgumentError) {:abc < "def"}
- end
- end
-
- context "string ops" do
- should "work as expected" do
- assert_equal :HELLO, :hello.upcase
- assert_equal 5, :hello.length
- end
- end
- end
-end
View
8 test/test_helper.rb
@@ -1,8 +0,0 @@
-require 'rubygems'
-require 'test/unit'
-require 'shoulda'
-
-require File.expand_path(File.dirname(__FILE__) + "/../lib/backports")
-
-# class Test::Unit::TestCase
-# end
Please sign in to comment.
Something went wrong with that request. Please try again.