oj 3.13.7 → 3.13.11

Sign up to get free protection for your applications and to get access to all the features.
data/test/foo.rb CHANGED
@@ -1,13 +1,77 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'oj'
3
+ $: << '.'
4
+ $: << File.join(File.dirname(__FILE__), "../lib")
5
+ $: << File.join(File.dirname(__FILE__), "../ext")
4
6
 
5
- Oj::default_options = {cache_str: 0, cache_keys: true, mode: :strict}
7
+ require "oj"
8
+ require "socket"
9
+ require 'io/nonblock'
6
10
 
7
- puts "Ruby version: #{RUBY_VERSION}"
8
- puts "Oj version: #{Oj::VERSION}"
11
+ =begin
12
+ #pid = spawn("nc -d 0.1 -l 5000", out: "/dev/null")
13
+ pid = spawn("nc -i 1 -l 7777", out: "/dev/null")
14
+ at_exit { Process.kill 9, pid }
15
+ sleep 0.2
16
+ s = Socket.tcp("localhost", 7777)
17
+ #s.nonblock = false
18
+ 1_000_000.times do |x|
19
+ Oj.to_stream(s, { x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]})
20
+ end
21
+ =end
9
22
 
10
- puts "cache_keys: #{Oj::default_options[:cache_keys]}"
11
- puts "cache_str: #{Oj::default_options[:cache_str]}"
23
+ =begin
24
+ IO.pipe do |r, w|
25
+ if fork
26
+ r.close
27
+ #w.nonblock = false
28
+ 1_000_000.times do |i|
29
+ begin
30
+ Oj.to_stream(w, { x: i})
31
+ rescue IOError => e
32
+ puts "*** #{i} raised #{e.class}: #{e}"
33
+ IO.select(nil, [w])
34
+ retry
35
+ end
36
+ w.puts
37
+ end
38
+ else
39
+ w.close
40
+ sleep(0.1)
41
+ r.each_line { |b|
42
+ #print b
43
+ }
44
+ r.close
45
+ Process.exit(0)
46
+ end
47
+ end
48
+ =end
12
49
 
13
- Oj.load('{"":""}').each_pair {|k,v| puts "k.frozen?: #{k.frozen?}\nv.frozen?: #{v.frozen?}"}
50
+ IO.pipe do |r, w|
51
+ if fork
52
+ r.close
53
+ #w.nonblock = false
54
+ a = []
55
+ 10_000.times do |i|
56
+ a << i
57
+ end
58
+ begin
59
+ Oj.to_stream(w, a, indent: 2)
60
+ rescue IOError => e
61
+ puts "*** raised #{e.class}: #{e}"
62
+ puts "*** fileno: #{w.fileno}"
63
+ puts "*** is an IO?: #{w.kind_of?(IO)}"
64
+ IO.select(nil, [w])
65
+ retry
66
+ end
67
+ w.puts
68
+ else
69
+ w.close
70
+ sleep(0.5)
71
+ r.each_line { |b|
72
+ #print b
73
+ }
74
+ r.close
75
+ Process.exit(0)
76
+ end
77
+ end
data/test/test_fast.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ # coding: utf-8
3
+ # frozen_string_literal: true
3
4
 
4
5
  $: << File.dirname(__FILE__)
5
6
 
@@ -36,6 +37,17 @@ class DocTest < Minitest::Test
36
37
  end
37
38
  end
38
39
 
40
+ def test_leaf_of_existing_path
41
+ json = %{{"foo": 1, "fizz": true}}
42
+ Oj::Doc.open(json) do |doc|
43
+ %w(/foo/bar /fizz/bar).each do |path|
44
+ assert_nil(doc.fetch(path))
45
+ assert_equal(:default, doc.fetch(path, :default))
46
+ refute(doc.exists?(path))
47
+ end
48
+ end
49
+ end
50
+
39
51
  def test_true
40
52
  json = %{true}
41
53
  Oj::Doc.open(json) do |doc|
@@ -282,11 +294,11 @@ class DocTest < Minitest::Test
282
294
  ['/nothing', nil],
283
295
  ['/array/10', nil],
284
296
  ].each do |path,val|
285
- if val.nil?
286
- assert_nil(doc.fetch(path))
287
- else
297
+ if val.nil?
298
+ assert_nil(doc.fetch(path))
299
+ else
288
300
  assert_equal(val, doc.fetch(path))
289
- end
301
+ end
290
302
  end
291
303
  end
292
304
  # verify empty hash and arrays return nil when a member is requested
@@ -313,7 +325,7 @@ class DocTest < Minitest::Test
313
325
  end
314
326
  end
315
327
 
316
- def test_exisits
328
+ def test_exists
317
329
  Oj::Doc.open(@json1) do |doc|
318
330
  [['/array/1', true],
319
331
  ['/array/1', true],
@@ -322,7 +334,7 @@ class DocTest < Minitest::Test
322
334
  ['/array/3', false],
323
335
  ['/nothing', false],
324
336
  ].each do |path,val|
325
- assert_equal(val, doc.exists?(path))
337
+ assert_equal(val, doc.exists?(path), "failed for #{path.inspect}")
326
338
  end
327
339
  end
328
340
  end
@@ -384,6 +396,19 @@ class DocTest < Minitest::Test
384
396
  end
385
397
  end
386
398
 
399
+ def test_nested_each_child
400
+ h = {}
401
+ Oj::Doc.open('{"a":1,"c":[2],"d":3}') do |doc|
402
+ doc.each_child('/') do |child|
403
+ h[child.path] = child.fetch
404
+ child.each_child do |grandchild|
405
+ h[grandchild.path] = grandchild.fetch
406
+ end
407
+ end
408
+ end
409
+ assert_equal({"/a"=>1, "/c"=>[2], "/c/1"=>2, "/d"=>3}, h)
410
+ end
411
+
387
412
  def test_size
388
413
  Oj::Doc.open('[1,2,3]') do |doc|
389
414
  assert_equal(4, doc.size)
@@ -480,6 +505,11 @@ class DocTest < Minitest::Test
480
505
  assert_equal({'/a/x' => 2, '/b/y' => 4}, results)
481
506
  end
482
507
 
508
+ def test_doc_empty
509
+ result = Oj::Doc.open("") { |doc| doc.each_child {} }
510
+ assert_nil(result)
511
+ end
512
+
483
513
  def test_comment
484
514
  json = %{{
485
515
  "x"/*one*/:/*two*/true,//three
data/test/test_saj.rb CHANGED
@@ -180,7 +180,7 @@ class SajTest < Minitest::Test
180
180
  assert_equal([:add_value, 12345, nil], handler.calls.first)
181
181
  type, message, line, column = handler.calls.last
182
182
  assert_equal([:error, 1, 6], [type, line, column])
183
- assert_match(%r{invalid format, extra characters at line 1, column 6 \[(?:[a-z\.]+/)*saj\.c:\d+\]}, message)
183
+ assert_match(%r{invalid format, extra characters at line 1, column 6 \[(?:[A-Za-z]:\/)?(?:[a-z\.]+/)*saj\.c:\d+\]}, message)
184
184
  end
185
185
 
186
186
  end
data/test/test_various.rb CHANGED
@@ -528,7 +528,7 @@ class Juice < Minitest::Test
528
528
  assert_equal(58, obj.y)
529
529
  end
530
530
 
531
- # Stream Deeply Nested
531
+ # Stream Deeply Nested
532
532
  def test_deep_nest_dump
533
533
  begin
534
534
  a = []
@@ -541,7 +541,7 @@ class Juice < Minitest::Test
541
541
  assert(false, "*** expected an exception")
542
542
  end
543
543
 
544
- # Stream IO
544
+ # Stream IO
545
545
  def test_io_string
546
546
  src = { 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}
547
547
  output = StringIO.open("", "w+")
@@ -553,6 +553,9 @@ class Juice < Minitest::Test
553
553
  end
554
554
 
555
555
  def test_io_file
556
+ # Windows does not support fork
557
+ return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
558
+
556
559
  src = { 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}
557
560
  filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
558
561
  File.open(filename, "w") { |f|
@@ -564,6 +567,28 @@ class Juice < Minitest::Test
564
567
  assert_equal(src, obj)
565
568
  end
566
569
 
570
+ def test_io_stream
571
+ IO.pipe do |r, w|
572
+ if fork
573
+ r.close
574
+ #w.nonblock = false
575
+ a = []
576
+ 10_000.times do |i|
577
+ a << i
578
+ end
579
+ Oj.to_stream(w, a, indent: 2)
580
+ w.close
581
+ else
582
+ w.close
583
+ sleep(0.1) # to force a busy
584
+ cnt = 0
585
+ r.each_line { cnt += 1 }
586
+ r.close
587
+ Process.exit(0)
588
+ end
589
+ end
590
+ end
591
+
567
592
  # comments
568
593
  def test_comment_slash
569
594
  json = %{{
data/test/tests.rb CHANGED
@@ -18,7 +18,6 @@ require 'test_object'
18
18
  require 'test_saj'
19
19
  require 'test_scp'
20
20
  require 'test_strict'
21
- require 'test_various'
22
21
  require 'test_rails'
23
22
  require 'test_wab'
24
23
  require 'test_writer'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.7
4
+ version: 3.13.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -117,6 +117,7 @@ files:
117
117
  - ext/oj/dump_object.c
118
118
  - ext/oj/dump_strict.c
119
119
  - ext/oj/encode.h
120
+ - ext/oj/encoder.c
120
121
  - ext/oj/err.c
121
122
  - ext/oj/err.h
122
123
  - ext/oj/extconf.rb
@@ -201,6 +202,7 @@ files:
201
202
  - test/activesupport6/time_zone_test_helpers.rb
202
203
  - test/bar.rb
203
204
  - test/baz.rb
205
+ - test/bug.rb
204
206
  - test/files.rb
205
207
  - test/foo.rb
206
208
  - test/helper.rb
@@ -332,6 +334,7 @@ test_files:
332
334
  - test/activesupport6/time_zone_test_helpers.rb
333
335
  - test/bar.rb
334
336
  - test/baz.rb
337
+ - test/bug.rb
335
338
  - test/files.rb
336
339
  - test/foo.rb
337
340
  - test/helper.rb