diff options
author | Peter Zhu <[email protected]> | 2023-12-23 14:51:43 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2023-12-23 16:52:05 -0500 |
commit | fadda88903d9fe764ae53eca07aaf85f08e162a7 (patch) | |
tree | aa7dc15578a064e7db9b1c5b2003ccced639157e /test/ruby/test_regexp.rb | |
parent | 688a1314e60b0e58d5325f50c02552e3018c5025 (diff) |
Fix Regexp#to_s for GC compaction
The test fails when RGENGC_CHECK_MODE is turned on:
TestRegexp#test_to_s_under_gc_compact_stress = 13.46 s
1) Failure:
TestRegexp#test_to_s_under_gc_compact_stress [test/ruby/test_regexp.rb:81]:
<"(?-mix:abcd\u3042)"> expected but was
<"(?-mix:\u5C78\u3030\u5C78\u3030\u5C78\u3030\u5C78\u3030\u5C78\u3030)">.
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r-- | test/ruby/test_regexp.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 4d94702502..77e9ca67f6 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -72,6 +72,18 @@ class TestRegexp < Test::Unit::TestCase end end + def test_to_s_under_gc_compact_stress + EnvUtil.under_gc_compact_stress do + str = "abcd\u3042" + [:UTF_16BE, :UTF_16LE, :UTF_32BE, :UTF_32LE].each do |es| + enc = Encoding.const_get(es) + rs = Regexp.new(str.encode(enc)).to_s + assert_equal("(?-mix:abcd\u3042)".encode(enc), rs) + assert_equal(enc, rs.encoding) + end + end + end + def test_to_s_extended_subexp re = /#\g#{"\n"}/x re = /#{re}/ |