Repository navigation
Expand file tree
/
Copy pathtest_compound_string_coderange.rb
More file actions
59 lines (49 loc) · 1.99 KB
/
Copy pathtest_compound_string_coderange.rb
File metadata and controls
59 lines (49 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# encoding: UTF-8
require 'test/unit'
require 'test/jruby/test_helper'
# GH-9591
#
# BuildCompoundStringInstr#simplifyInstr folds a compound string into a single
# literal. It used to assign CR_VALID without scanning the bytes. An ASCII-only
# string must be CR_7BIT, otherwise String#hash disagrees with String#eql? and
# uniq/Hash/Set split byte-identical strings.
#
# The interpreter builds these strings at run time and scans them, so the bug
# only appeared once a method was compiled. Each test therefore runs in a child
# process with the compiler forced on.
class TestCompoundStringCodeRange < Test::Unit::TestCase
include TestHelper
FORCE_COMPILE = { "jruby.compile.mode" => "FORCE" }
def test_folded_integer_interpolation_is_ascii_only
assert_equal 'true', run_compiled('print "abc#{1}def".ascii_only?')
end
def test_folded_symbol_interpolation_is_ascii_only
assert_equal 'true', run_compiled('print "abc#{:sym}def".ascii_only?')
end
def test_folded_float_interpolation_is_ascii_only
assert_equal 'true', run_compiled('print "abc#{1.5}def".ascii_only?')
end
def test_dedented_heredoc_is_ascii_only
script = 'value = <<~EOS' "\n" \
' hello world' "\n" \
'EOS' "\n" \
'print value.ascii_only?'
assert_equal 'true', run_compiled(script)
end
def test_folded_string_hash_agrees_with_eql
script = 'folded = "abc#{1}def"' "\n" \
'plain = "abc1def"' "\n" \
'print [folded.eql?(plain), folded.hash == plain.hash, [folded, plain].uniq.size].inspect'
assert_equal '[true, true, 1]', run_compiled(script)
end
# The fix must not mark real non-ASCII text as 7-bit.
def test_folded_non_ascii_string_is_not_ascii_only
script = 'value = "café#{1}!"' "\n" \
'print [value.ascii_only?, value.valid_encoding?].inspect'
assert_equal '[false, true]', run_compiled(script)
end
private
def run_compiled(script)
with_temp_script(script) { |f| jruby(f.path, FORCE_COMPILE) }
end
end