Skip to content

Commit

Permalink
[GR-14806] Update specs
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4077
  • Loading branch information
eregon committed Nov 28, 2023
2 parents 78f52bc + 4e3a3f6 commit 374383c
Show file tree
Hide file tree
Showing 35 changed files with 275 additions and 73 deletions.
12 changes: 12 additions & 0 deletions spec/ruby/core/array/assoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@
a.assoc(s1.first).should equal(s1)
a.assoc(s2.first).should equal(s2)
end

it "calls to_ary on non-array elements" do
s1 = [1, 2]
s2 = ArraySpecs::ArrayConvertible.new(2, 3)
a = [s1, s2]

s1.should_not_receive(:to_ary)
a.assoc(s1.first).should equal(s1)

a.assoc(2).should == [2, 3]
s2.called.should equal(:to_ary)
end
end
12 changes: 12 additions & 0 deletions spec/ruby/core/array/rassoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ def o.==(other); other == 'foobar'; end

[[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1]
end

it "does not call to_ary on non-array elements" do
s1 = [1, 2]
s2 = ArraySpecs::ArrayConvertible.new(2, 3)
a = [s1, s2]

s1.should_not_receive(:to_ary)
a.rassoc(2).should equal(s1)

s2.should_not_receive(:to_ary)
a.rassoc(3).should equal(nil)
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/file/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
File.should.exist?(@file)
end

it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
it "raises an Errno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
-> { @fh = File.new(@file, File::CREAT|File::EXCL) }.should raise_error(Errno::EEXIST)
end

Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/core/file/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
end
end

it "raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do
it "raises an Errno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do
-> {
File.open(@file, File::CREAT|File::EXCL) do |f|
f.puts("writing")
Expand Down Expand Up @@ -423,7 +423,7 @@
}.should raise_error(IOError)
end

it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
-> {
File.open(@file, File::RDONLY|File::TRUNC) do |f|
f.puts("writing").should == nil
Expand All @@ -441,7 +441,7 @@
}.should raise_error(Errno::EINVAL)
end

it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
-> {
File.open(@file, File::RDONLY|File::TRUNC) do |f|
f.puts("writing").should == nil
Expand Down
26 changes: 26 additions & 0 deletions spec/ruby/core/io/read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,32 @@
@io.read(10, buf).should == nil

buf.should == ''

buf = 'non-empty string'

@io.read(nil, buf).should == ""

buf.should == ''

buf = 'non-empty string'

@io.read(0, buf).should == ""

buf.should == ''
end

it "raise FrozenError if the output buffer is frozen" do
@io.read
-> { @io.read(0, 'frozen-string'.freeze) }.should raise_error(FrozenError)
-> { @io.read(1, 'frozen-string'.freeze) }.should raise_error(FrozenError)
-> { @io.read(nil, 'frozen-string'.freeze) }.should raise_error(FrozenError)
end

ruby_bug "", ""..."3.3" do
it "raise FrozenError if the output buffer is frozen (2)" do
@io.read
-> { @io.read(1, ''.freeze) }.should raise_error(FrozenError)
end
end

it "consumes zero bytes when reading zero bytes" do
Expand Down
15 changes: 15 additions & 0 deletions spec/ruby/core/kernel/Integer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,21 @@
Integer("777", obj).should == 0777
end

# https://bugs.ruby-lang.org/issues/19349
ruby_version_is ''...'3.3' do
it "ignores the base if it is not an integer and does not respond to #to_i" do
Integer("777", "8").should == 777
end
end

ruby_version_is '3.3' do
it "raises a TypeError if it is not an integer and does not respond to #to_i" do
-> {
Integer("777", "8")
}.should raise_error(TypeError, "no implicit conversion of String into Integer")
end
end

describe "when passed exception: false" do
describe "and valid argument" do
it "returns an Integer number" do
Expand Down
7 changes: 7 additions & 0 deletions spec/ruby/language/singleton_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,11 @@ def singleton_method; 1 end
o.freeze
klass.frozen?.should == true
end

it "will be unfrozen if the frozen object is cloned with freeze set to false" do
o = Object.new
o.freeze
o2 = o.clone(freeze: false)
o2.singleton_class.frozen?.should == false
end
end
16 changes: 9 additions & 7 deletions spec/ruby/library/English/English_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@
$LAST_MATCH_INFO.should == $~
end

it "aliases $IGNORECASE to $=" do
$VERBOSE, verbose = nil, $VERBOSE
begin
$IGNORECASE.should_not be_nil
$IGNORECASE.should == $=
ensure
$VERBOSE = verbose
ruby_version_is ""..."3.3" do
it "aliases $IGNORECASE to $=" do
$VERBOSE, verbose = nil, $VERBOSE
begin
$IGNORECASE.should_not be_nil
$IGNORECASE.should == $=
ensure
$VERBOSE = verbose
end
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/ruby/library/date/iso8601_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
d.should == Date.civil(-4712, 1, 1)
end

it "raises a Date::Error if the argument is a invalid Date" do
-> {
Date.iso8601('invalid')
}.should raise_error(Date::Error, "invalid date")
end

it "raises a Date::Error when passed a nil" do
-> {
Date.iso8601(nil)
}.should raise_error(Date::Error, "invalid date")
end

it "raises a TypeError when passed an Object" do
-> { Date.iso8601(Object.new) }.should raise_error(TypeError)
end
Expand All @@ -32,4 +44,13 @@
h = Date._iso8601('invalid')
h.should == {}
end

it "returns an empty hash if the argument is nil" do
h = Date._iso8601(nil)
h.should == {}
end

it "raises a TypeError when passed an Object" do
-> { Date._iso8601(Object.new) }.should raise_error(TypeError)
end
end
4 changes: 2 additions & 2 deletions spec/ruby/library/date/shared/parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
d.day.should == 23
end

it "can parse a 'mmm DD YYYY' string into a Date object" do
it "can parse a 'DD mmm YYYY' string into a Date object" do
d = Date.parse("23#{@sep}feb#{@sep}2008")
d.year.should == 2008
d.month.should == 2
Expand Down Expand Up @@ -42,7 +42,7 @@
d.should == Date.civil(2005, 11, 5)
end

it "can parse a year, day and month name into a Date object" do
it "can parse a day, month name and year into a Date object" do
d = Date.parse("5th#{@sep}november#{@sep}2005")
d.should == Date.civil(2005, 11, 5)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/library/date/shared/parse_eu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
d.day.should == 1
end

it "can parse a MM-DD-YYYY string into a Date object" do
it "can parse a DD-MM-YYYY string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}2007")
d.year.should == 2007
d.month.should == 1
d.day.should == 10
end

it "can parse a MM-DD-YY string into a Date object" do
it "can parse a YY-MM-DD string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}07")
d.year.should == 2010
d.month.should == 1
d.day.should == 7
end

it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do
it "can parse a YY-MM-DD string into a Date object NOT using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", false)
d.year.should == 10
d.month.should == 1
d.day.should == 7
end

it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do
it "can parse a YY-MM-DD string into a Date object using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", true)
d.year.should == 2010
d.month.should == 1
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/library/date/shared/parse_us.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
d.day.should == 1
end

it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do
it "parses a DD#{@sep}MM#{@sep}YYYY string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}2007")
d.year.should == 2007
d.month.should == 1
d.day.should == 10
end

it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do
it "parses a YY#{@sep}MM#{@sep}DD string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}07")
d.year.should == 2010
d.month.should == 1
d.day.should == 7
end

it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do
it "parses a YY#{@sep}MM#{@sep}DD string into a Date object NOT using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", false)
d.year.should == 10
d.month.should == 1
d.day.should == 7
end

it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do
it "parses a YY#{@sep}MM#{@sep}DD string into a Date object using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", true)
d.year.should == 2010
d.month.should == 1
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/library/digest/instance/shared/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
c = Class.new do
include Digest::Instance
end
-> { c.new.update("test") }.should raise_error(RuntimeError)
-> { c.new.send(@method, "test") }.should raise_error(RuntimeError)
end
end
14 changes: 14 additions & 0 deletions spec/ruby/library/etc/uname_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative '../../spec_helper'
require 'etc'

describe "Etc.uname" do
it "returns a Hash with the documented keys" do
uname = Etc.uname
uname.should be_kind_of(Hash)
uname.should.key?(:sysname)
uname.should.key?(:nodename)
uname.should.key?(:release)
uname.should.key?(:version)
uname.should.key?(:machine)
end
end
42 changes: 42 additions & 0 deletions spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative '../../spec_helper'
require 'openssl'

describe "OpenSSL.fixed_length_secure_compare" do
it "returns true for two strings with the same content" do
input1 = "the quick brown fox jumps over the lazy dog"
input2 = "the quick brown fox jumps over the lazy dog"
OpenSSL.fixed_length_secure_compare(input1, input2).should be_true
end

it "returns false for two strings of equal size with different content" do
input1 = "the quick brown fox jumps over the lazy dog"
input2 = "the lazy dog jumps over the quick brown fox"
OpenSSL.fixed_length_secure_compare(input1, input2).should be_false
end

it "converts both arguments to strings using #to_str" do
input1 = mock("input1")
input1.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog")
input2 = mock("input2")
input2.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog")
OpenSSL.fixed_length_secure_compare(input1, input2).should be_true
end

it "does not accept arguments that are not string and cannot be coerced into strings" do
-> {
OpenSSL.fixed_length_secure_compare("input1", :input2)
}.should raise_error(TypeError, 'no implicit conversion of Symbol into String')

-> {
OpenSSL.fixed_length_secure_compare(Object.new, "input2")
}.should raise_error(TypeError, 'no implicit conversion of Object into String')
end

it "raises an ArgumentError for two strings of different size" do
input1 = "the quick brown fox jumps over the lazy dog"
input2 = "the quick brown fox"
-> {
OpenSSL.fixed_length_secure_compare(input1, input2)
}.should raise_error(ArgumentError, 'inputs must be of equal length')
end
end
16 changes: 0 additions & 16 deletions spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,6 @@
}.should raise_error(ArgumentError, 'missing keywords: :salt, :iterations, :length, :hash')
end


guard -> { OpenSSL::OPENSSL_VERSION_NUMBER < 0x30000000 } do
it "treats 0 or less iterations as a single iteration" do
salt = "\x00".b * 16
length = 16
hash = "sha1"

# "Any iter less than 1 is treated as a single iteration."
key0 = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: 0)
key_negative = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: -1)
key1 = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: 1)
key0.should == key1
key_negative.should == key1
end
end

guard -> { OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000 } do
it "raises an OpenSSL::KDF::KDFError for 0 or less iterations" do
-> {
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/library/openssl/kdf/scrypt_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../../../spec_helper'
require 'openssl'

guard -> { OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000 } do
guard -> { OpenSSL::KDF.respond_to?(:scrypt) } do
describe "OpenSSL::KDF.scrypt" do
before :each do
@defaults = {
Expand Down
Loading

0 comments on commit 374383c

Please sign in to comment.