summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-01-11 18:46:51 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-01-11 18:46:51 +0900
commit3d3bc029c5b48ddfbb7c5f7b062cb364894c64af (patch)
tree35c9d93eba801e5c43724f6d606d093e99e2378f /test/ruby
parent0480c073449e5116847c9e975ac794f28daef0ac (diff)
Reject encodings determined at runtime as source code encodings
The encodings determined at runtime are affected by the runtime environment, such as the OS and locale, while the file contents are not.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_parse.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index c2f02ff809..858c623bcc 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -767,6 +767,34 @@ x = __ENCODING__
END
end
assert_equal(__ENCODING__, x)
+
+ assert_raise(ArgumentError) do
+ EnvUtil.with_default_external(Encoding::US_ASCII) {eval <<-END, nil, __FILE__, __LINE__+1}
+# coding = external
+x = __ENCODING__
+ END
+ end
+
+ assert_raise(ArgumentError) do
+ EnvUtil.with_default_internal(Encoding::US_ASCII) {eval <<-END, nil, __FILE__, __LINE__+1}
+# coding = internal
+x = __ENCODING__
+ END
+ end
+
+ assert_raise(ArgumentError) do
+ eval <<-END, nil, __FILE__, __LINE__+1
+# coding = filesystem
+x = __ENCODING__
+ END
+ end
+
+ assert_raise(ArgumentError) do
+ eval <<-END, nil, __FILE__, __LINE__+1
+# coding = locale
+x = __ENCODING__
+ END
+ end
end
def test_utf8_bom