Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/jruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: build

on:
push:
pull_request:
schedule:
- cron: '12 3 * * *'

jobs:
build:
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
strategy:
matrix:
ruby: [ 'jruby-9.3' ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and enable caching
- name: Build
run: bundle exec rake build
- name: Run test
run: bundle exec rake test
# Temporarily skipped until a released version of JRuby support 2.7+
# - name: Installation test
# run: gem install pkg/*.gem
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ source "https://rubygems.org"

gem "rake"
gem "test-unit"
gem "ruby2_keywords", group: :test
60 changes: 31 additions & 29 deletions lib/pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def pretty_print(q) # :nodoc:
class File < IO # :nodoc:
class Stat # :nodoc:
def pretty_print(q) # :nodoc:
require 'etc.so'
require 'etc'
q.object_group(self) {
q.breakable
q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
Expand Down Expand Up @@ -530,37 +530,39 @@ def pretty_print(q) # :nodoc:
end
end

class RubyVM::AbstractSyntaxTree::Node
def pretty_print_children(q, names = [])
children.zip(names) do |c, n|
if n
q.breakable
q.text "#{n}:"
end
q.group(2) do
q.breakable
q.pp c
if defined?(RubyVM::AbstractSyntaxTree)
class RubyVM::AbstractSyntaxTree::Node
def pretty_print_children(q, names = [])
children.zip(names) do |c, n|
if n
q.breakable
q.text "#{n}:"
end
q.group(2) do
q.breakable
q.pp c
end
end
end
end

def pretty_print(q)
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
case type
when :SCOPE
pretty_print_children(q, %w"tbl args body")
when :ARGS
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
when :DEFN
pretty_print_children(q, %w[mid body])
when :ARYPTN
pretty_print_children(q, %w[const pre rest post])
when :HSHPTN
pretty_print_children(q, %w[const kw kwrest])
else
pretty_print_children(q)
end
}
def pretty_print(q)
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
case type
when :SCOPE
pretty_print_children(q, %w"tbl args body")
when :ARGS
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
when :DEFN
pretty_print_children(q, %w[mid body])
when :ARYPTN
pretty_print_children(q, %w[const pre rest post])
when :HSHPTN
pretty_print_children(q, %w[const kw kwrest])
else
pretty_print_children(q)
end
}
end
end
end

Expand Down
12 changes: 11 additions & 1 deletion test/test_pp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
require 'pp'
require 'delegate'
require 'test/unit'
require 'ruby2_keywords'

# Define bind_call for Ruby 2.6 and earlier, to allow testing on JRuby 9.3
class UnboundMethod
unless public_method_defined?(:bind_call)
def bind_call(obj, *args, &block)
bind(obj).call(*args, &block)
end
end
end

module PPTestModule

Expand Down Expand Up @@ -158,7 +168,7 @@ def test_withinspect
a << HasInspect.new(a)
assert_equal("[<inspect:[...]>]\n", PP.pp(a, ''.dup))
assert_equal("#{a.inspect}\n", PP.pp(a, ''.dup))
end
end unless RUBY_VERSION < "2.7" # temporary mask to test on JRuby 9.3 (2.6 equivalent)

def test_share_nil
begin
Expand Down