Sha256: a3ef640e8d7efb5c7f4855633c94a010f0fe4557fec1ed7ccbc3198094d5c8bf

Contents?: true

Size: 678 Bytes

Versions: 2

Compression:

Stored size: 678 Bytes

Contents

module Pact
  module JRubySupport

    # Under jruby, JSON.pretty_generate inserts a blank new line between the opening and closing
    # brackets of an empty hash, like so:
    # {
    #   "empty": {
    #
    #   }
    # }
    # This screws up the UnixDiffFormatter, so we need to remove the blank lines.

    def fix_blank_lines_in_empty_hashes json
      json.gsub(/({\n)\n(\s*})/,'\1\2')
    end

    # preserve pre json 2.8.x behaviour
    # https://github.com/ruby/json/pull/626
    def add_blank_lines_in_empty_hashes(json)
      json.gsub(/({\s*})/, "{\n  }")
    end

    def add_blank_lines_in_empty_arrays(json)
      json.gsub(/\[\s*\]/, "[\n  ]")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact-support-1.21.1 lib/pact/shared/jruby_support.rb
pact-support-1.21.0 lib/pact/shared/jruby_support.rb