diff options
| author | Earlopain <14981592+Earlopain@users.noreply.github.com> | 2026-05-08 21:04:08 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-05-08 20:12:59 +0000 |
| commit | dc90c26a103ad62df73464cc1896edbcc90bd0c7 (patch) | |
| tree | 721c23616309fbd17f62fd21a1a2d80c787c0cf3 /test | |
| parent | 3a5bfb8a144cbc1d8021fd3709e007fc6f5b1261 (diff) | |
[ruby/prism] Respect `encoding` option in `Prism.lex` and friends
utf-8 is the default for source files but can be overwritten via options
https://github.com/ruby/prism/commit/355f451528
Diffstat (limited to 'test')
| -rw-r--r-- | test/prism/lex_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/prism/lex_test.rb b/test/prism/lex_test.rb index 8ea7ce7e9b..1e06d52184 100644 --- a/test/prism/lex_test.rb +++ b/test/prism/lex_test.rb @@ -47,6 +47,24 @@ module Prism end end + def test_lex_encoding + tokens = Prism.lex('"わたし"', encoding: Encoding::Windows_31J).value + tokens.each do |t| + assert_equal(Encoding::Windows_31J, t[0].value.encoding) + end + + # Shebangs must appear on the first line. For these cases, the encoding + # comment may appear second, but it should still change encoding. + tokens = Prism.lex(<<~RUBY, encoding: Encoding::Windows_31J).value + #! /usr/bin/env ruby + # encoding: utf-8 + "わたし" + RUBY + tokens.each do |t| + assert_equal(Encoding::UTF_8, t[0].value.encoding) + end + end + if RUBY_VERSION >= "3.3" def test_lex_compat source = "foo bar" |
