mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@d419e74
This commit is contained in:
parent
26a9f80c82
commit
a2fac1d72c
44 changed files with 772 additions and 514 deletions
|
@ -10,7 +10,7 @@ AllCops:
|
|||
Layout/TrailingWhitespace:
|
||||
Enabled: true
|
||||
|
||||
Layout/TrailingBlankLines:
|
||||
Layout/TrailingEmptyLines:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
- library/coverage/fixtures/some_class.rb
|
||||
|
@ -34,10 +34,10 @@ Lint/InterpolationCheck:
|
|||
Lint/LiteralAsCondition:
|
||||
Enabled: false
|
||||
|
||||
Lint/UnneededRequireStatement:
|
||||
Lint/RedundantRequireStatement:
|
||||
Enabled: false
|
||||
|
||||
Lint/UnneededSplatExpansion:
|
||||
Lint/RedundantSplatExpansion:
|
||||
Enabled: false
|
||||
|
||||
Lint/UnifiedInteger:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config`
|
||||
# on 2018-04-03 22:23:59 +0900 using RuboCop version 0.54.0.
|
||||
# on 2019-12-12 22:16:26 +0900 using RuboCop version 0.77.0.
|
||||
# The point is for the user to remove these configuration records
|
||||
# one by one as the offenses are removed from the code base.
|
||||
# Note that changes in the inspected code, or installation of new
|
||||
|
@ -20,22 +20,24 @@ Lint/DuplicateMethods:
|
|||
- 'core/unboundmethod/fixtures/classes.rb'
|
||||
- 'fixtures/class.rb'
|
||||
|
||||
# Offense count: 5
|
||||
# Offense count: 8
|
||||
Lint/EnsureReturn:
|
||||
Exclude:
|
||||
- 'language/fixtures/ensure.rb'
|
||||
- 'language/fixtures/return.rb'
|
||||
- 'language/return_spec.rb'
|
||||
|
||||
# Offense count: 10
|
||||
Lint/FlipFlop:
|
||||
Exclude:
|
||||
- 'language/if_spec.rb'
|
||||
- 'language/precedence_spec.rb'
|
||||
|
||||
# Offense count: 10
|
||||
Lint/FloatOutOfRange:
|
||||
Exclude:
|
||||
- 'core/string/modulo_spec.rb'
|
||||
|
||||
# Offense count: 29
|
||||
Lint/HandleExceptions:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
Lint/ImplicitStringConcatenation:
|
||||
Exclude:
|
||||
|
@ -58,13 +60,19 @@ Lint/InheritException:
|
|||
- 'core/exception/fixtures/common.rb'
|
||||
- 'core/module/fixtures/autoload_ex1.rb'
|
||||
|
||||
# Offense count: 5
|
||||
# Offense count: 72
|
||||
# Cop supports --auto-correct.
|
||||
Lint/LiteralInInterpolation:
|
||||
Exclude:
|
||||
- 'core/module/refine_spec.rb'
|
||||
- 'core/regexp/shared/new.rb'
|
||||
- 'core/string/shared/to_sym.rb'
|
||||
- 'language/alias_spec.rb'
|
||||
- 'language/defined_spec.rb'
|
||||
- 'language/fixtures/squiggly_heredoc.rb'
|
||||
- 'language/symbol_spec.rb'
|
||||
- 'language/undef_spec.rb'
|
||||
- 'library/net/ftp/connect_spec.rb'
|
||||
|
||||
# Offense count: 16
|
||||
Lint/Loop:
|
||||
|
@ -74,11 +82,11 @@ Lint/Loop:
|
|||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
Lint/MultipleCompare:
|
||||
Lint/MultipleComparison:
|
||||
Exclude:
|
||||
- 'language/precedence_spec.rb'
|
||||
|
||||
# Offense count: 12
|
||||
# Offense count: 9
|
||||
Lint/ParenthesesAsGroupedExpression:
|
||||
Exclude:
|
||||
- 'core/string/fixtures/freeze_magic_comment.rb'
|
||||
|
@ -86,13 +94,19 @@ Lint/ParenthesesAsGroupedExpression:
|
|||
- 'language/fixtures/send.rb'
|
||||
- 'language/method_spec.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Lint/RedundantStringCoercion:
|
||||
Exclude:
|
||||
- 'core/io/print_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Lint/RedundantWithIndex:
|
||||
Exclude:
|
||||
- 'core/enumerator/with_index_spec.rb'
|
||||
|
||||
# Offense count: 26
|
||||
# Offense count: 22
|
||||
Lint/RescueException:
|
||||
Exclude:
|
||||
- 'command_line/fixtures/debug_info.rb'
|
||||
|
@ -102,27 +116,24 @@ Lint/RescueException:
|
|||
- 'core/kernel/fixtures/autoload_frozen.rb'
|
||||
- 'core/module/autoload_spec.rb'
|
||||
- 'core/mutex/sleep_spec.rb'
|
||||
- 'core/process/euid_spec.rb'
|
||||
- 'core/process/setsid_spec.rb'
|
||||
- 'core/process/uid_spec.rb'
|
||||
- 'core/thread/abort_on_exception_spec.rb'
|
||||
- 'core/thread/shared/exit.rb'
|
||||
- 'language/rescue_spec.rb'
|
||||
- 'library/erb/filename_spec.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Offense count: 4
|
||||
# Configuration parameters: IgnoreImplicitReferences.
|
||||
Lint/ShadowedArgument:
|
||||
Exclude:
|
||||
- 'language/fixtures/super.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Lint/StringConversionInInterpolation:
|
||||
Exclude:
|
||||
- 'core/io/print_spec.rb'
|
||||
# Offense count: 39
|
||||
# Configuration parameters: AllowComments.
|
||||
Lint/SuppressedException:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 9
|
||||
# Configuration parameters: AllowKeywordBlockArguments.
|
||||
Lint/UnderscorePrefixedVariableName:
|
||||
Exclude:
|
||||
- 'core/io/pipe_spec.rb'
|
||||
|
@ -137,13 +148,4 @@ Lint/UselessAccessModifier:
|
|||
- 'core/module/fixtures/classes.rb'
|
||||
- 'core/module/module_function_spec.rb'
|
||||
- 'core/module/private_class_method_spec.rb'
|
||||
- 'core/module/private_spec.rb'
|
||||
- 'core/module/protected_spec.rb'
|
||||
- 'core/module/public_spec.rb'
|
||||
- 'language/fixtures/send.rb'
|
||||
|
||||
# Offense count: 6186
|
||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||
# URISchemes: http, https
|
||||
Metrics/LineLength:
|
||||
Max: 588
|
||||
|
|
|
@ -34,6 +34,12 @@ describe "RUBY_PLATFORM" do
|
|||
it "is a String" do
|
||||
RUBY_PLATFORM.should be_kind_of(String)
|
||||
end
|
||||
|
||||
platform_is :darwin do
|
||||
it 'ends with the build time kernel major version on darwin' do
|
||||
RUBY_PLATFORM.should =~ /-darwin\d+$/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "RUBY_RELEASE_DATE" do
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/common'
|
||||
|
||||
describe "SystemCallError#errno" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
||||
describe "Errno::EINVAL.new" do
|
||||
it "can be called with no arguments" do
|
||||
exc = Errno::EINVAL.new
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "LocalJumpError#exit_value" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
def get_me_a_return
|
||||
Proc.new { return 42 }
|
||||
end
|
||||
-> { get_me_a_return.call }.should raise_error(LocalJumpError) { |e|
|
||||
e.exit_value.should == 42
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "FrozenError" do
|
||||
ruby_version_is "2.5" do
|
||||
it "is a subclass of RuntimeError" do
|
||||
RuntimeError.should be_ancestor_of(FrozenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "FrozenError.new" do
|
||||
ruby_version_is "2.7" do
|
||||
it "should take optional receiver argument" do
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
-> {"abc\xa4def".encode("ISO-8859-1", "EUC-JP") }.should raise_error(Encoding::InvalidByteSequenceError) { |e|
|
||||
e.incomplete_input?.should == false
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "IOError" do
|
||||
it "is a superclass of EOFError" do
|
||||
IOError.should be_ancestor_of(EOFError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "IO::EAGAINWaitReadable" do
|
||||
it "combines Errno::EAGAIN and IO::WaitReadable" do
|
||||
IO::EAGAINWaitReadable.superclass.should == Errno::EAGAIN
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "NameError" do
|
||||
it "is a superclass of NoMethodError" do
|
||||
NameError.should be_ancestor_of(NoMethodError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "NameError.new" do
|
||||
it "should take optional name argument" do
|
||||
NameError.new("msg","name").name.should == "name"
|
||||
|
@ -22,3 +16,15 @@ describe "NameError.new" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "NameError#dup" do
|
||||
it "copies the name and receiver" do
|
||||
begin
|
||||
foo
|
||||
rescue NameError => ne
|
||||
name_error_dup = ne.dup
|
||||
name_error_dup.name.should == :foo
|
||||
name_error_dup.receiver.should == self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,3 +104,17 @@ describe "NoMethodError#message" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "NoMethodError#dup" do
|
||||
it "copies the name, arguments and receiver" do
|
||||
begin
|
||||
receiver = Object.new
|
||||
receiver.foo(:one, :two)
|
||||
rescue NoMethodError => nme
|
||||
no_method_error_dup = nme.dup
|
||||
no_method_error_dup.name.should == :foo
|
||||
no_method_error_dup.receiver.should == receiver
|
||||
no_method_error_dup.args.should == [:one, :two]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "RangeError" do
|
||||
it "is a superclass of FloatDomainError" do
|
||||
RangeError.should be_ancestor_of(FloatDomainError)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,10 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "LocalJumpError#reason" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
def get_me_a_return
|
||||
Proc.new { return 42 }
|
||||
end
|
||||
-> { get_me_a_return.call }.should raise_error(LocalJumpError) { |e|
|
||||
e.reason.should == :return
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "StopIteration" do
|
||||
it "is a subclass of IndexError" do
|
||||
StopIteration.superclass.should equal(IndexError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "StopIteration#result" do
|
||||
before :each do
|
||||
obj = Object.new
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "SignalException#signm" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
it "returns the signal name" do
|
||||
-> { Process.kill(:TERM, Process.pid) }.should raise_error(SignalException) { |e|
|
||||
e.signm.should == 'SIGTERM'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "SignalException#signo" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
it "returns the signal number" do
|
||||
-> { Process.kill(:TERM, Process.pid) }.should raise_error(SignalException) { |e|
|
||||
e.signo.should == Signal.list['TERM']
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "SystemExit#status" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
it "returns the exit status" do
|
||||
-> { exit 42 }.should raise_error(SystemExit) { |e|
|
||||
e.status.should == 42
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "SystemExit#success?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
it "returns true if the process exited successfully" do
|
||||
-> { exit 0 }.should raise_error(SystemExit) { |e|
|
||||
e.success?.should == true
|
||||
}
|
||||
end
|
||||
|
||||
it "returns false if the process exited unsuccessfully" do
|
||||
-> { exit(-1) }.should raise_error(SystemExit) { |e|
|
||||
e.success?.should == false
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -128,3 +128,16 @@ describe "SystemCallError#message" do
|
|||
SystemCallError.new("XXX").message.should =~ /XXX/
|
||||
end
|
||||
end
|
||||
|
||||
describe "SystemCallError#dup" do
|
||||
it "copies the errno" do
|
||||
dup_sce = SystemCallError.new("message", 42).dup
|
||||
dup_sce.errno.should == 42
|
||||
end
|
||||
end
|
||||
|
||||
describe "SystemCallError#backtrace" do
|
||||
it "is nil if not raised" do
|
||||
SystemCallError.new("message", 42).backtrace.should == nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "SystemStackError" do
|
||||
it "is a subclass of Exception" do
|
||||
SystemStackError.superclass.should == Exception
|
||||
end
|
||||
end
|
|
@ -1,11 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "UncaughtThrowError" do
|
||||
it "is a subclass of ArgumentError" do
|
||||
ArgumentError.should be_ancestor_of(UncaughtThrowError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "UncaughtThrowError#tag" do
|
||||
it "returns the object thrown" do
|
||||
begin
|
||||
|
|
|
@ -5,4 +5,8 @@ describe "GC.start" do
|
|||
GC.start.should == nil
|
||||
GC.start.should == nil
|
||||
end
|
||||
|
||||
it "accepts keyword arguments" do
|
||||
GC.start(full_mark: true, immediate_sweep: true).should == nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,6 @@ describe "Kernel#printf" do
|
|||
end
|
||||
|
||||
describe "Kernel.printf" do
|
||||
|
||||
before :each do
|
||||
@stdout = $stdout
|
||||
@name = tmp("kernel_puts.txt")
|
||||
|
@ -38,7 +37,7 @@ describe "Kernel.printf" do
|
|||
context "io is specified" do
|
||||
it_behaves_like :kernel_sprintf, -> format, *args {
|
||||
io = StringIO.new
|
||||
printf(io, format, *args)
|
||||
Kernel.printf(io, format, *args)
|
||||
io.string
|
||||
}
|
||||
end
|
||||
|
@ -49,7 +48,7 @@ describe "Kernel.printf" do
|
|||
|
||||
begin
|
||||
$stdout = io = StringIO.new
|
||||
printf(format, *args)
|
||||
Kernel.printf(format, *args)
|
||||
io.string
|
||||
ensure
|
||||
$stdout = stdout
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,19 @@
|
|||
describe :kernel_sprintf_encoding, shared: true do
|
||||
def format(*args)
|
||||
@method.call(*args)
|
||||
it "can produce a string with valid encoding" do
|
||||
string = @method.call("good day %{valid}", valid: "e")
|
||||
string.encoding.should == Encoding::UTF_8
|
||||
string.valid_encoding?.should be_true
|
||||
end
|
||||
|
||||
it "can produce a string with invalid encoding" do
|
||||
string = @method.call("good day %{invalid}", invalid: "\x80")
|
||||
string.encoding.should == Encoding::UTF_8
|
||||
string.valid_encoding?.should be_false
|
||||
end
|
||||
|
||||
it "returns a String in the same encoding as the format String if compatible" do
|
||||
string = "%s".force_encoding(Encoding::KOI8_U)
|
||||
result = format(string, "dogs")
|
||||
result = @method.call(string, "dogs")
|
||||
result.encoding.should equal(Encoding::KOI8_U)
|
||||
end
|
||||
|
||||
|
@ -13,7 +21,7 @@ describe :kernel_sprintf_encoding, shared: true do
|
|||
string = "foo %s".force_encoding(Encoding::US_ASCII)
|
||||
argument = "b\303\274r".force_encoding(Encoding::UTF_8)
|
||||
|
||||
result = format(string, argument)
|
||||
result = @method.call(string, argument)
|
||||
result.encoding.should equal(Encoding::UTF_8)
|
||||
end
|
||||
|
||||
|
@ -22,7 +30,7 @@ describe :kernel_sprintf_encoding, shared: true do
|
|||
argument = "Ђ".encode('windows-1251')
|
||||
|
||||
-> {
|
||||
format(string, argument)
|
||||
@method.call(string, argument)
|
||||
}.should raise_error(Encoding::CompatibilityError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,6 +38,22 @@ ruby_version_is "2.6" do
|
|||
(f << g).lambda?.should == false
|
||||
end
|
||||
|
||||
it "is a Proc when other is lambda" do
|
||||
f = proc { |x| x * x }
|
||||
g = -> x { x + x }
|
||||
|
||||
(f << g).is_a?(Proc).should == true
|
||||
(f << g).lambda?.should == false
|
||||
end
|
||||
|
||||
it "is a lambda when self is lambda" do
|
||||
f = -> x { x * x }
|
||||
g = proc { |x| x + x }
|
||||
|
||||
(f << g).is_a?(Proc).should == true
|
||||
(f << g).lambda?.should == true
|
||||
end
|
||||
|
||||
it "may accept multiple arguments" do
|
||||
inc = proc { |n| n + 1 }
|
||||
mul = proc { |n, m| n * m }
|
||||
|
@ -91,6 +107,22 @@ ruby_version_is "2.6" do
|
|||
(f >> g).lambda?.should == false
|
||||
end
|
||||
|
||||
it "is a Proc when other is lambda" do
|
||||
f = proc { |x| x * x }
|
||||
g = -> x { x + x }
|
||||
|
||||
(f >> g).is_a?(Proc).should == true
|
||||
(f >> g).lambda?.should == false
|
||||
end
|
||||
|
||||
it "is a lambda when self is lambda" do
|
||||
f = -> x { x * x }
|
||||
g = proc { |x| x + x }
|
||||
|
||||
(f >> g).is_a?(Proc).should == true
|
||||
(f >> g).lambda?.should == true
|
||||
end
|
||||
|
||||
it "may accept multiple arguments" do
|
||||
inc = proc { |n| n + 1 }
|
||||
mul = proc { |n, m| n * m }
|
||||
|
|
|
@ -319,6 +319,10 @@ describe "String#inspect" do
|
|||
0.chr.inspect.should == '"\\x00"'
|
||||
end
|
||||
|
||||
it "uses \\x notation for broken UTF-8 sequences" do
|
||||
"\xF0\x9F".inspect.should == '"\\xF0\\x9F"'
|
||||
end
|
||||
|
||||
describe "when default external is UTF-8" do
|
||||
before :each do
|
||||
@extenc, Encoding.default_external = Encoding.default_external, Encoding::UTF_8
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative '../kernel/shared/sprintf'
|
||||
require_relative '../kernel/shared/sprintf_encoding'
|
||||
require_relative 'fixtures/classes'
|
||||
require_relative '../../shared/hash/key_error'
|
||||
|
||||
describe "String#%" do
|
||||
it_behaves_like :kernel_sprintf, -> format, *args {
|
||||
format % args
|
||||
}
|
||||
|
||||
it_behaves_like :kernel_sprintf_encoding, -> format, *args {
|
||||
format % args
|
||||
}
|
||||
end
|
||||
|
||||
# TODO: these specs are mostly redundant with kernel/shared/sprintf.rb specs.
|
||||
# These specs should be moved there and deduplicated.
|
||||
describe "String#%" do
|
||||
context "when key is missing from passed-in hash" do
|
||||
it_behaves_like :key_error, -> obj, key { "%{#{key}}" % obj }, { a: 5 }
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative '../kernel/shared/sprintf'
|
||||
require_relative '../kernel/shared/sprintf_encoding'
|
||||
|
||||
describe "String#%" do
|
||||
it_behaves_like :kernel_sprintf, -> format, *args {
|
||||
format % args
|
||||
}
|
||||
|
||||
it_behaves_like :kernel_sprintf_encoding, -> format, *args {
|
||||
format % args
|
||||
}
|
||||
end
|
|
@ -38,4 +38,9 @@ describe "Symbol#to_proc" do
|
|||
end
|
||||
klass.new.to_proc.should == :value
|
||||
end
|
||||
|
||||
it "produces a proc with source location nil" do
|
||||
pr = :to_s.to_proc
|
||||
pr.source_location.should == nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,11 +4,13 @@ describe :thread_to_s, shared: true do
|
|||
sep = ruby_version_is("2.7") ? " " : "@"
|
||||
|
||||
it "returns a description including file and line number" do
|
||||
Thread.new { "hello" }.send(@method).should =~ /^#<Thread:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ } \w+>$/
|
||||
thread, line = Thread.new { "hello" }, __LINE__
|
||||
thread.join
|
||||
thread.send(@method).should =~ /^#<Thread:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{line} \w+>$/
|
||||
end
|
||||
|
||||
it "has a binary encoding" do
|
||||
Thread.new { "hello" }.send(@method).encoding.should == Encoding::BINARY
|
||||
ThreadSpecs.status_of_current_thread.send(@method).encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "can check it's own status" do
|
||||
|
|
15
spec/ruby/language/END_spec.rb
Normal file
15
spec/ruby/language/END_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe "The END keyword" do
|
||||
it "runs only once for multiple calls" do
|
||||
ruby_exe("10.times { END { puts 'foo' }; } ").should == "foo\n"
|
||||
end
|
||||
|
||||
it "runs last in a given code unit" do
|
||||
ruby_exe("END { puts 'bar' }; puts'foo'; ").should == "foo\nbar\n"
|
||||
end
|
||||
|
||||
it "runs multiple ends in LIFO order" do
|
||||
ruby_exe("END { puts 'foo' }; END { puts 'bar' }").should == "bar\nfoo\n"
|
||||
end
|
||||
end
|
|
@ -46,6 +46,12 @@ describe "Kernel#BigDecimal" do
|
|||
BigDecimal(" \t\n \r-Infinity \n").infinite?.should == -1
|
||||
end
|
||||
|
||||
it "coerces the value argument with #to_str" do
|
||||
initial = mock("value")
|
||||
initial.should_receive(:to_str).and_return("123")
|
||||
BigDecimal(initial).should == BigDecimal("123")
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.6" do
|
||||
it "ignores trailing garbage" do
|
||||
BigDecimal("123E45ruby").should == BigDecimal("123E45")
|
||||
|
|
|
@ -41,6 +41,7 @@ describe "BigDecimal#to_s" do
|
|||
|
||||
str1 = '-123.45678 90123 45678 9'
|
||||
BigDecimal("-123.45678901234567890").to_s('5F').should == str1
|
||||
BigDecimal('1000010').to_s('5F').should == "10000 10.0"
|
||||
# trailing zeroes removed
|
||||
BigDecimal("1.00000000000").to_s('1F').should == "1.0"
|
||||
# 0 is treated as no spaces
|
||||
|
|
|
@ -32,6 +32,50 @@ describe "ConditionVariable#wait" do
|
|||
th.join
|
||||
end
|
||||
|
||||
it "can be interrupted by Thread#run" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
in_synchronize = false
|
||||
|
||||
th = Thread.new do
|
||||
m.synchronize do
|
||||
in_synchronize = true
|
||||
cv.wait(m)
|
||||
end
|
||||
:success
|
||||
end
|
||||
|
||||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
|
||||
th.run
|
||||
th.value.should == :success
|
||||
end
|
||||
|
||||
it "can be interrupted by Thread#wakeup" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
in_synchronize = false
|
||||
|
||||
th = Thread.new do
|
||||
m.synchronize do
|
||||
in_synchronize = true
|
||||
cv.wait(m)
|
||||
end
|
||||
:success
|
||||
end
|
||||
|
||||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
|
||||
th.wakeup
|
||||
th.value.should == :success
|
||||
end
|
||||
|
||||
it "reacquires the lock even if the thread is killed" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
|
|
|
@ -479,4 +479,14 @@ describe "C-API Encoding function" do
|
|||
length.should == 4
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_enc_str_asciionly_p" do
|
||||
it "returns true for an ASCII string" do
|
||||
@s.rb_enc_str_asciionly_p("hello").should be_true
|
||||
end
|
||||
|
||||
it "returns false for a non-ASCII string" do
|
||||
@s.rb_enc_str_asciionly_p("hüllo").should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -196,6 +196,14 @@ static VALUE encoding_spec_rb_enc_codepoint_len(VALUE self, VALUE str) {
|
|||
return rb_ary_new3(2, LONG2NUM(codepoint), LONG2NUM(len));
|
||||
}
|
||||
|
||||
static VALUE encoding_spec_rb_enc_str_asciionly_p(VALUE self, VALUE str) {
|
||||
if (rb_enc_str_asciionly_p(str)) {
|
||||
return Qtrue;
|
||||
} else {
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
void Init_encoding_spec(void) {
|
||||
VALUE cls = rb_define_class("CApiEncodingSpecs", rb_cObject);
|
||||
rb_define_method(cls, "ENC_CODERANGE_ASCIIONLY",
|
||||
|
@ -242,6 +250,7 @@ void Init_encoding_spec(void) {
|
|||
rb_define_method(cls, "rb_to_encoding_index", encoding_spec_rb_to_encoding_index, 1);
|
||||
rb_define_method(cls, "rb_enc_nth", encoding_spec_rb_enc_nth, 2);
|
||||
rb_define_method(cls, "rb_enc_codepoint_len", encoding_spec_rb_enc_codepoint_len, 1);
|
||||
rb_define_method(cls, "rb_enc_str_asciionly_p", encoding_spec_rb_enc_str_asciionly_p, 1);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -34,6 +34,11 @@ static VALUE gc_spec_rb_gc_adjust_memory_usage(VALUE self, VALUE diff) {
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE gc_spec_rb_gc_register_mark_object(VALUE self, VALUE obj) {
|
||||
rb_gc_register_mark_object(obj);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void Init_gc_spec(void) {
|
||||
VALUE cls = rb_define_class("CApiGCSpecs", rb_cObject);
|
||||
registered_tagged_value = INT2NUM(10);
|
||||
|
@ -48,6 +53,7 @@ void Init_gc_spec(void) {
|
|||
rb_define_method(cls, "rb_gc_disable", gc_spec_rb_gc_disable, 0);
|
||||
rb_define_method(cls, "rb_gc", gc_spec_rb_gc, 0);
|
||||
rb_define_method(cls, "rb_gc_adjust_memory_usage", gc_spec_rb_gc_adjust_memory_usage, 1);
|
||||
rb_define_method(cls, "rb_gc_register_mark_object", gc_spec_rb_gc_register_mark_object, 1);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -113,6 +113,15 @@ VALUE hash_spec_rb_hash_set_ifnone(VALUE self, VALUE hash, VALUE def) {
|
|||
return rb_hash_set_ifnone(hash, def);
|
||||
}
|
||||
|
||||
VALUE hash_spec_compute_a_hash_code(VALUE self, VALUE seed) {
|
||||
int int_seed = FIX2INT(seed);
|
||||
st_index_t h = rb_hash_start(int_seed);
|
||||
h = rb_hash_uint32(h, 540u);
|
||||
h = rb_hash_uint32(h, 340u);
|
||||
h = rb_hash_end(h);
|
||||
return ULONG2NUM(h);
|
||||
}
|
||||
|
||||
void Init_hash_spec(void) {
|
||||
VALUE cls = rb_define_class("CApiHashSpecs", rb_cObject);
|
||||
rb_define_method(cls, "rb_hash", hash_spec_rb_hash, 1);
|
||||
|
@ -136,6 +145,7 @@ void Init_hash_spec(void) {
|
|||
rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0);
|
||||
rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1);
|
||||
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);
|
||||
rb_define_method(cls, "compute_a_hash_code", hash_spec_compute_a_hash_code, 1);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -201,6 +201,19 @@ VALUE io_spec_rb_io_close(VALUE self, VALUE io) {
|
|||
return rb_io_close(io);
|
||||
}
|
||||
|
||||
VALUE io_spec_rb_io_set_nonblock(VALUE self, VALUE io) {
|
||||
rb_io_t* fp;
|
||||
int flags;
|
||||
GetOpenFile(io, fp);
|
||||
rb_io_set_nonblock(fp);
|
||||
#ifdef F_GETFL
|
||||
flags = fcntl(fp->fd, F_GETFL, 0);
|
||||
return flags & O_NONBLOCK ? Qtrue : Qfalse;
|
||||
#else
|
||||
return Qfalse;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* this is needed to ensure rb_io_wait_*able functions behave
|
||||
* predictably because errno may be set to unexpected values
|
||||
|
@ -225,6 +238,7 @@ void Init_io_spec(void) {
|
|||
rb_define_method(cls, "rb_io_check_readable", io_spec_rb_io_check_readable, 1);
|
||||
rb_define_method(cls, "rb_io_check_writable", io_spec_rb_io_check_writable, 1);
|
||||
rb_define_method(cls, "rb_io_check_closed", io_spec_rb_io_check_closed, 1);
|
||||
rb_define_method(cls, "rb_io_set_nonblock", io_spec_rb_io_set_nonblock, 1);
|
||||
rb_define_method(cls, "rb_io_taint_check", io_spec_rb_io_taint_check, 1);
|
||||
rb_define_method(cls, "rb_io_wait_readable", io_spec_rb_io_wait_readable, 2);
|
||||
rb_define_method(cls, "rb_io_wait_writable", io_spec_rb_io_wait_writable, 1);
|
||||
|
|
|
@ -51,6 +51,10 @@ VALUE symbol_spec_rb_intern_str(VALUE self, VALUE str) {
|
|||
return ID2SYM(rb_intern_str(str));
|
||||
}
|
||||
|
||||
VALUE symbol_spec_rb_check_symbol_cstr(VALUE self, VALUE str) {
|
||||
return rb_check_symbol_cstr(RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
|
||||
}
|
||||
|
||||
VALUE symbol_spec_rb_is_class_id(VALUE self, VALUE sym) {
|
||||
return rb_is_class_id(SYM2ID(sym)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
@ -79,6 +83,7 @@ void Init_symbol_spec(void) {
|
|||
rb_define_method(cls, "rb_id2name", symbol_spec_rb_id2name, 1);
|
||||
rb_define_method(cls, "rb_id2str", symbol_spec_rb_id2str, 1);
|
||||
rb_define_method(cls, "rb_intern_str", symbol_spec_rb_intern_str, 1);
|
||||
rb_define_method(cls, "rb_check_symbol_cstr", symbol_spec_rb_check_symbol_cstr, 1);
|
||||
rb_define_method(cls, "rb_is_class_id", symbol_spec_rb_is_class_id, 1);
|
||||
rb_define_method(cls, "rb_is_const_id", symbol_spec_rb_is_const_id, 1);
|
||||
rb_define_method(cls, "rb_is_instance_id", symbol_spec_rb_is_instance_id, 1);
|
||||
|
|
|
@ -58,4 +58,10 @@ describe "CApiGCSpecs" do
|
|||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_gc_register_mark_object" do
|
||||
it "can be called with an object" do
|
||||
@f.rb_gc_register_mark_object(Object.new).should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -254,4 +254,13 @@ describe "C-API Hash function" do
|
|||
-> { @s.rb_Hash(h) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "hash code functions" do
|
||||
it "computes a deterministic number" do
|
||||
hash_code = @s.compute_a_hash_code(53)
|
||||
hash_code.should be_an_instance_of(Integer)
|
||||
hash_code.should == @s.compute_a_hash_code(53)
|
||||
@s.compute_a_hash_code(90) == @s.compute_a_hash_code(90)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -151,6 +151,16 @@ describe "C-API IO function" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "rb_io_set_nonblock" do
|
||||
platform_is_not :windows do
|
||||
it "returns true when nonblock flag is set" do
|
||||
require 'io/nonblock'
|
||||
@o.rb_io_set_nonblock(@io)
|
||||
@io.nonblock?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# NOTE: unlike the name might suggest in MRI this function checks if an
|
||||
# object is frozen, *not* if it's tainted.
|
||||
describe "rb_io_taint_check" do
|
||||
|
|
|
@ -71,6 +71,19 @@ describe "C-API Symbol function" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "rb_check_symbol_cstr" do
|
||||
it "returns a Symbol if a Symbol already exists for the given C string" do
|
||||
sym = :test_symbol
|
||||
@s.rb_check_symbol_cstr('test_symbol').should == sym
|
||||
end
|
||||
|
||||
it "returns nil if the Symbol does not exist yet and does not create it" do
|
||||
str = "symbol_does_not_exist_#{Object.new.object_id}_#{rand}"
|
||||
@s.rb_check_symbol_cstr(str).should == nil # does not create the Symbol
|
||||
@s.rb_check_symbol_cstr(str).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_is_const_id" do
|
||||
it "returns true given a const-like symbol" do
|
||||
@s.rb_is_const_id(:Foo).should == true
|
||||
|
|
Loading…
Reference in a new issue