Skip to content

Commit

Permalink
Update to ruby/spec@ab32a1a
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jun 26, 2022
1 parent f616e81 commit d3d5ef0
Show file tree
Hide file tree
Showing 74 changed files with 1,195 additions and 318 deletions.
3 changes: 3 additions & 0 deletions spec/ruby/.rubocop.yml
Expand Up @@ -99,6 +99,9 @@ Lint/DuplicateElsifCondition:
Lint/OutOfRangeRegexpRef:
Enabled: false

Lint/InheritException:
Enabled: false

Lint/ElseLayout:
Exclude:
- 'language/if_spec.rb'
Expand Down
11 changes: 0 additions & 11 deletions spec/ruby/.rubocop_todo.yml
Expand Up @@ -50,17 +50,6 @@ Lint/IneffectiveAccessModifier:
- 'core/module/fixtures/classes.rb'
- 'language/fixtures/private.rb'

# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: runtime_error, standard_error
Lint/InheritException:
Exclude:
- 'core/enumerator/lazy/fixtures/classes.rb'
- 'core/exception/fixtures/common.rb'
- 'core/module/fixtures/autoload_ex1.rb'
- 'shared/kernel/raise.rb'

# Offense count: 72
# Cop supports --auto-correct.
Lint/LiteralInInterpolation:
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/array/fill_spec.rb
Expand Up @@ -205,6 +205,12 @@
-> { [].fill('a', obj) }.should raise_error(TypeError)
end

it "raises a TypeError when the length is not numeric" do
-> { [1, 2, 3].fill("x", 1, "foo") }.should raise_error(TypeError, /no implicit conversion of String into Integer/)
-> { [1, 2, 3].fill("x", 1, :"foo") }.should raise_error(TypeError, /no implicit conversion of Symbol into Integer/)
-> { [1, 2, 3].fill("x", 1, Object.new) }.should raise_error(TypeError, /no implicit conversion of Object into Integer/)
end

not_supported_on :opal do
it "raises an ArgumentError or RangeError for too-large sizes" do
error_types = [RangeError, ArgumentError]
Expand Down
62 changes: 62 additions & 0 deletions spec/ruby/core/array/fixtures/classes.rb
Expand Up @@ -40,6 +40,68 @@ def self.empty_recursive_array
a
end

# Chi squared critical values for tests with n degrees of freedom at 99% confidence.
# Values obtained from NIST Engineering Statistic Handbook at
# https://www.itl.nist.gov/div898/handbook/eda/section3/eda3674.htm

CHI_SQUARED_CRITICAL_VALUES = [
0,
6.635, 9.210, 11.345, 13.277, 15.086, 16.812, 18.475, 20.090, 21.666, 23.209,
24.725, 26.217, 27.688, 29.141, 30.578, 32.000, 33.409, 34.805, 36.191, 37.566,
38.932, 40.289, 41.638, 42.980, 44.314, 45.642, 46.963, 48.278, 49.588, 50.892,
52.191, 53.486, 54.776, 56.061, 57.342, 58.619, 59.893, 61.162, 62.428, 63.691,
64.950, 66.206, 67.459, 68.710, 69.957, 71.201, 72.443, 73.683, 74.919, 76.154,
77.386, 78.616, 79.843, 81.069, 82.292, 83.513, 84.733, 85.950, 87.166, 88.379,
89.591, 90.802, 92.010, 93.217, 94.422, 95.626, 96.828, 98.028, 99.228, 100.425,
101.621, 102.816, 104.010, 105.202, 106.393, 107.583, 108.771, 109.958, 111.144, 112.329,
113.512, 114.695, 115.876, 117.057, 118.236, 119.414, 120.591, 121.767, 122.942, 124.116,
125.289, 126.462, 127.633, 128.803, 129.973, 131.141, 132.309, 133.476, 134.642, 135.807,
]

def self.measure_sample_fairness(size, samples, iters)
ary = Array.new(size) { |x| x }
(samples).times do |i|
chi_results = []
3.times do
counts = Array.new(size) { 0 }
expected = iters / size
iters.times do
x = ary.sample(samples)[i]
counts[x] += 1
end
chi_squared = 0.0
counts.each do |count|
chi_squared += (((count - expected) ** 2) * 1.0 / expected)
end
chi_results << chi_squared
break if chi_squared <= CHI_SQUARED_CRITICAL_VALUES[size]
end

chi_results.min.should <= CHI_SQUARED_CRITICAL_VALUES[size]
end
end

def self.measure_sample_fairness_large_sample_size(size, samples, iters)
ary = Array.new(size) { |x| x }
counts = Array.new(size) { 0 }
expected = iters * samples / size
iters.times do
ary.sample(samples).each do |sample|
counts[sample] += 1
end
end
chi_squared = 0.0
counts.each do |count|
chi_squared += (((count - expected) ** 2) * 1.0 / expected)
end

# Chi squared critical values for tests with 4 degrees of freedom
# Values obtained from NIST Engineering Statistic Handbook at
# https://www.itl.nist.gov/div898/handbook/eda/section3/eda3674.htm

chi_squared.should <= CHI_SQUARED_CRITICAL_VALUES[size]
end

class MyArray < Array
# The #initialize method has a different signature than Array to help
# catch places in the specs that do not assert the #initialize is not
Expand Down
18 changes: 8 additions & 10 deletions spec/ruby/core/array/sample_spec.rb
Expand Up @@ -3,16 +3,14 @@

describe "Array#sample" do
it "samples evenly" do
ary = [0, 1, 2, 3]
3.times do |i|
counts = [0, 0, 0, 0]
4000.times do
counts[ary.sample(3)[i]] += 1
end
counts.each do |count|
(800..1200).should include(count)
end
end
ArraySpecs.measure_sample_fairness(4, 1, 400)
ArraySpecs.measure_sample_fairness(4, 2, 400)
ArraySpecs.measure_sample_fairness(4, 3, 400)
ArraySpecs.measure_sample_fairness(40, 3, 400)
ArraySpecs.measure_sample_fairness(40, 4, 400)
ArraySpecs.measure_sample_fairness(40, 8, 400)
ArraySpecs.measure_sample_fairness(40, 16, 400)
ArraySpecs.measure_sample_fairness_large_sample_size(100, 80, 4000)
end

it "returns nil for an empty Array" do
Expand Down
10 changes: 5 additions & 5 deletions spec/ruby/core/dir/foreach_spec.rb
Expand Up @@ -41,13 +41,13 @@

it "accepts an encoding keyword for the encoding of the entries" do
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
dirs.each { |dir| dir.encoding.should == Encoding::UTF_8 }

dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::UTF_16LE).to_a.sort
dirs.each {|dir| dir.encoding.should == Encoding::UTF_16LE}
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::ISO_8859_1).to_a.sort
dirs.each { |dir| dir.encoding.should == Encoding::ISO_8859_1 }

Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::UTF_16LE) do |f|
f.encoding.should == Encoding::UTF_16LE
Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::ISO_8859_1) do |f|
f.encoding.should == Encoding::ISO_8859_1
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/core/exception/signal_exception_spec.rb
Expand Up @@ -93,7 +93,7 @@

platform_is_not :windows do
it "runs after at_exit" do
output = ruby_exe(<<-RUBY, exit_status: nil)
output = ruby_exe(<<-RUBY, exit_status: :SIGKILL)
at_exit do
puts "hello"
$stdout.flush
Expand All @@ -107,7 +107,7 @@
end

it "cannot be trapped with Signal.trap" do
ruby_exe(<<-RUBY, exit_status: nil)
ruby_exe(<<-RUBY, exit_status: :SIGPROF)
Signal.trap("PROF") {}
raise(SignalException, "PROF")
RUBY
Expand All @@ -116,7 +116,7 @@
end

it "self-signals for USR1" do
ruby_exe("raise(SignalException, 'USR1')", exit_status: nil)
ruby_exe("raise(SignalException, 'USR1')", exit_status: :SIGUSR1)
$?.termsig.should == Signal.list.fetch('USR1')
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/ruby/core/file/open_spec.rb
Expand Up @@ -494,6 +494,14 @@
File.open(@file, "w") { |f| f.puts "testing" }
File.size(@file).should > 0
File.open(@file, "rb+") do |f|
f.binmode?.should == true
f.external_encoding.should == Encoding::ASCII_8BIT
f.pos.should == 0
f.should_not.eof?
end
File.open(@file, "r+b") do |f|
f.binmode?.should == true
f.external_encoding.should == Encoding::ASCII_8BIT
f.pos.should == 0
f.should_not.eof?
end
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/float/divide_spec.rb
Expand Up @@ -36,4 +36,8 @@
-> { 13.0 / "10" }.should raise_error(TypeError)
-> { 13.0 / :symbol }.should raise_error(TypeError)
end

it "divides correctly by Rational numbers" do
(1.2345678901234567 / Rational(1, 10000000000000000000)).should == 1.2345678901234567e+19
end
end
64 changes: 64 additions & 0 deletions spec/ruby/core/float/round_spec.rb
Expand Up @@ -103,6 +103,70 @@
5.55.round(1, half: :up).should eql(5.6)
5.55.round(1, half: :down).should eql(5.5)
5.55.round(1, half: :even).should eql(5.6)
-5.55.round(1, half: nil).should eql(-5.6)
-5.55.round(1, half: :up).should eql(-5.6)
-5.55.round(1, half: :down).should eql(-5.5)
-5.55.round(1, half: :even).should eql(-5.6)
end

it "preserves cases where neighbouring floating pointer number increase the decimal places" do
4.8100000000000005.round(5, half: nil).should eql(4.81)
4.8100000000000005.round(5, half: :up).should eql(4.81)
4.8100000000000005.round(5, half: :down).should eql(4.81)
4.8100000000000005.round(5, half: :even).should eql(4.81)
-4.8100000000000005.round(5, half: nil).should eql(-4.81)
-4.8100000000000005.round(5, half: :up).should eql(-4.81)
-4.8100000000000005.round(5, half: :down).should eql(-4.81)
-4.8100000000000005.round(5, half: :even).should eql(-4.81)
4.81.round(5, half: nil).should eql(4.81)
4.81.round(5, half: :up).should eql(4.81)
4.81.round(5, half: :down).should eql(4.81)
4.81.round(5, half: :even).should eql(4.81)
-4.81.round(5, half: nil).should eql(-4.81)
-4.81.round(5, half: :up).should eql(-4.81)
-4.81.round(5, half: :down).should eql(-4.81)
-4.81.round(5, half: :even).should eql(-4.81)
4.809999999999999.round(5, half: nil).should eql(4.81)
4.809999999999999.round(5, half: :up).should eql(4.81)
4.809999999999999.round(5, half: :down).should eql(4.81)
4.809999999999999.round(5, half: :even).should eql(4.81)
-4.809999999999999.round(5, half: nil).should eql(-4.81)
-4.809999999999999.round(5, half: :up).should eql(-4.81)
-4.809999999999999.round(5, half: :down).should eql(-4.81)
-4.809999999999999.round(5, half: :even).should eql(-4.81)
end

ruby_bug "", ""..."3.3" do
# These numbers are neighbouring floating point numbers round a
# precise value. They test that the rounding modes work correctly
# round that value and precision is not lost which might cause
# incorrect results.
it "does not lose precision during the rounding process" do
767573.1875850001.round(5, half: nil).should eql(767573.18759)
767573.1875850001.round(5, half: :up).should eql(767573.18759)
767573.1875850001.round(5, half: :down).should eql(767573.18759)
767573.1875850001.round(5, half: :even).should eql(767573.18759)
-767573.1875850001.round(5, half: nil).should eql(-767573.18759)
-767573.1875850001.round(5, half: :up).should eql(-767573.18759)
-767573.1875850001.round(5, half: :down).should eql(-767573.18759)
-767573.1875850001.round(5, half: :even).should eql(-767573.18759)
767573.187585.round(5, half: nil).should eql(767573.18759)
767573.187585.round(5, half: :up).should eql(767573.18759)
767573.187585.round(5, half: :down).should eql(767573.18758)
767573.187585.round(5, half: :even).should eql(767573.18758)
-767573.187585.round(5, half: nil).should eql(-767573.18759)
-767573.187585.round(5, half: :up).should eql(-767573.18759)
-767573.187585.round(5, half: :down).should eql(-767573.18758)
-767573.187585.round(5, half: :even).should eql(-767573.18758)
767573.1875849998.round(5, half: nil).should eql(767573.18758)
767573.1875849998.round(5, half: :up).should eql(767573.18758)
767573.1875849998.round(5, half: :down).should eql(767573.18758)
767573.1875849998.round(5, half: :even).should eql(767573.18758)
-767573.1875849998.round(5, half: nil).should eql(-767573.18758)
-767573.1875849998.round(5, half: :up).should eql(-767573.18758)
-767573.1875849998.round(5, half: :down).should eql(-767573.18758)
-767573.1875849998.round(5, half: :even).should eql(-767573.18758)
end
end

it "raises FloatDomainError for exceptional values with a half option" do
Expand Down
39 changes: 19 additions & 20 deletions spec/ruby/core/integer/chr_spec.rb
Expand Up @@ -223,26 +223,25 @@

# #5864
it "raises RangeError if self is invalid as a codepoint in the specified encoding" do
[ [0x80, "US-ASCII"],
[0x0100, "BINARY"],
[0x0100, "EUC-JP"],
[0xA1A0, "EUC-JP"],
[0xA1, "EUC-JP"],
[0x80, "SHIFT_JIS"],
[0xE0, "SHIFT_JIS"],
[0x0100, "ISO-8859-9"],
[620, "TIS-620"],
[0xD800, "UTF-8"],
[0xDBFF, "UTF-8"],
[0xDC00, "UTF-8"],
[0xDFFF, "UTF-8"],
[0xD800, "UTF-16"],
[0xDBFF, "UTF-16"],
[0xDC00, "UTF-16"],
[0xDFFF, "UTF-16"],
].each do |integer, encoding_name|
-> { integer.chr(encoding_name) }.should raise_error(RangeError)
end
-> { 0x80.chr("US-ASCII") }.should raise_error(RangeError)
-> { 0x0100.chr("BINARY") }.should raise_error(RangeError)
-> { 0x0100.chr("EUC-JP") }.should raise_error(RangeError)
-> { 0xA1A0.chr("EUC-JP") }.should raise_error(RangeError)
-> { 0xA1.chr("EUC-JP") }.should raise_error(RangeError)
-> { 0x80.chr("SHIFT_JIS") }.should raise_error(RangeError)
-> { 0xE0.chr("SHIFT_JIS") }.should raise_error(RangeError)
-> { 0x0100.chr("ISO-8859-9") }.should raise_error(RangeError)
-> { 620.chr("TIS-620") }.should raise_error(RangeError)
# UTF-16 surrogate range
-> { 0xD800.chr("UTF-8") }.should raise_error(RangeError)
-> { 0xDBFF.chr("UTF-8") }.should raise_error(RangeError)
-> { 0xDC00.chr("UTF-8") }.should raise_error(RangeError)
-> { 0xDFFF.chr("UTF-8") }.should raise_error(RangeError)
# UTF-16 surrogate range
-> { 0xD800.chr("UTF-16") }.should raise_error(RangeError)
-> { 0xDBFF.chr("UTF-16") }.should raise_error(RangeError)
-> { 0xDC00.chr("UTF-16") }.should raise_error(RangeError)
-> { 0xDFFF.chr("UTF-16") }.should raise_error(RangeError)
end

it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do
Expand Down
5 changes: 5 additions & 0 deletions spec/ruby/core/integer/fdiv_spec.rb
Expand Up @@ -55,6 +55,11 @@
num.fdiv(den).should == -0.5555555555555556
end

it "rounds to the correct float for bignum denominators" do
1.fdiv(10**324).should == 0.0
1.fdiv(10**323).should == 1.0e-323
end

it "performs floating-point division between self and a Float" do
8.fdiv(9.0).should be_close(0.888888888888889, TOLERANCE)
end
Expand Down
14 changes: 2 additions & 12 deletions spec/ruby/core/io/advise_spec.rb
Expand Up @@ -73,19 +73,9 @@
end
end

platform_is :linux do
guard -> { platform_is :linux and kernel_version_is '3.6' } do # [ruby-core:65355] tmpfs is not supported
it "supports the willneed advice type" do
require 'etc'
uname = if Etc.respond_to?(:uname)
Etc.uname[:release]
else
`uname -r`.chomp
end
if (uname.split('.').map(&:to_i) <=> [3,6]) < 0
skip "[ruby-core:65355] tmpfs is not supported"
else
@io.advise(:willneed).should be_nil
end
@io.advise(:willneed).should be_nil
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/ruby/core/io/fixtures/classes.rb
Expand Up @@ -108,6 +108,14 @@ def self.lines_space_separator
"linha ", "cinco.\nHere ", "is ", "line ", "six.\n" ]
end

def self.lines_space_separator_without_trailing_spaces
[ "Voici", "la", "ligne", "une.\nQui",
"\303\250", "la", "linea", "due.\n\n\nAqu\303\255",
"est\303\241", "la", "l\303\255nea", "tres.\nHier",
"ist", "Zeile", "vier.\n\nEst\303\241", "aqui", "a",
"linha", "cinco.\nHere", "is", "line", "six.\n" ]
end

def self.lines_arbitrary_separator
[ "Voici la ligne une.\nQui \303\250",
" la linea due.\n\n\nAqu\303\255 est\303\241 la l\303\255nea tres.\nHier ist Zeile vier.\n\nEst\303\241 aqui a linha cinco.\nHere is line six.\n" ]
Expand All @@ -119,6 +127,12 @@ def self.paragraphs
"Est\303\241 aqui a linha cinco.\nHere is line six.\n" ]
end

def self.paragraphs_without_trailing_new_line_characters
[ "Voici la ligne une.\nQui \303\250 la linea due.",
"Aqu\303\255 est\303\241 la l\303\255nea tres.\nHier ist Zeile vier.",
"Est\303\241 aqui a linha cinco.\nHere is line six.\n" ]
end

# Creates an IO instance for an existing fixture file. The
# file should obviously not be deleted.
def self.io_fixture(name, mode = "r:utf-8")
Expand Down

0 comments on commit d3d5ef0

Please sign in to comment.