Skip to content

Hash#inspect with colon style - #10924

Merged
mame merged 7 commits into
ruby:masterfrom
tompng:hash_colon_style_inspect
Oct 3, 2024
Merged

Hash#inspect with colon style#10924
mame merged 7 commits into
ruby:masterfrom
tompng:hash_colon_style_inspect

Conversation

@tompng

@tompng tompng commented Jun 6, 2024

Copy link
Copy Markdown
Member

Implements https://bugs.ruby-lang.org/issues/20433#note-7
Change Hash#inspect to use colon style if the key is a symbol.
When key is not a symbol, space is added around =>

puts({a!: 1, "<=>" => 1, "a=": 1, 42 => 1}.inspect)
# => {a!: 1, "<=>" => 1, "a=": 1, 42 => 1}
# it was {:a!=>1, "<=>"=>1, :a==>1, 42=>1}

Symbol key that needs quote can be determined by this

chars = (32..127).map(&:chr)+["☆"]-[*'b'..'z',*'B'..'Z',*'1'..'9']
(1..3).each do |n|
  symbols = chars.repeated_permutation(n).map(&:join).map(&:to_sym)
  # Found symbols that needs quote
  a = symbols.reject do |sym|
    k = sym.inspect[1..]
    begin;{sym=>1} == eval("{#{k}: 1}");rescue SyntaxError;false;end
  end
  # Determine logic
  b = symbols.select do |sym|
    s = sym.inspect
    s[1]=='@'||s[1]=='$'||s[1]=='!'||"%&*+-/<=>@]^`|~".include?(s[-1])
  end
  p a == b
end

@cloudbees-smart-tests

This comment has been minimized.

@tompng
tompng force-pushed the hash_colon_style_inspect branch 3 times, most recently from de3bb45 to 898f9cb Compare June 7, 2024 16:21
@mame
mame requested a review from ko1 June 13, 2024 09:40
@tompng
tompng force-pushed the hash_colon_style_inspect branch 2 times, most recently from 75adf8f to aaa8d8c Compare June 14, 2024 14:13
@ko1
ko1 removed their request for review July 19, 2024 01:07
@tompng
tompng force-pushed the hash_colon_style_inspect branch from aaa8d8c to a6c54d5 Compare July 24, 2024 17:20
@tompng
tompng force-pushed the hash_colon_style_inspect branch 3 times, most recently from d6475a1 to 49e6761 Compare August 15, 2024 17:13
@tompng

tompng commented Aug 16, 2024

Copy link
Copy Markdown
Member Author

test-bundled-gems (debug) still fails but it is because debug(tag=v1.9.2) does not contain fixed test code yet.

@tompng
tompng force-pushed the hash_colon_style_inspect branch from 49e6761 to 998fdb3 Compare September 1, 2024 14:28
@tompng
tompng force-pushed the hash_colon_style_inspect branch from 998fdb3 to 3b3adec Compare September 20, 2024 14:39
@mame
mame force-pushed the hash_colon_style_inspect branch from 3b3adec to f74a5ae Compare October 3, 2024 07:30
@tompng
tompng force-pushed the hash_colon_style_inspect branch from f74a5ae to 71c2b08 Compare October 3, 2024 09:19
@mame
mame enabled auto-merge (rebase) October 3, 2024 09:20
@mame
mame merged commit 5bf8a53 into ruby:master Oct 3, 2024
@tompng
tompng deleted the hash_colon_style_inspect branch October 3, 2024 10:05
st0012 added a commit to ruby/rdoc that referenced this pull request Oct 3, 2024
tompng added a commit to tompng/error_highlight that referenced this pull request Oct 3, 2024
tompng added a commit to tompng/pp that referenced this pull request Oct 3, 2024
mame pushed a commit to ruby/error_highlight that referenced this pull request Oct 3, 2024
casperisfine pushed a commit to Shopify/rails that referenced this pull request Oct 3, 2024
One isn't because of Ruby, but the source location of the route
is different based on the Ruby version. So by normalizing the
`rails routes` output we make the test more resilient.

The other is that `Hash#inspect` just changed in ruby-head
ruby/ruby#10924
casperisfine pushed a commit to Shopify/rails that referenced this pull request Oct 3, 2024
One isn't because of Ruby, but the source location of the route
is different based on the Ruby version. So by normalizing the
`rails routes` output we make the test more resilient.

The other is that `Hash#inspect` just changed in ruby-head
ruby/ruby#10924
casperisfine pushed a commit to Shopify/rails that referenced this pull request Oct 3, 2024
One isn't because of Ruby, but the source location of the route
is different based on the Ruby version. So by normalizing the
`rails routes` output we make the test more resilient.

The other is that `Hash#inspect` just changed in ruby-head
ruby/ruby#10924
casperisfine pushed a commit to Shopify/rails that referenced this pull request Oct 3, 2024
One isn't because of Ruby, but the source location of the route
is different based on the Ruby version. So by normalizing the
`rails routes` output we make the test more resilient.

The other is that `Hash#inspect` just changed in ruby-head
ruby/ruby#10924
byroot added a commit to byroot/rails that referenced this pull request Oct 5, 2024
byroot added a commit to rails/rails that referenced this pull request Oct 5, 2024
byroot added a commit to rails/rails that referenced this pull request Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants