summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authortompng <[email protected]>2024-06-07 02:05:22 +0900
committerYusuke Endoh <[email protected]>2024-10-03 18:47:09 +0900
commita8a059125314a411eaf879a9fbfdc68d6c01a667 (patch)
treef85d3d1e48a18b49d031d260068fcea3d00976f2 /test/ruby
parent2c0149d330d3068272eed785d627d9f0daa95bbf (diff)
Hash#inspect with colon style
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/10924
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_hash.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index f60ba0cffd..8219abc678 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -869,6 +869,33 @@ class TestHash < Test::Unit::TestCase
$, = nil
end
+ def test_inspect
+ no_quote = '{a: 1, a!: 1, a?: 1}'
+ quote0 = '{"": 1}'
+ quote1 = '{"0": 1, "!": 1, "%": 1, "&": 1, "*": 1, "+": 1, "-": 1, "/": 1, "<": 1, ">": 1, "^": 1, "`": 1, "|": 1, "~": 1}'
+ quote2 = '{"@a": 1, "$a": 1, "+@": 1, "a=": 1, "[]": 1}'
+ quote3 = '{"a\"b": 1, "@@a": 1, "<=>": 1, "===": 1, "[]=": 1}'
+ assert_equal(no_quote, eval(no_quote).inspect)
+ assert_equal(quote0, eval(quote0).inspect)
+ assert_equal(quote1, eval(quote1).inspect)
+ assert_equal(quote2, eval(quote2).inspect)
+ assert_equal(quote3, eval(quote3).inspect)
+ begin
+ enc = Encoding.default_external
+ Encoding.default_external = Encoding::ASCII
+ utf8_ascii_hash = '{"\\u3042": 1}'
+ assert_equal(eval(utf8_ascii_hash).inspect, utf8_ascii_hash)
+ Encoding.default_external = Encoding::UTF_8
+ utf8_hash = "{\u3042: 1}"
+ assert_equal(eval(utf8_hash).inspect, utf8_hash)
+ Encoding.default_external = Encoding::Windows_31J
+ sjis_hash = "{\x87]: 1}".force_encoding('sjis')
+ assert_equal(eval(sjis_hash).inspect, sjis_hash)
+ ensure
+ Encoding.default_external = enc
+ end
+ end
+
def test_update
h1 = @cls[ 1 => 2, 2 => 3, 3 => 4 ]
h2 = @cls[ 2 => 'two', 4 => 'four' ]