Skip to content

Commit

Permalink
Add binding for Regexp#fixed_encoding?
Browse files Browse the repository at this point in the history
It turned out we already had the method in C++, we just did not disclose
it to Ruby space.
  • Loading branch information
herwinw committed Sep 21, 2024
1 parent 3073fab commit 74394c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/natalie/compiler/binding_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,7 @@ def generate_name
gen.binding('Regexp', 'casefold?', 'RegexpObject', 'casefold', argc: 0, pass_env: true, pass_block: false, return_type: :bool)
gen.binding('Regexp', 'encoding', 'RegexpObject', 'encoding', argc: 0, pass_env: false, pass_block: false, return_type: :Object)
gen.binding('Regexp', 'eql?', 'RegexpObject', 'eq', argc: 1, pass_env: true, pass_block: false, aliases: ['=='], return_type: :bool)
gen.binding('Regexp', 'fixed_encoding?' ,'RegexpObject', 'is_fixed_encoding', argc: 0, pass_env: false, pass_block: false, return_type: :bool)
gen.binding('Regexp', 'hash', 'RegexpObject', 'hash', argc: 0, pass_env: true, pass_block: false, return_type: :Object)
gen.binding('Regexp', 'initialize', 'RegexpObject', 'initialize', argc: 1..2, pass_env: true, pass_block: false, return_type: :Object, visibility: :private)
gen.binding('Regexp', 'inspect', 'RegexpObject', 'inspect', argc: 0, pass_env: true, pass_block: false, return_type: :Object)
Expand Down
8 changes: 2 additions & 6 deletions spec/language/regexp/encoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,11 @@
make_regexp = -> str { /#{str}/ }

r = make_regexp.call("été".dup.force_encoding(Encoding::UTF_8))
NATFIXME 'Implement Regexp#fixed_encoding?', exception: NoMethodError, message: "undefined method `fixed_encoding?' for an instance of Regexp" do
r.should.fixed_encoding?
end
r.should.fixed_encoding?
r.encoding.should == Encoding::UTF_8

r = make_regexp.call("abc".dup.force_encoding(Encoding::UTF_8))
NATFIXME 'Implement Regexp#fixed_encoding?', exception: NoMethodError, message: "undefined method `fixed_encoding?' for an instance of Regexp" do
r.should_not.fixed_encoding?
end
r.should_not.fixed_encoding?
r.encoding.should == Encoding::US_ASCII
end
end

0 comments on commit 74394c6

Please sign in to comment.