Sha256: 81c6adac9ecd7cbe14a9068cd9abc13a2c3ecd54611a9fc3b52fc35ed90dab9e

Contents?: true

Size: 1.49 KB

Versions: 13

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe 'Parsing very long text' do
  shared_examples 'running script successfully' do |script|
    def dup_pipe(parent_half, child_half, new_io)
      parent_half.close
      new_io.reopen(child_half)
      child_half.close
    end

    def capture(cmd, stdin_data)
      child_in, child_out, child_err = IO::pipe, IO::pipe, IO::pipe

      child_pid = fork do
        dup_pipe(child_in[1], child_in[0], STDIN)
        dup_pipe(child_out[0], child_out[1], STDOUT)
        dup_pipe(child_err[0], child_err[1], STDERR)

        exec(cmd)
      end

      [
        child_in[0],
        child_out[1],
        child_err[1],
      ].each(&:close)

      child_in[1].write(stdin_data)
      child_in[1].close
      _, status = Process.waitpid2(child_pid)

      return child_out[0].read, child_err[0].read, status
    ensure
      [
        child_in[1],
        child_out[0],
        child_err[0],
      ].reject(&:closed?).each(&:close)
    end

    it 'runs successfully' do
      out, err, status = capture('ruby', script)
      expect([err, status.exitstatus]).to eq(['', 0])
    end
  end

  context 'when parseing big floats' do
    include_examples('running script successfully', <<-EOS)
require "yajl"
Yajl::Parser.parse('[0.' + '1' * 2**23 + ']')
    EOS
  end

  context 'when parseing long hash key with symbolize_keys option' do
    include_examples('running script successfully', <<-EOS)
require "yajl"
Yajl::Parser.parse('{"' + 'a' * 2**23 + '": 0}', :symbolize_keys => true)
    EOS
  end
end

Version data entries

13 entries across 13 versions & 6 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/spec/parsing/large_number_spec.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/spec/parsing/large_number_spec.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/spec/parsing/large_number_spec.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/spec/parsing/large_number_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/yajl-ruby-1.4.3/spec/parsing/large_number_spec.rb
yajl-ruby-1.4.3 spec/parsing/large_number_spec.rb
yajl-ruby-1.4.2 spec/parsing/large_number_spec.rb
yajl-ruby-1.4.1 spec/parsing/large_number_spec.rb
yajl-ruby-1.4.0 spec/parsing/large_number_spec.rb
yajl-ruby-1.3.1 spec/parsing/large_number_spec.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/spec/parsing/large_number_spec.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/spec/parsing/large_number_spec.rb
yajl-ruby-1.3.0 spec/parsing/large_number_spec.rb