File: large_number_spec.rb

package info (click to toggle)
ruby-yajl 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 3,068; ruby: 2,619; makefile: 4; sh: 3
file content (60 lines) | stat: -rw-r--r-- 1,527 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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