diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b71d424..77aed90 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,7 @@ jobs: - { os: windows-latest, ruby: mingw } - { os: windows-latest, ruby: mswin } - { os: ubuntu-latest, ruby: 'jruby-head', bundle: 'bundle exec' } + - { os: ubuntu-latest, ruby: 'truffleruby-head' } runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/lib/pp.rb b/lib/pp.rb index 1708dee..fb7aa7b 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -422,8 +422,10 @@ def pretty_print_cycle(q) # :nodoc: class Data # :nodoc: def pretty_print(q) # :nodoc: - q.group(1, sprintf("#') { - q.seplist(PP.mcall(self, Data, :members), lambda { q.text "," }) {|member| + class_name = PP.mcall(self, Kernel, :class).name + class_name = " #{class_name}" if class_name + q.group(1, "#') { + q.seplist(PP.mcall(self, Kernel, :class).members, lambda { q.text "," }) {|member| q.breakable q.text member.to_s q.text '=' @@ -438,7 +440,7 @@ def pretty_print(q) # :nodoc: def pretty_print_cycle(q) # :nodoc: q.text sprintf("#", PP.mcall(self, Kernel, :class).name) end -end if "3.2" <= RUBY_VERSION +end if defined?(Data.define) class Range # :nodoc: def pretty_print(q) # :nodoc: diff --git a/test/test_pp.rb b/test/test_pp.rb index bb2299a..473133b 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -140,15 +140,18 @@ def test_struct a = S.new(1,2) a.b = a assert_equal("#>\n", PP.pp(a, ''.dup)) - assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) + assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) unless RUBY_ENGINE == "truffleruby" end - if "3.2" <= RUBY_VERSION + if defined?(Data.define) D = Data.define(:aaa, :bbb) def test_data a = D.new("aaa", "bbb") assert_equal("#\n", PP.pp(a, ''.dup, 20)) assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup)) + + b = Data.define(:a).new(42) + assert_equal("#{b.inspect}\n", PP.pp(b, ''.dup)) end end @@ -164,7 +167,7 @@ def test_anonymous end def test_withinspect - omit if RUBY_ENGINE == "jruby" + omit if RUBY_ENGINE == "jruby" or RUBY_ENGINE == "truffleruby" a = [] a << HasInspect.new(a) assert_equal("[]\n", PP.pp(a, ''.dup))