Skip to content

Commit

Permalink
[Bug #20280] Fix wrong tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 19, 2024
1 parent d9b61e2 commit 8c5b7eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
28 changes: 15 additions & 13 deletions spec/ruby/language/hash_spec.rb
Expand Up @@ -191,20 +191,22 @@ def h.to_hash; {:b => 2, :c => 3}; end
usascii_hash.keys.first.encoding.should == Encoding::US_ASCII
end

it "raises an EncodingError at parse time when Symbol key with invalid bytes" do
ScratchPad.record []
-> {
eval 'ScratchPad << 1; {:"\xC3" => 1}'
}.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"')
ScratchPad.recorded.should == []
end
ruby_bug "#20280", ""..."3.4" do
it "raises a SyntaxError at parse time when Symbol key with invalid bytes" do
ScratchPad.record []
-> {
eval 'ScratchPad << 1; {:"\xC3" => 1}'
}.should raise_error(SyntaxError, /invalid symbol/)
ScratchPad.recorded.should == []
end

it "raises an EncodingError at parse time when Symbol key with invalid bytes and 'key: value' syntax used" do
ScratchPad.record []
-> {
eval 'ScratchPad << 1; {"\xC3": 1}'
}.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"')
ScratchPad.recorded.should == []
it "raises a SyntaxError at parse time when Symbol key with invalid bytes and 'key: value' syntax used" do
ScratchPad.record []
-> {
eval 'ScratchPad << 1; {"\xC3": 1}'
}.should raise_error(SyntaxError, /invalid symbol/)
ScratchPad.recorded.should == []
end
end
end

Expand Down
14 changes: 8 additions & 6 deletions spec/ruby/language/symbol_spec.rb
Expand Up @@ -96,11 +96,13 @@
%I{a b #{"c"}}.should == [:a, :b, :c]
end

it "raises an EncodingError at parse time when Symbol with invalid bytes" do
ScratchPad.record []
-> {
eval 'ScratchPad << 1; :"\xC3"'
}.should raise_error(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"')
ScratchPad.recorded.should == []
ruby_bug "#20280", ""..."3.4" do
it "raises an SyntaxError at parse time when Symbol with invalid bytes" do
ScratchPad.record []
-> {
eval 'ScratchPad << 1; :"\xC3"'
}.should raise_error(SyntaxError, /invalid symbol/)
ScratchPad.recorded.should == []
end
end
end

0 comments on commit 8c5b7eb

Please sign in to comment.