diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-10-09 10:34:42 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-10-09 15:42:23 +0000 |
| commit | e39e582594feaeb40722b2921e8feb562d94269b (patch) | |
| tree | 1e4c70593457de30083a4260d403f7b1ec924f84 /test | |
| parent | 2e2a5e4ff945ca8c17eae6c3b6b2b8b7d3dcdf69 (diff) | |
[ruby/prism] Attempt to assume binary is UTF-8
https://github.com/ruby/prism/commit/343197e4ff
Diffstat (limited to 'test')
| -rw-r--r-- | test/prism/ruby/location_test.rb | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/test/prism/ruby/location_test.rb b/test/prism/ruby/location_test.rb index e360a0db72..3d3e7dd562 100644 --- a/test/prism/ruby/location_test.rb +++ b/test/prism/ruby/location_test.rb @@ -140,23 +140,36 @@ module Prism assert_equal 7, location.end_code_units_column(Encoding::UTF_32LE) end - def test_code_units_handles_binary_encoding_with_multibyte_characters - # If the encoding is set to binary and the source contains multibyte - # characters, we avoid breaking the code unit offsets, but they will - # still be incorrect. - + def test_code_units_binary_valid_utf8 program = Prism.parse(<<~RUBY).value # -*- encoding: binary -*- 😀 + 😀 RUBY - # first 😀 - location = program.statements.body.first.receiver.location + receiver = program.statements.body.first.receiver + assert_equal "😀".b.to_sym, receiver.name + + location = receiver.location + assert_equal 1, location.end_code_units_column(Encoding::UTF_8) + assert_equal 2, location.end_code_units_column(Encoding::UTF_16LE) + assert_equal 1, location.end_code_units_column(Encoding::UTF_32LE) + end - assert_equal 4, location.end_code_units_column(Encoding::UTF_8) - assert_equal 4, location.end_code_units_column(Encoding::UTF_16LE) - assert_equal 4, location.end_code_units_column(Encoding::UTF_32LE) + def test_code_units_binary_invalid_utf8 + program = Prism.parse(<<~RUBY).value + # -*- encoding: binary -*- + + \x90 + \x90 + RUBY + + receiver = program.statements.body.first.receiver + assert_equal "\x90".b.to_sym, receiver.name + + location = receiver.location + assert_equal 1, location.end_code_units_column(Encoding::UTF_8) + assert_equal 1, location.end_code_units_column(Encoding::UTF_16LE) + assert_equal 1, location.end_code_units_column(Encoding::UTF_32LE) end def test_chop |
