Skip to content

Commit ee09feb

Browse files
committed
Fix exception message to match CRuby when Integer#chr is called with incorrect codepoint value
* close oracle/truffleruby#2795
1 parent a28ec5e commit ee09feb

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

core/integer/chr_spec.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
end
1111

1212
it "raises a RangeError is self is less than 0" do
13-
-> { -1.chr }.should raise_error(RangeError)
14-
-> { (-bignum_value).chr }.should raise_error(RangeError)
13+
-> { -1.chr }.should raise_error(RangeError, /-1 out of char range/)
14+
-> { (-bignum_value).chr }.should raise_error(RangeError, /bignum out of char range/)
1515
end
1616

1717
it "raises a RangeError if self is too large" do
18-
-> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError)
18+
-> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError, /2206368128 out of char range/)
1919
end
2020

2121
describe "when Encoding.default_internal is nil" do
@@ -48,8 +48,8 @@
4848
end
4949

5050
it "raises a RangeError is self is greater than 255" do
51-
-> { 256.chr }.should raise_error(RangeError)
52-
-> { bignum_value.chr }.should raise_error(RangeError)
51+
-> { 256.chr }.should raise_error(RangeError, /256 out of char range/)
52+
-> { bignum_value.chr }.should raise_error(RangeError, /bignum out of char range/)
5353
end
5454
end
5555

@@ -137,7 +137,7 @@
137137
[620, "TIS-620"]
138138
].each do |integer, encoding_name|
139139
Encoding.default_internal = Encoding.find(encoding_name)
140-
-> { integer.chr }.should raise_error(RangeError)
140+
-> { integer.chr }.should raise_error(RangeError, /(invalid codepoint|out of char range)/)
141141
end
142142
end
143143
end
@@ -165,12 +165,12 @@
165165

166166
# http://redmine.ruby-lang.org/issues/4869
167167
it "raises a RangeError is self is less than 0" do
168-
-> { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError)
169-
-> { (-bignum_value).chr(Encoding::EUC_JP) }.should raise_error(RangeError)
168+
-> { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError, /-1 out of char range/)
169+
-> { (-bignum_value).chr(Encoding::EUC_JP) }.should raise_error(RangeError, /bignum out of char range/)
170170
end
171171

172172
it "raises a RangeError if self is too large" do
173-
-> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError)
173+
-> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError, /2206368128 out of char range/)
174174
end
175175

176176
it "returns a String with the specified encoding" do

0 commit comments

Comments
 (0)