Skip to content

Commit 9327b8a

Browse files
committed
1 parent 283e646 commit 9327b8a

File tree

15 files changed

+217
-78
lines changed

15 files changed

+217
-78
lines changed

spec/ruby/.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Lint/DuplicateElsifCondition:
9999
Lint/OutOfRangeRegexpRef:
100100
Enabled: false
101101

102+
Lint/InheritException:
103+
Enabled: false
104+
102105
Lint/ElseLayout:
103106
Exclude:
104107
- 'language/if_spec.rb'

spec/ruby/.rubocop_todo.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ Lint/IneffectiveAccessModifier:
5050
- 'core/module/fixtures/classes.rb'
5151
- 'language/fixtures/private.rb'
5252

53-
# Offense count: 6
54-
# Cop supports --auto-correct.
55-
# Configuration parameters: EnforcedStyle.
56-
# SupportedStyles: runtime_error, standard_error
57-
Lint/InheritException:
58-
Exclude:
59-
- 'core/enumerator/lazy/fixtures/classes.rb'
60-
- 'core/exception/fixtures/common.rb'
61-
- 'core/module/fixtures/autoload_ex1.rb'
62-
- 'shared/kernel/raise.rb'
63-
6453
# Offense count: 72
6554
# Cop supports --auto-correct.
6655
Lint/LiteralInInterpolation:

spec/ruby/core/env/shared/update.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
ENV["bar"].should == "1"
1616
end
1717

18+
ruby_version_is "3.2" do
19+
it "adds the multiple parameter hashes to ENV, returning ENV" do
20+
ENV.send(@method, {"foo" => "0", "bar" => "1"}, {"baz" => "2"}).should equal(ENV)
21+
ENV["foo"].should == "0"
22+
ENV["bar"].should == "1"
23+
ENV["baz"].should == "2"
24+
end
25+
end
26+
1827
it "returns ENV when no block given" do
1928
ENV.send(@method, {"foo" => "0", "bar" => "1"}).should equal(ENV)
2029
end

spec/ruby/core/float/round_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
-4.809999999999999.round(5, half: :even).should eql(-4.81)
137137
end
138138

139-
ruby_bug "", ""..."3.2" do
139+
ruby_bug "", ""..."3.3" do
140140
# These numbers are neighbouring floating point numbers round a
141141
# precise value. They test that the rounding modes work correctly
142142
# round that value and precision is not lost which might cause

spec/ruby/core/io/shared/readlines.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
(result ? result : ScratchPad.recorded).should == IOSpecs.lines
8080
end
8181

82-
ruby_bug "#18767", ""..."3.2" do
82+
ruby_bug "#18767", ""..."3.3" do
8383
describe "when passed limit" do
8484
it "raises ArgumentError when passed 0 as a limit" do
8585
-> { IO.send(@method, @name, 0, &@object) }.should raise_error(ArgumentError)
@@ -256,4 +256,4 @@
256256
end
257257
end
258258
end
259-
end
259+
end

spec/ruby/core/math/ldexp_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
it "accepts any second argument that can be coerced with Integer()" do
4646
Math.ldexp(3.23, MathSpecs::Integer.new).should be_close(12.92, TOLERANCE)
4747
end
48+
49+
it "returns correct value that closes to the max value of double type" do
50+
Math.ldexp(0.5122058490966879, 1024).should == 9.207889385574391e+307
51+
Math.ldexp(0.9999999999999999, 1024).should == 1.7976931348623157e+308
52+
Math.ldexp(0.99999999999999999, 1024).should == Float::INFINITY
53+
end
4854
end
4955

5056
describe "Math#ldexp" do

spec/ruby/core/module/autoload_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,36 @@ class LexicalScope
577577
end
578578
end
579579

580+
ruby_version_is "3.2" do
581+
it "warns once in verbose mode if the constant was defined in a parent scope" do
582+
ScratchPad.record -> {
583+
ModuleSpecs::DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent
584+
}
585+
586+
module ModuleSpecs
587+
module Autoload
588+
autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
589+
self.autoload?(:DeclaredInCurrentDefinedInParent).should == fixture(__FILE__, "autoload_callback.rb")
590+
const_defined?(:DeclaredInCurrentDefinedInParent).should == true
591+
592+
-> {
593+
DeclaredInCurrentDefinedInParent
594+
}.should complain(
595+
/Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/,
596+
verbose: true,
597+
)
598+
599+
-> {
600+
DeclaredInCurrentDefinedInParent
601+
}.should_not complain(/.*/, verbose: true)
602+
self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
603+
const_defined?(:DeclaredInCurrentDefinedInParent).should == false
604+
ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true
605+
end
606+
end
607+
end
608+
end
609+
580610
ruby_version_is "3.1" do
581611
it "looks up in parent scope after failed autoload" do
582612
@remove << :DeclaredInCurrentDefinedInParent

spec/ruby/core/regexp/shared/new.rb

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ class RegexpSpecsSubclassTwo < Regexp; end
5858
end
5959
end
6060

61+
it "sets options from second argument if it is true" do
62+
r = Regexp.send(@method, 'Hi', true)
63+
(r.options & Regexp::IGNORECASE).should_not == 0
64+
(r.options & Regexp::MULTILINE).should == 0
65+
not_supported_on :opal do
66+
(r.options & Regexp::EXTENDED).should == 0
67+
end
68+
end
69+
6170
it "sets options from second argument if it is one of the Integer option constants" do
6271
r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE)
6372
(r.options & Regexp::IGNORECASE).should_not == 0
@@ -88,12 +97,67 @@ class RegexpSpecsSubclassTwo < Regexp; end
8897
(r.options & Regexp::EXTENDED).should_not == 0
8998
end
9099

91-
it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do
92-
r = Regexp.send(@method, 'Hi', Object.new)
93-
(r.options & Regexp::IGNORECASE).should_not == 0
94-
(r.options & Regexp::MULTILINE).should == 0
95-
not_supported_on :opal do
96-
(r.options & Regexp::EXTENDED).should == 0
100+
ruby_version_is ""..."3.2" do
101+
it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do
102+
r = Regexp.send(@method, 'Hi', Object.new)
103+
(r.options & Regexp::IGNORECASE).should_not == 0
104+
(r.options & Regexp::MULTILINE).should == 0
105+
not_supported_on :opal do
106+
(r.options & Regexp::EXTENDED).should == 0
107+
end
108+
end
109+
end
110+
111+
ruby_version_is "3.2" do
112+
it "warns any non-Integer, non-nil, non-false second argument" do
113+
r = nil
114+
-> {
115+
r = Regexp.send(@method, 'Hi', Object.new)
116+
}.should complain(/expected true or false as ignorecase/, {verbose: true})
117+
(r.options & Regexp::IGNORECASE).should_not == 0
118+
(r.options & Regexp::MULTILINE).should == 0
119+
not_supported_on :opal do
120+
(r.options & Regexp::EXTENDED).should == 0
121+
end
122+
end
123+
124+
it "accepts a String of supported flags as the second argument" do
125+
r = Regexp.send(@method, 'Hi', 'i')
126+
(r.options & Regexp::IGNORECASE).should_not == 0
127+
(r.options & Regexp::MULTILINE).should == 0
128+
not_supported_on :opal do
129+
(r.options & Regexp::EXTENDED).should == 0
130+
end
131+
132+
r = Regexp.send(@method, 'Hi', 'imx')
133+
(r.options & Regexp::IGNORECASE).should_not == 0
134+
(r.options & Regexp::MULTILINE).should_not == 0
135+
not_supported_on :opal do
136+
(r.options & Regexp::EXTENDED).should_not == 0
137+
end
138+
139+
r = Regexp.send(@method, 'Hi', 'mimi')
140+
(r.options & Regexp::IGNORECASE).should_not == 0
141+
(r.options & Regexp::MULTILINE).should_not == 0
142+
not_supported_on :opal do
143+
(r.options & Regexp::EXTENDED).should == 0
144+
end
145+
146+
r = Regexp.send(@method, 'Hi', '')
147+
(r.options & Regexp::IGNORECASE).should == 0
148+
(r.options & Regexp::MULTILINE).should == 0
149+
not_supported_on :opal do
150+
(r.options & Regexp::EXTENDED).should == 0
151+
end
152+
end
153+
154+
it "raises an Argument error if the second argument contains unsupported chars" do
155+
-> { Regexp.send(@method, 'Hi', 'e') }.should raise_error(ArgumentError)
156+
-> { Regexp.send(@method, 'Hi', 'n') }.should raise_error(ArgumentError)
157+
-> { Regexp.send(@method, 'Hi', 's') }.should raise_error(ArgumentError)
158+
-> { Regexp.send(@method, 'Hi', 'u') }.should raise_error(ArgumentError)
159+
-> { Regexp.send(@method, 'Hi', 'j') }.should raise_error(ArgumentError)
160+
-> { Regexp.send(@method, 'Hi', 'mjx') }.should raise_error(ArgumentError)
97161
end
98162
end
99163

spec/ruby/core/string/dedup_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'shared/dedup'
3+
4+
describe 'String#dedup' do
5+
ruby_version_is '3.2'do
6+
it_behaves_like :string_dedup, :dedup
7+
end
8+
end

spec/ruby/core/string/shared/dedup.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
describe :string_dedup, shared: true do
2+
it 'returns self if the String is frozen' do
3+
input = 'foo'.freeze
4+
output = input.send(@method)
5+
6+
output.should equal(input)
7+
output.should.frozen?
8+
end
9+
10+
it 'returns a frozen copy if the String is not frozen' do
11+
input = 'foo'
12+
output = input.send(@method)
13+
14+
output.should.frozen?
15+
output.should_not equal(input)
16+
output.should == 'foo'
17+
end
18+
19+
it "returns the same object for equal unfrozen strings" do
20+
origin = "this is a string"
21+
dynamic = %w(this is a string).join(' ')
22+
23+
origin.should_not equal(dynamic)
24+
origin.send(@method).should equal(dynamic.send(@method))
25+
end
26+
27+
it "returns the same object when it's called on the same String literal" do
28+
"unfrozen string".send(@method).should equal("unfrozen string".send(@method))
29+
"unfrozen string".send(@method).should_not equal("another unfrozen string".send(@method))
30+
end
31+
32+
it "deduplicates frozen strings" do
33+
dynamic = %w(this string is frozen).join(' ').freeze
34+
35+
dynamic.should_not equal("this string is frozen".freeze)
36+
37+
dynamic.send(@method).should equal("this string is frozen".freeze)
38+
dynamic.send(@method).should equal("this string is frozen".send(@method).freeze)
39+
end
40+
41+
ruby_version_is "3.0" do
42+
it "interns the provided string if it is frozen" do
43+
dynamic = "this string is unique and frozen #{rand}".freeze
44+
dynamic.send(@method).should equal(dynamic)
45+
end
46+
end
47+
end

0 commit comments

Comments
 (0)