Sha256: 2c243af9fc9ed07c724f02a919ef75035fefe3f7e20f11ae546a8eb98285f79c

Contents?: true

Size: 1.49 KB

Versions: 4

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)
      [err, status.exitstatus].should 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

4 entries across 4 versions & 2 rubygems

Version Path
yajl-ruby-1.2.3 spec/parsing/large_number_spec.rb
yajl-ruby-1.2.2 spec/parsing/large_number_spec.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/yajl-ruby-1.2.1/spec/parsing/large_number_spec.rb
yajl-ruby-1.2.1 spec/parsing/large_number_spec.rb