Skip to content

Commit fb8fdb9

Browse files
committed
1 parent 6dd4357 commit fb8fdb9

Some content is hidden

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

46 files changed

+559
-74
lines changed
+11
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

+14
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

+4-4
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/io/shared/each.rb

+14-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,20 @@
190190
end
191191

192192
describe "when passed chomp and nil as a separator" do
193-
it "yields self's content without trailing new line character" do
194-
@io.pos = 100
195-
@io.send(@method, nil, chomp: true) { |s| ScratchPad << s }
196-
ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six."]
193+
ruby_version_is "3.2" do
194+
it "yields self's content" do
195+
@io.pos = 100
196+
@io.send(@method, nil, chomp: true) { |s| ScratchPad << s }
197+
ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
198+
end
199+
end
200+
201+
ruby_version_is ""..."3.2" do
202+
it "yields self's content without trailing new line character" do
203+
@io.pos = 100
204+
@io.send(@method, nil, chomp: true) { |s| ScratchPad << s }
205+
ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six."]
206+
end
197207
end
198208
end
199209

spec/ruby/core/process/clock_gettime_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@
8383
end
8484
end
8585

86-
platform_is :freebsd, :openbsd do
86+
platform_is :freebsd do
8787
it "CLOCK_VIRTUAL" do
8888
Process.clock_gettime(Process::CLOCK_VIRTUAL).should be_an_instance_of(Float)
8989
end
9090

9191
it "CLOCK_PROF" do
9292
Process.clock_gettime(Process::CLOCK_PROF).should be_an_instance_of(Float)
9393
end
94+
end
9495

96+
platform_is :freebsd, :openbsd do
9597
it "CLOCK_UPTIME" do
9698
Process.clock_gettime(Process::CLOCK_UPTIME).should be_an_instance_of(Float)
9799
end

spec/ruby/core/range/clone_spec.rb

+26
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

+3-1
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

+10
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

+5
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

+20-2
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

+2-1
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

+4
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

spec/ruby/core/string/delete_suffix_spec.rb

+4
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_suffix("\x82").should == "\xe3\x81\x82"
26+
end
27+
2428
it "doesn't set $~" do
2529
$~ = nil
2630

spec/ruby/core/string/downcase_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
it "does not downcase non-ASCII characters" do
2828
"CÅR".downcase(:ascii).should == "cÅr"
2929
end
30+
31+
it "works with substrings" do
32+
"prefix TÉ"[-2..-1].downcase(:ascii).should == "tÉ"
33+
end
3034
end
3135

3236
describe "full Unicode case mapping adapted for Turkic languages" do

spec/ruby/core/string/encoding_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
it "is equal to the source encoding by default" do
1111
s = StringSpecs::ISO88599Encoding.new
1212
s.cedilla.encoding.should == s.source_encoding
13+
s.cedilla.encode("utf-8").should == 350.chr(Encoding::UTF_8) # S-cedilla
1314
end
1415

1516
it "returns the given encoding if #force_encoding has been called" do

spec/ruby/core/string/fixtures/iso-8859-9-encoding.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ class ISO88599Encoding
44
def source_encoding; __ENCODING__; end
55
def x_escape; [0xDF].pack('C').force_encoding("iso-8859-9"); end
66
def ascii_only; "glark"; end
7-
def cedilla; "Ş"; end
7+
def cedilla; "Þ"; end # S-cedilla
88
end
99
end

spec/ruby/core/string/include_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
StringSpecs::MyString.new("hello").include?(StringSpecs::MyString.new("lo")).should == true
1414
end
1515

16+
it "returns true if both strings are empty" do
17+
"".should.include?("")
18+
"".force_encoding("EUC-JP").should.include?("")
19+
"".should.include?("".force_encoding("EUC-JP"))
20+
"".force_encoding("EUC-JP").should.include?("".force_encoding("EUC-JP"))
21+
end
22+
23+
it "returns true if the RHS is empty" do
24+
"a".should.include?("")
25+
"a".force_encoding("EUC-JP").should.include?("")
26+
"a".should.include?("".force_encoding("EUC-JP"))
27+
"a".force_encoding("EUC-JP").should.include?("".force_encoding("EUC-JP"))
28+
end
29+
1630
it "tries to convert other to string using to_str" do
1731
other = mock('lo')
1832
other.should_receive(:to_str).and_return("lo")

spec/ruby/core/string/inspect_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
].should be_computed_by(:inspect)
2020
end
2121

22+
it "returns a string with special characters replaced with \\<char> notation for UTF-16" do
23+
pairs = [
24+
["\a", '"\\a"'],
25+
["\b", '"\\b"'],
26+
["\t", '"\\t"'],
27+
["\n", '"\\n"'],
28+
["\v", '"\\v"'],
29+
["\f", '"\\f"'],
30+
["\r", '"\\r"'],
31+
["\e", '"\\e"']
32+
].map { |str, result| [str.encode('UTF-16LE'), result] }
33+
34+
pairs.should be_computed_by(:inspect)
35+
end
36+
2237
it "returns a string with \" and \\ escaped with a backslash" do
2338
[ ["\"", '"\\""'],
2439
["\\", '"\\\\"']
@@ -311,6 +326,11 @@
311326
"\xF0\x9F".inspect.should == '"\\xF0\\x9F"'
312327
end
313328

329+
it "works for broken US-ASCII strings" do
330+
s = "©".force_encoding("US-ASCII")
331+
s.inspect.should == '"\xC2\xA9"'
332+
end
333+
314334
describe "when default external is UTF-8" do
315335
before :each do
316336
@extenc, Encoding.default_external = Encoding.default_external, Encoding::UTF_8

spec/ruby/core/string/lstrip_spec.rb

+26-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
" hello world ".lstrip.should == "hello world "
1111
"\n\r\t\n\v\r hello world ".lstrip.should == "hello world "
1212
"hello".lstrip.should == "hello"
13+
" こにちわ".lstrip.should == "こにちわ"
14+
end
15+
16+
it "works with lazy substrings" do
17+
" hello "[1...-1].lstrip.should == "hello "
18+
" hello world "[1...-1].lstrip.should == "hello world "
19+
"\n\r\t\n\v\r hello world "[1...-1].lstrip.should == "hello world "
20+
" こにちわ "[1...-1].lstrip.should == "こにちわ"
1321
end
1422

1523
ruby_version_is '3.0' do
@@ -27,20 +35,26 @@
2735
a.should == "hello "
2836
end
2937

38+
it "returns nil if no modifications were made" do
39+
a = "hello"
40+
a.lstrip!.should == nil
41+
a.should == "hello"
42+
end
43+
44+
it "makes a string empty if it is only whitespace" do
45+
"".lstrip!.should == nil
46+
" ".lstrip.should == ""
47+
" ".lstrip.should == ""
48+
end
49+
3050
ruby_version_is '3.0' do
31-
it "strips leading \\0" do
51+
it "removes leading NULL bytes and whitespace" do
3252
a = "\000 \000hello\000 \000"
3353
a.lstrip!
3454
a.should == "hello\000 \000"
3555
end
3656
end
3757

38-
it "returns nil if no modifications were made" do
39-
a = "hello"
40-
a.lstrip!.should == nil
41-
a.should == "hello"
42-
end
43-
4458
it "raises a FrozenError on a frozen instance that is modified" do
4559
-> { " hello ".freeze.lstrip! }.should raise_error(FrozenError)
4660
end
@@ -51,9 +65,13 @@
5165
-> { "".freeze.lstrip! }.should raise_error(FrozenError)
5266
end
5367

54-
it "raises an ArgumentError if the first codepoint is invalid" do
68+
it "raises an ArgumentError if the first non-space codepoint is invalid" do
5569
s = "\xDFabc".force_encoding(Encoding::UTF_8)
5670
s.valid_encoding?.should be_false
5771
-> { s.lstrip! }.should raise_error(ArgumentError)
72+
73+
s = " \xDFabc".force_encoding(Encoding::UTF_8)
74+
s.valid_encoding?.should be_false
75+
-> { s.lstrip! }.should raise_error(ArgumentError)
5876
end
5977
end

spec/ruby/core/string/ord_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
it "raises an ArgumentError if called on an empty String" do
2626
-> { ''.ord }.should raise_error(ArgumentError)
2727
end
28+
29+
it "raises ArgumentError if the character is broken" do
30+
s = "©".force_encoding("US-ASCII")
31+
-> { s.ord }.should raise_error(ArgumentError, "invalid byte sequence in US-ASCII")
32+
end
2833
end

0 commit comments

Comments
 (0)