Skip to content

Commit 6582df2

Browse files
committed
1 parent 44f4241 commit 6582df2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+526
-54
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
3+
4+
ruby_version_is '3.1' do
5+
describe "Enumerable#compact" do
6+
it 'returns array without nil elements' do
7+
arr = EnumerableSpecs::Numerous.new(nil, 1, 2, nil, true)
8+
arr.compact.should == [1, 2, true]
9+
end
10+
end
11+
end

spec/ruby/core/enumerator/lazy/lazy_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
]
1717
lazy_methods += [:chunk_while, :uniq]
1818

19+
ruby_version_is '3.1' do
20+
lazy_methods += [:compact]
21+
end
22+
1923
Enumerator::Lazy.instance_methods(false).should include(*lazy_methods)
2024
end
2125
end
@@ -26,3 +30,13 @@
2630
lazy.lazy.should equal(lazy)
2731
end
2832
end
33+
34+
ruby_version_is '3.1' do
35+
describe "Enumerator::Lazy#compact" do
36+
it 'returns array without nil elements' do
37+
arr = [1, nil, 3, false, 5].to_enum.lazy.compact
38+
arr.should be_an_instance_of(Enumerator::Lazy)
39+
arr.force.should == [1, 3, false, 5]
40+
end
41+
end
42+
end

spec/ruby/core/file/shared/fnmatch.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@
159159
end
160160

161161
it "does not match leading periods in filenames with wildcards by default" do
162-
File.send(@method, '*', '.profile').should == false
163-
File.send(@method, '*', 'home/.profile').should == true
164-
File.send(@method, '*/*', 'home/.profile').should == true
165-
File.send(@method, '*/*', 'dave/.profile', File::FNM_PATHNAME).should == false
162+
File.should_not.send(@method, '*', '.profile')
163+
File.should.send(@method, '*', 'home/.profile')
164+
File.should.send(@method, '*/*', 'home/.profile')
165+
File.should_not.send(@method, '*/*', 'dave/.profile', File::FNM_PATHNAME)
166166
end
167167

168168
it "matches patterns with leading periods to dotfiles by default" do

spec/ruby/core/range/clone_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "Range#clone" do
4+
it "duplicates the range" do
5+
original = (1..3)
6+
copy = original.clone
7+
copy.begin.should == 1
8+
copy.end.should == 3
9+
copy.should_not.exclude_end?
10+
copy.should_not.equal? original
11+
12+
original = ("a"..."z")
13+
copy = original.clone
14+
copy.begin.should == "a"
15+
copy.end.should == "z"
16+
copy.should.exclude_end?
17+
copy.should_not.equal? original
18+
end
19+
20+
it "maintains the frozen state" do
21+
(1..2).clone.frozen?.should == (1..2).frozen?
22+
(1..).clone.frozen?.should == (1..).frozen?
23+
Range.new(1, 2).clone.frozen?.should == Range.new(1, 2).frozen?
24+
Class.new(Range).new(1, 2).clone.frozen?.should == Class.new(Range).new(1, 2).frozen?
25+
end
26+
end

spec/ruby/core/range/dup_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
describe "Range#dup" do
44
it "duplicates the range" do
5-
copy = (1..3).dup
5+
original = (1..3)
6+
copy = original.dup
67
copy.begin.should == 1
78
copy.end.should == 3
89
copy.should_not.exclude_end?
10+
copy.should_not.equal?(original)
911

1012
copy = ("a"..."z").dup
1113
copy.begin.should == "a"

spec/ruby/core/range/new_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,15 @@
6565

6666
range_exclude.should_not == range_include
6767
end
68+
69+
ruby_version_is "3.0" do
70+
it "creates a frozen range if the class is Range.class" do
71+
Range.new(1, 2).should.frozen?
72+
end
73+
74+
it "does not create a frozen range if the class is not Range.class" do
75+
Class.new(Range).new(1, 2).should_not.frozen?
76+
end
77+
end
6878
end
6979
end

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
Regexp.send(@method, str).should == '\+\[\]\('
1818
end
1919

20+
it "works for broken strings" do
21+
Regexp.send(@method, "a.\x85b.".force_encoding("US-ASCII")).should =="a\\.\x85b\\.".force_encoding("US-ASCII")
22+
Regexp.send(@method, "a.\x80".force_encoding("UTF-8")).should == "a\\.\x80".force_encoding("UTF-8")
23+
end
24+
2025
it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
2126
str = "abc".force_encoding("euc-jp")
2227
Regexp.send(@method, str).encoding.should == Encoding::US_ASCII

spec/ruby/core/regexp/source_spec.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,26 @@
99
/x(.)xz/.source.should == "x(.)xz"
1010
end
1111

12-
it "will remove escape characters" do
13-
/foo\/bar/.source.should == "foo/bar"
12+
it "keeps escape sequences as is" do
13+
/\x20\+/.source.should == '\x20\+'
14+
end
15+
16+
describe "escaping" do
17+
it "keeps escaping of metacharacter" do
18+
/\$/.source.should == "\\$"
19+
end
20+
21+
it "keeps escaping of metacharacter used as a terminator" do
22+
%r+\++.source.should == "\\+"
23+
end
24+
25+
it "removes escaping of non-metacharacter used as a terminator" do
26+
%r@\@@.source.should == "@"
27+
end
28+
29+
it "keeps escaping of non-metacharacter not used as a terminator" do
30+
/\@/.source.should == "\\@"
31+
end
1432
end
1533

1634
not_supported_on :opal do

spec/ruby/core/string/capitalize_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"hello".capitalize.should == "Hello"
1111
"HELLO".capitalize.should == "Hello"
1212
"123ABC".capitalize.should == "123abc"
13+
"abcdef"[1...-1].capitalize.should == "Bcde"
1314
end
1415

1516
describe "full Unicode case mapping" do
@@ -37,7 +38,7 @@
3738
end
3839

3940
it "handles non-ASCII substrings properly" do
40-
"garçon"[1..-1].capitalize(:ascii).should == "Arçon"
41+
"garçon"[1...-1].capitalize(:ascii).should == "Arço"
4142
end
4243
end
4344

spec/ruby/core/string/delete_prefix_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
r.should == s
2222
end
2323

24+
it "does not remove partial bytes, only full characters" do
25+
"\xe3\x81\x82".delete_prefix("\xe3").should == "\xe3\x81\x82"
26+
end
27+
2428
it "doesn't set $~" do
2529
$~ = nil
2630

0 commit comments

Comments
 (0)