diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_regexp.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 805c57b472..cf989615e0 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1876,6 +1876,21 @@ class TestRegexp < Test::Unit::TestCase assert_equal(/0/, pr1.call(2)) end + def test_once_constant_interpolation + # A /o regexp whose interpolation folds to a constant must build a Regexp, + # not resurrect it as a String. The peephole optimizer rewrites + # "dupstring str; toregexp" into a single literal-push instruction; that + # instruction must become putobject (not keep dupstring). + assert_separately([], <<~'RUBY') + def m; /#{"a"}#{"b"}/o; end + assert_equal(/ab/, m) + assert_equal(/ab/, m) + assert_predicate(m, :frozen?) + assert_equal(/a/i, eval('/#{"a"}/io')) + assert_equal(0, ("ab" =~ /#{"a"}/o)) + RUBY + end + def test_once_recursive pr2 = proc{|i| if i > 0 |
