summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-10-13 11:56:08 -0400
committerJemma Issroff <jemmaissroff@gmail.com>2023-10-16 15:40:19 -0700
commit39dd3343d8672a70ebb0990c166d99a8b29ee19e (patch)
tree97c32fb828813311710ca241747e0599109ea150 /test
parentfd87372a7482cbf7672c44ef95bc1dc3b00bab7c (diff)
[ruby/prism] Parse all magic comments
https://github.com/ruby/prism/commit/2b3d59f424
Diffstat (limited to 'test')
-rw-r--r--test/prism/magic_comment_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/prism/magic_comment_test.rb b/test/prism/magic_comment_test.rb
new file mode 100644
index 0000000000..c40364ccfa
--- /dev/null
+++ b/test/prism/magic_comment_test.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require_relative "test_helper"
+
+module Prism
+ class MagicCommentTest < TestCase
+ examples = [
+ "# encoding: ascii",
+ "# coding: ascii",
+ "# eNcOdInG: ascii",
+ "# CoDiNg: ascii",
+ "# \s\t\v encoding \s\t\v : \s\t\v ascii \s\t\v",
+ "# -*- encoding: ascii -*-",
+ "# -*- coding: ascii -*-",
+ "# -*- eNcOdInG: ascii -*-",
+ "# -*- CoDiNg: ascii -*-",
+ "# -*- \s\t\v encoding \s\t\v : \s\t\v ascii \s\t\v -*-",
+ "# -*- foo: bar; encoding: ascii -*-",
+ "# coding \t \r \v : \t \v \r ascii-8bit\n"
+ ]
+
+ examples.each do |example|
+ define_method(:"test_magic_comment_#{example}") do
+ assert_magic_comment(example)
+ end
+ end
+
+ private
+
+ def assert_magic_comment(example)
+ expected = Ripper.new(example).tap(&:parse).encoding
+ actual = Prism.parse(example).source.source.encoding
+ assert_equal expected, actual
+ end
+ end
+end