1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,10 @@
describe :range_begin, shared: true do
it "returns the first element of self" do
(-1..1).send(@method).should == -1
(0..1).send(@method).should == 0
(0xffff...0xfffff).send(@method).should == 65535
('Q'..'T').send(@method).should == 'Q'
('Q'...'T').send(@method).should == 'Q'
(0.5..2.4).send(@method).should == 0.5
end
end

View file

@ -0,0 +1,93 @@
# -*- encoding: ascii-8bit -*-
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe :range_cover, shared: true do
it "uses the range element's <=> to make the comparison" do
a = mock('a')
a.should_receive(:<=>).twice.and_return(-1,-1)
(a..'z').send(@method, 'b').should be_true
end
it "uses a continuous inclusion test" do
('a'..'f').send(@method, 'aa').should be_true
('a'..'f').send(@method, 'babe').should be_true
('a'..'f').send(@method, 'baby').should be_true
('a'..'f').send(@method, 'ga').should be_false
(-10..-2).send(@method, -2.5).should be_true
end
describe "on string elements" do
it "returns true if other is matched by element.succ" do
('a'..'c').send(@method, 'b').should be_true
('a'...'c').send(@method, 'b').should be_true
end
it "returns true if other is not matched by element.succ" do
('a'..'c').send(@method, 'bc').should be_true
('a'...'c').send(@method, 'bc').should be_true
end
end
describe "with weird succ" do
describe "when included end value" do
before :each do
@range = RangeSpecs::TenfoldSucc.new(1)..RangeSpecs::TenfoldSucc.new(99)
end
it "returns false if other is less than first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
end
it "returns true if other is equal as first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
end
it "returns true if other is matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
end
it "returns true if other is not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_true
end
it "returns true if other is equal as last element but not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_true
end
it "returns false if other is greater than last element but matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
end
end
describe "when excluded end value" do
before :each do
@range = RangeSpecs::TenfoldSucc.new(1)...RangeSpecs::TenfoldSucc.new(99)
end
it "returns false if other is less than first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
end
it "returns true if other is equal as first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
end
it "returns true if other is matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
end
it "returns true if other is not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_true
end
it "returns false if other is equal as last element but not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_false
end
it "returns false if other is greater than last element but matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
end
end
end
end

View file

@ -0,0 +1,66 @@
# -*- encoding: ascii-8bit -*-
require File.expand_path('../../../../spec_helper', __FILE__)
describe :range_cover_and_include, shared: true do
it "returns true if other is an element of self" do
(0..5).send(@method, 2).should == true
(-5..5).send(@method, 0).should == true
(-1...1).send(@method, 10.5).should == false
(-10..-2).send(@method, -2.5).should == true
('C'..'X').send(@method, 'M').should == true
('C'..'X').send(@method, 'A').should == false
('B'...'W').send(@method, 'W').should == false
('B'...'W').send(@method, 'Q').should == true
(0xffff..0xfffff).send(@method, 0xffffd).should == true
(0xffff..0xfffff).send(@method, 0xfffd).should == false
(0.5..2.4).send(@method, 2).should == true
(0.5..2.4).send(@method, 2.5).should == false
(0.5..2.4).send(@method, 2.4).should == true
(0.5...2.4).send(@method, 2.4).should == false
end
it "compares values using <=>" do
rng = (1..5)
m = mock("int")
m.should_receive(:coerce).and_return([1, 2])
m.should_receive(:<=>).and_return(1)
rng.send(@method, m).should be_false
end
it "raises an ArgumentError without exactly one argument" do
lambda{ (1..2).send(@method) }.should raise_error(ArgumentError)
lambda{ (1..2).send(@method, 1, 2) }.should raise_error(ArgumentError)
end
it "returns true if argument is equal to the first value of the range" do
(0..5).send(@method, 0).should be_true
('f'..'s').send(@method, 'f').should be_true
end
it "returns true if argument is equal to the last value of the range" do
(0..5).send(@method, 5).should be_true
(0...5).send(@method, 4).should be_true
('f'..'s').send(@method, 's').should be_true
end
it "returns true if argument is less than the last value of the range and greater than the first value" do
(20..30).send(@method, 28).should be_true
('e'..'h').send(@method, 'g').should be_true
("\u{999}".."\u{9999}").send @method, "\u{9995}"
end
it "returns true if argument is sole element in the range" do
(30..30).send(@method, 30).should be_true
end
it "returns false if range is empty" do
(30...30).send(@method, 30).should be_false
(30...30).send(@method, nil).should be_false
end
it "returns false if the range does not contain the argument" do
('A'..'C').send(@method, 20.9).should be_false
('A'...'C').send(@method, 'C').should be_false
end
end

View file

@ -0,0 +1,10 @@
describe :range_end, shared: true do
it "end returns the last element of self" do
(-1..1).send(@method).should == 1
(0..1).send(@method).should == 1
("A".."Q").send(@method).should == "Q"
("A"..."Q").send(@method).should == "Q"
(0xffff...0xfffff).send(@method).should == 1048575
(0.5..2.4).send(@method).should == 2.4
end
end

View file

@ -0,0 +1,45 @@
require File.expand_path('../../fixtures/classes', __FILE__)
describe :range_eql, shared: true do
it "returns true if other has same begin, end, and exclude_end? values" do
(0..2).send(@method, 0..2).should == true
('G'..'M').send(@method,'G'..'M').should == true
(0.5..2.4).send(@method, 0.5..2.4).should == true
(5..10).send(@method, Range.new(5,10)).should == true
('D'..'V').send(@method, Range.new('D','V')).should == true
(0.5..2.4).send(@method, Range.new(0.5, 2.4)).should == true
(0xffff..0xfffff).send(@method, 0xffff..0xfffff).should == true
(0xffff..0xfffff).send(@method, Range.new(0xffff,0xfffff)).should == true
a = RangeSpecs::Xs.new(3)..RangeSpecs::Xs.new(5)
b = Range.new(RangeSpecs::Xs.new(3), RangeSpecs::Xs.new(5))
a.send(@method, b).should == true
end
it "returns false if one of the attributes differs" do
('Q'..'X').send(@method, 'A'..'C').should == false
('Q'...'X').send(@method, 'Q'..'W').should == false
('Q'..'X').send(@method, 'Q'...'X').should == false
(0.5..2.4).send(@method, 0.5...2.4).should == false
(1482..1911).send(@method, 1482...1911).should == false
(0xffff..0xfffff).send(@method, 0xffff...0xfffff).should == false
a = RangeSpecs::Xs.new(3)..RangeSpecs::Xs.new(5)
b = Range.new(RangeSpecs::Ys.new(3), RangeSpecs::Ys.new(5))
a.send(@method, b).should == false
end
it "returns false if other is not a Range" do
(1..10).send(@method, 1).should == false
(1..10).send(@method, 'a').should == false
(1..10).send(@method, mock('x')).should == false
end
it "returns true for subclasses of Range" do
Range.new(1, 2).send(@method, RangeSpecs::MyRange.new(1, 2)).should == true
a = Range.new(RangeSpecs::Xs.new(3), RangeSpecs::Xs.new(5))
b = RangeSpecs::MyRange.new(RangeSpecs::Xs.new(3), RangeSpecs::Xs.new(5))
a.send(@method, b).should == true
end
end

View file

@ -0,0 +1,91 @@
# -*- encoding: ascii-8bit -*-
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe :range_include, shared: true do
describe "on string elements" do
it "returns true if other is matched by element.succ" do
('a'..'c').send(@method, 'b').should be_true
('a'...'c').send(@method, 'b').should be_true
end
it "returns false if other is not matched by element.succ" do
('a'..'c').send(@method, 'bc').should be_false
('a'...'c').send(@method, 'bc').should be_false
end
end
describe "with weird succ" do
describe "when included end value" do
before :each do
@range = RangeSpecs::TenfoldSucc.new(1)..RangeSpecs::TenfoldSucc.new(99)
end
it "returns false if other is less than first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
end
it "returns true if other is equal as first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
end
it "returns true if other is matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
end
it "returns false if other is not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_false
end
it "returns false if other is equal as last element but not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_false
end
it "returns false if other is greater than last element but matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
end
end
describe "when excluded end value" do
before :each do
@range = RangeSpecs::TenfoldSucc.new(1)...RangeSpecs::TenfoldSucc.new(99)
end
it "returns false if other is less than first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
end
it "returns true if other is equal as first element" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
end
it "returns true if other is matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
end
it "returns false if other is not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_false
end
it "returns false if other is equal as last element but not matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_false
end
it "returns false if other is greater than last element but matched by element.succ" do
@range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
end
end
end
describe "with Time endpoints" do
it "uses cover? logic" do
now = Time.now
range = (now..(now + 60))
range.include?(now).should == true
range.include?(now - 1).should == false
range.include?(now + 60).should == true
range.include?(now + 61).should == false
end
end
end