Commit graph

40 commits

Author SHA1 Message Date
Samuel Williams
021ccbf7e8 [ruby/pp] Ensure the thread local state is always set up.
(https://github.com/ruby/pp/pull/38)

5b5d483ac2
2025-02-25 03:38:04 +00:00
tompng
7b51b3c75b [ruby/pp] Fix pretty printing range begin/end with false or nil
6d9c0f255a
2024-11-19 14:52:01 +00:00
Jean Boussier
83702f7157 [ruby/pp] Handle BasicObject
Right now attempting to pretty print a BasicObject or any other
object lacking a few core Object methods will result in an error

```
Error: test_basic_object(PPTestModule::PPInspectTest): NoMethodError: undefined method `is_a?' for an instance of BasicObject
lib/pp.rb:192:in `pp'
lib/pp.rb:97:in `block in pp'
lib/pp.rb:158:in `guard_inspect_key'
lib/pp.rb:97:in `pp'
test/test_pp.rb:131:in `test_basic_object'
     128:
     129:   def test_basic_object
     130:     a = BasicObject.new
  => 131:     assert_match(/\A#<BasicObject:0x[\da-f]+>\n\z/, PP.pp(a, ''.dup))
     132:   end
     133: end
     134:
```

With some fairly small changes we can fallback to `Object#inspect`
which is better than an error.

4e9f6c2de0
2024-11-12 02:13:15 +00:00
Jean Boussier
107a4da122 [ruby/pp] Data#pretty_print handle privated or removed members
[Bug #20808]

The previous implementation assumed all members are accessible,
but it's possible for users to change the visibility of members or
to entirely remove the accessor.

fb19501434
2024-11-12 02:11:43 +00:00
Yusuke Endoh
a985695b9e Make test_hash_symbol_colon_key pass on LANG=en_US
It failed on a platform with LANG=en_US
```
  1) Failure:
PPTestModule::PPSingleLineTest#test_hash_symbol_colon_key [/home/chkbuild/chkbuild/tmp/build/20241010T010005Z/ruby/test/test_pp.rb:207]:
<"{a: 1, a!: 1, a?: 1, \u3042: 1}"> expected but was
<"{a: 1, a!: 1, a?: 1, \"\\u3042\": 1}">.
```
2024-10-10 12:23:18 +09:00
tompng
f7343b636f prettyprint hash with colon style 2024-10-03 18:47:09 +09:00
Nobuyoshi Nakada
6e704311bb [ruby/pp] Extract pp_hash_pair
The method which prints single pair of a hash, to make extending
pretty printing Hash easier, apart from Hash construct itself.

3fcf2d1142
2024-02-21 16:45:01 +00:00
Nobuyoshi Nakada
37b8fc7477 [ruby/pp] Get rid of hardcoded class name
So that the `pp` method can work in inherited classes with that
class.

f204df3aad
2024-02-21 16:45:00 +00:00
Nobuyoshi Nakada
d9ebb65b79 [ruby/pp] Fix compatibility with 3.3 or earlier
f5cee21a1e
2024-02-21 16:39:17 +00:00
Samuel Giddins
e0312f90bb [ruby/pp] Print beginless ranges properly
Instead of displaying the start of the range as nil

1df210d903
2024-01-15 14:04:14 +00:00
Benoit Daloze
4e0c2f05ef [ruby/pp] Add TruffleRuby in CI
* Only 2 cyclic tests are failing, with the ... in a slightly different place in the output.

6e5c7d741e
2024-01-11 13:44:03 +00:00
Benoit Daloze
1ed3b60375 [ruby/pp] Fix pretty printing a Data subclass instance when the subclass is anonymous
* It would be "#<data  a=42>" (double space) instead of "#<data a=42>" (like #inspect).

bed72bfcb8
2024-01-11 13:44:01 +00:00
Benoit Daloze
3b9cc22536 [ruby/pp] Use a proper feature check to check if Data is defined
ed602b9f2b
2024-01-11 13:44:00 +00:00
S-H-GAMELINKS
1b8d01136c Introduce Numeric Node's 2024-01-07 09:24:34 +09:00
Stan Lo
bf3ed7e826 [ruby/pp] Remove patch added for Ruby 2.6/JRuby 9.3
09dae96129
2023-04-25 23:21:58 +00:00
Stan Lo
c9b61ec53e [ruby/pp] Skip certain tests for JRuby
f7bde31ca9
2023-04-25 23:21:57 +00:00
manga_osyo
7b7e5153e8 [ruby/pp] [Feature #19045] Add support Data#pretty_print
343a20d721
2022-10-14 21:31:24 +09:00
Charles Oliver Nutter
66ec3217df
[ruby/pp] Add context to bind_call and skip 2.7+ test
The bind_call definition here is added primarily to support
running the tests on JRuby 9.3, which only supports Ruby 2.6
features. The excluded test appears to depend on inspect behavior
that changed after Ruby 2.6.

With these two changes the test suite runs green on Ruby 2.6 and
JRuby 9.3.

892c612958
2021-12-18 08:38:59 +09:00
Charles Oliver Nutter
cc73dfb92a
[ruby/pp] Incorporate 2.6 versions of 2.7 methods needed
* UnboundMethod#bind_call
* ruby2_keywords gem for testing

721d8cbd10
2021-12-18 08:38:59 +09:00
Charles Oliver Nutter
e57dd8c2b5
Mask RubyVM-specific test 2020-03-05 16:49:27 -06:00
Jeremy Evans
f8a8f05512 Remove empty keyword splats when calling even when using ruby2_keywords
Keeping empty keyword splats for ruby2_keywords methods was
necessary in 2.7 to prevent the final positional hash being
treated as keywords.  Now that keyword argument separation
has been committed, the final positional hash is never
treated as keywords, so there is no need to keep empty
keyword splats when using ruby2_keywords.
2020-01-23 09:30:29 -08:00
Benoit Daloze
0ea759eac9 Add more direct test for pp with a ruby2_keywords Hash 2020-01-23 10:59:26 +01:00
Jeremy Evans
28d31ead34 Fix pp when passed a empty ruby2_keywords-flagged hash as array element
This causes problems because the hash is passed to a block not
accepting keywords.  Because the hash is empty and keyword flagged,
it is removed before calling the block.  This doesn't cause an
ArgumentError because it is a block and not a lambda.  Just like
any other block not passed required arguments, arguments not
passed are set to nil.

Issues like this are a strong reason not to have ruby2_keywords
by default.

Fixes [Bug #16519]
2020-01-22 10:27:02 -08:00
Richard Viney
6a75a46053
Make prettyprint’s cycle detection aware of Delegator instances
Fixes [Bug #13144]

Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
2019-12-16 23:43:49 +09:00
Nobuyoshi Nakada
3620568d3a
Suppress void context warnings in verbose mode 2019-06-30 11:49:40 +09:00
nobu
8edd642381 test_pp.rb: show the node when failed
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 00:57:06 +00:00
nobu
87e1dd2982 Add RubyVM::AST#pretty_print
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 00:24:38 +00:00
akr
68ebbbfebe * lib/open-uri.rb: Remove indicator for "frozen_string_literal: true".
* lib/pp.rb: Ditto.

* lib/prettyprint.rb: Ditto.

* lib/resolv.rb: Ditto.

* lib/securerandom.rb: Ditto.

* lib/tmpdir.rb: Ditto.

* lib/unicode_normalize/tables.rb: Ditto.

* test/net/ftp/test_buffered_socket.rb: Ditto.

* test/net/ftp/test_mlsx_entry.rb: Ditto.

* test/open-uri/test_open-uri.rb: Ditto.

* test/open-uri/test_ssl.rb: Ditto.

* test/pathname/test_pathname.rb: Ditto.

* test/test_pp.rb: Ditto.

* test/test_prettyprint.rb: Ditto.

* tool/transcode-tblgen.rb: Ditto.

* ext/pathname/lib/pathname.rb: Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-10 11:48:14 +00:00
akr
36ca18b847 Put an line before "frozen_string_literal: true" for emacs.
https://bugs.ruby-lang.org/issues/8976#note-49


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-05 22:22:56 +00:00
akr
805c20a8e5 * lib/pp.rb: Use frozen_string_literal: true.
* lib/prettyprint.rb: Ditto.

* lib/resolv.rb: Ditto.

* lib/tmpdir.rb: Ditto.

* test/test_pp.rb: Ditto.

* test/test_prettyprint.rb: Ditto.

* tool/transcode-tblgen.rb: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-05 13:27:48 +00:00
usa
d03528608d * test/test_pp.rb (PPTestModule::PPFileStatTest): test for r48719.
is this the right place here?



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-05 19:48:15 +00:00
ko1
180c744b3b * numeric.c (rb_float_new_in_heap), include/ruby/ruby.h:
make all Float objects frozen.
  [ruby-dev:46081] [ruby-trunk - Feature #6936]
  Most part of patch by NARUSE, Yui  <naruse@ruby-lang.org>.
* class.c (singleton_class_of): raise TypeError when
  trying to define a singleton method on Float objects.
* vm.c (vm_define_method): ditto.
* test/ruby/marshaltestlib.rb: catch up above changes.
* test/ruby/test_class.rb: ditto.
* test/test_pp.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-27 02:10:53 +00:00
eregon
fd7dc23d28 Kernel#inspect: improve consistency and do not call #to_s.
* object.c (rb_obj_inspect): Kernel#inspect: do not call #to_s. A class
  can now benefit from the nice default #inspect even if it defines #to_s.
  Also, there is no more unexpected change in #inspect result.
* NEWS: Add note about the change.
* bignum.c, io.c, numeric.c, object.c, proc.c, vm.c (Init_*):
  Adapt internal structures (by aliasing #inspect to #to_s) so they
  don't rely on the removed behavior (#inspect calling overridden #to_s).
* test/ruby/test_object.rb (test_inspect): add tests for Kernel#inspect.
* lib/pp.rb (class PP): do not call #to_s anymore, as #inspect
  no more does (mame).
* test/test_pp.rb (class PPInspectTest): remove related assertion (mame).
  [ruby-core:43238][Feature #6130]
* test/drb/drbtest.rb (DRbCore#teardown, DRbAry#teardown):
  adapt DRb tests with the new change (shirosaki).
  [ruby-core:47182][Bug #6866]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-15 11:50:01 +00:00
naruse
780e7d0951 Revert r36699 and r36700. [Feature #6130]
Revert "Kernel#inspect: improve consistency and do not call #to_s."
Revert "update PP with recent Kernel#inspect change. Patch by Yusuke Endoh."

r36699 cause test-all failure on test/drb/test_drb.rb and
test/drb/test_drbssl.rb. Run test-all before commit.

Moreover its ChangeLog formst is wrong: see CommitterHowto
https://bugs.ruby-lang.org/projects/ruby/wiki/CommitterHowto#ChangeLog

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-15 01:09:10 +00:00
eregon
e1aa72d441 update PP with recent Kernel#inspect change. Patch by Yusuke Endoh.
* lib/pp.rb (class PP): do not call #to_s anymore, as #inspect no more does.
* test/test_pp.rb (class PPInspectTest): remove related assertion.
  [ruby-core:43238][Feature #6130]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-14 10:21:04 +00:00
akr
4319b48ab6 * lib/pp.rb (PP::ObjectMixin#pretty_print): use to_s regardless of
instance variables.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-07 12:05:38 +00:00
akr
4319c0235d * lib/pp.rb (PP:ObjectMixin#pretty_print): delegates has no inspect
method.  [ruby-core:25804]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-27 04:08:31 +00:00
akr
29f73c43a5 * test/test_pp.rb: extract from lib/pp.rb.
* test/test_prettyprint.rb: extract from lib/prettyprint.rb.

* test/test_tsort.rb: extract from lib/tsort.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-14 23:36:45 +00:00
nahi
45c950c1df * test/test_*.rb: Pathname#parent -> Pathname#dirname.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-13 04:06:31 +00:00
nahi
79c0e644a1 * test/inlinetest.rb, test/{test_generator.rb,test_ipaddr.rb,
test_pathname.rb,test_pp.rb,test_prettyprint.rb,test_set.rb,
          test_time.rb,test_tsort.rb: added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-06 02:34:24 +00:00