oj 3.7.4 → 3.13.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1352 -0
- data/README.md +29 -8
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +53 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -43
- data/ext/oj/circarray.h +16 -17
- data/ext/oj/code.c +165 -179
- data/ext/oj/code.h +27 -29
- data/ext/oj/compat.c +174 -194
- data/ext/oj/custom.c +809 -866
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +848 -863
- data/ext/oj/dump.h +81 -67
- data/ext/oj/dump_compat.c +85 -123
- data/ext/oj/dump_leaf.c +100 -188
- data/ext/oj/dump_object.c +527 -656
- data/ext/oj/dump_strict.c +315 -338
- data/ext/oj/encode.h +7 -34
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +48 -48
- data/ext/oj/extconf.rb +17 -4
- data/ext/oj/fast.c +1070 -1087
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +469 -436
- data/ext/oj/object.c +525 -593
- data/ext/oj/odd.c +154 -138
- data/ext/oj/odd.h +37 -38
- data/ext/oj/oj.c +1325 -986
- data/ext/oj/oj.h +333 -316
- data/ext/oj/parse.c +1002 -846
- data/ext/oj/parse.h +92 -87
- data/ext/oj/parser.c +1557 -0
- data/ext/oj/parser.h +91 -0
- data/ext/oj/rails.c +888 -878
- data/ext/oj/rails.h +11 -14
- data/ext/oj/reader.c +141 -147
- data/ext/oj/reader.h +73 -89
- data/ext/oj/resolve.c +41 -62
- data/ext/oj/resolve.h +7 -9
- data/ext/oj/rxclass.c +71 -75
- data/ext/oj/rxclass.h +18 -19
- data/ext/oj/saj.c +443 -486
- data/ext/oj/saj2.c +602 -0
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +787 -709
- data/ext/oj/stream_writer.c +133 -159
- data/ext/oj/strict.c +127 -118
- data/ext/oj/string_writer.c +230 -249
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +19 -19
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +59 -67
- data/ext/oj/val_stack.h +91 -129
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +342 -353
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/error.rb +1 -1
- data/lib/oj/json.rb +1 -1
- data/lib/oj/mimic.rb +48 -14
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/state.rb +8 -7
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +0 -8
- data/pages/Compatibility.md +1 -1
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +53 -46
- data/pages/Options.md +72 -11
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +73 -22
- data/pages/Security.md +1 -1
- data/test/activerecord/result_test.rb +7 -2
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +6 -12
- data/test/baz.rb +16 -0
- data/test/bug.rb +16 -0
- data/test/foo.rb +69 -75
- data/test/helper.rb +16 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +18 -4
- data/test/json_gem/json_parser_test.rb +9 -0
- data/test/json_gem/test_helper.rb +12 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_dump.rb +50 -0
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +46 -10
- data/test/test_custom.rb +147 -8
- data/test/test_fast.rb +62 -2
- data/test/test_file.rb +25 -2
- data/test/test_gc.rb +13 -0
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +7 -2
- data/test/test_object.rb +85 -9
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +335 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +5 -5
- data/test/test_strict.rb +26 -1
- data/test/test_various.rb +87 -65
- data/test/test_wab.rb +2 -0
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +1 -1
- data/test/zoo.rb +13 -0
- metadata +60 -110
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
data/test/test_file.rb
CHANGED
@@ -125,13 +125,16 @@ class FileJuice < Minitest::Test
|
|
125
125
|
|
126
126
|
# Time
|
127
127
|
def test_time_object
|
128
|
+
skip 'TruffleRuby fails this spec' if RUBY_ENGINE == 'truffleruby'
|
129
|
+
|
128
130
|
t = Time.now()
|
129
131
|
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
130
132
|
dump_and_load(t, false)
|
131
133
|
end
|
132
134
|
def test_time_object_early
|
133
|
-
|
134
|
-
|
135
|
+
skip 'Windows does not support dates before 1970.' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
136
|
+
skip 'TruffleRuby fails this spec' if RUBY_ENGINE == 'truffleruby'
|
137
|
+
|
135
138
|
t = Time.xmlschema("1954-01-05T00:00:00.123456")
|
136
139
|
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
137
140
|
dump_and_load(t, false)
|
@@ -166,6 +169,8 @@ class FileJuice < Minitest::Test
|
|
166
169
|
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
167
170
|
elsif 'jruby' == $ruby
|
168
171
|
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
172
|
+
elsif 'truffleruby' == $ruby
|
173
|
+
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
169
174
|
else
|
170
175
|
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
171
176
|
end
|
@@ -212,6 +217,24 @@ class FileJuice < Minitest::Test
|
|
212
217
|
dump_and_load(DateTime.new(2012, 6, 19), false)
|
213
218
|
end
|
214
219
|
|
220
|
+
def test_load_unicode_path
|
221
|
+
json =<<~JSON
|
222
|
+
{
|
223
|
+
"x":true,
|
224
|
+
"y":58,
|
225
|
+
"z": [1,2,3]
|
226
|
+
}
|
227
|
+
JSON
|
228
|
+
|
229
|
+
Tempfile.create('file_test_conceição1.json') do |f|
|
230
|
+
f.write(json)
|
231
|
+
f.close
|
232
|
+
|
233
|
+
objects = Oj.load_file(f.path)
|
234
|
+
assert_equal(Oj.load(json), objects)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
215
238
|
def dump_and_load(obj, trace=false)
|
216
239
|
filename = File.join(File.dirname(__FILE__), 'file_test.json')
|
217
240
|
File.open(filename, "w") { |f|
|
data/test/test_gc.rb
CHANGED
@@ -26,10 +26,12 @@ class GCTest < Minitest::Test
|
|
26
26
|
|
27
27
|
def setup
|
28
28
|
@default_options = Oj.default_options
|
29
|
+
GC.stress = true
|
29
30
|
end
|
30
31
|
|
31
32
|
def teardown
|
32
33
|
Oj.default_options = @default_options
|
34
|
+
GC.stress = false
|
33
35
|
end
|
34
36
|
|
35
37
|
# if no crash then the GC marking is working
|
@@ -41,9 +43,20 @@ class GCTest < Minitest::Test
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def test_parse_object_gc
|
46
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
47
|
+
|
44
48
|
g = Goo.new(0, nil)
|
45
49
|
100.times { |i| g = Goo.new(i, g) }
|
46
50
|
json = Oj.dump(g, :mode => :object)
|
47
51
|
Oj.object_load(json)
|
48
52
|
end
|
53
|
+
|
54
|
+
def test_parse_gc
|
55
|
+
json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
|
56
|
+
|
57
|
+
50.times do
|
58
|
+
data = Oj.load(json)
|
59
|
+
assert_equal(json, Oj.dump(data))
|
60
|
+
end
|
61
|
+
end
|
49
62
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
%w(lib ext).each do |dir|
|
7
|
+
$: << File.join($oj_dir, dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'minitest'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'oj'
|
13
|
+
|
14
|
+
class Generator < Minitest::Test
|
15
|
+
|
16
|
+
def test_before
|
17
|
+
json = Oj.generate({})
|
18
|
+
assert_equal("{}", json)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/test_hash.rb
CHANGED
@@ -5,7 +5,7 @@ $: << File.dirname(__FILE__)
|
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
8
|
-
class
|
8
|
+
class HashTest < Minitest::Test
|
9
9
|
|
10
10
|
module TestModule
|
11
11
|
end
|
@@ -25,5 +25,15 @@ class Hashi < Minitest::Test
|
|
25
25
|
assert_equal(3, obj[:abc])
|
26
26
|
assert_equal(3, obj.abc())
|
27
27
|
end
|
28
|
+
|
29
|
+
def test_marshal
|
30
|
+
h = Oj::EasyHash.new()
|
31
|
+
h['abc'] = 3
|
32
|
+
out = Marshal.dump(h)
|
33
|
+
|
34
|
+
obj = Marshal.load(out)
|
35
|
+
assert_equal(Oj::EasyHash, obj.class)
|
36
|
+
assert_equal(3, obj[:abc])
|
37
|
+
end
|
28
38
|
|
29
39
|
end # HashTest
|
data/test/test_integer_range.rb
CHANGED
@@ -15,7 +15,7 @@ class IntegerRangeTest < Minitest::Test
|
|
15
15
|
def setup
|
16
16
|
@default_options = Oj.default_options
|
17
17
|
# in null mode other options other than the number formats are not used.
|
18
|
-
Oj.default_options = { :mode => :null }
|
18
|
+
Oj.default_options = { :mode => :null, bigdecimal_as_decimal: true }
|
19
19
|
end
|
20
20
|
|
21
21
|
def teardown
|
@@ -23,18 +23,24 @@ class IntegerRangeTest < Minitest::Test
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_range
|
26
|
+
skip 'TruffleRuby fails this spec with `ArgumentError: :integer_range must be a range of Fixnum.`' if RUBY_ENGINE == 'truffleruby'
|
27
|
+
|
26
28
|
test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9007199254740993}
|
27
29
|
exp = '{"s":0,"s2":-1,"s3":1,"u":"-2","u2":"2","u3":"9007199254740993"}'
|
28
30
|
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_bignum
|
34
|
+
skip 'TruffleRuby fails this spec with `ArgumentError: :integer_range must be a range of Fixnum.`' if RUBY_ENGINE == 'truffleruby'
|
35
|
+
|
32
36
|
test = {u: -10000000000000000000, u2: 10000000000000000000}
|
33
37
|
exp = '{"u":"-10000000000000000000","u2":"10000000000000000000"}'
|
34
38
|
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
35
39
|
end
|
36
40
|
|
37
41
|
def test_valid_modes
|
42
|
+
skip 'TruffleRuby fails this spec with `ArgumentError: :integer_range must be a range of Fixnum.`' if RUBY_ENGINE == 'truffleruby'
|
43
|
+
|
38
44
|
test = {safe: 0, unsafe: 9007199254740993}
|
39
45
|
exp = '{"safe":0,"unsafe":"9007199254740993"}'
|
40
46
|
|
@@ -70,4 +76,3 @@ class IntegerRangeTest < Minitest::Test
|
|
70
76
|
assert_equal(exp, Oj.dump(test, integer_range: false))
|
71
77
|
end
|
72
78
|
end
|
73
|
-
|
data/test/test_object.rb
CHANGED
@@ -7,11 +7,12 @@ require 'helper'
|
|
7
7
|
|
8
8
|
class ObjectJuice < Minitest::Test
|
9
9
|
class Jeez
|
10
|
-
attr_accessor :x, :y
|
10
|
+
attr_accessor :x, :y, :_z
|
11
11
|
|
12
12
|
def initialize(x, y)
|
13
13
|
@x = x
|
14
14
|
@y = y
|
15
|
+
@_z = x.to_s
|
15
16
|
end
|
16
17
|
|
17
18
|
def eql?(o)
|
@@ -220,6 +221,13 @@ class ObjectJuice < Minitest::Test
|
|
220
221
|
|
221
222
|
def teardown
|
222
223
|
Oj.default_options = @default_options
|
224
|
+
#=begin
|
225
|
+
if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
|
226
|
+
#Oj::debug_odd("teardown before GC.verify_compaction_references")
|
227
|
+
verify_gc_compaction
|
228
|
+
#Oj::debug_odd("teardown after GC.verify_compaction_references")
|
229
|
+
end
|
230
|
+
#=end
|
223
231
|
end
|
224
232
|
|
225
233
|
def test_nil
|
@@ -453,6 +461,8 @@ class ObjectJuice < Minitest::Test
|
|
453
461
|
end
|
454
462
|
|
455
463
|
def test_json_module_object
|
464
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
465
|
+
|
456
466
|
obj = One::Two::Three::Deep.new()
|
457
467
|
dump_and_load(obj, false)
|
458
468
|
end
|
@@ -623,11 +633,15 @@ class ObjectJuice < Minitest::Test
|
|
623
633
|
end
|
624
634
|
|
625
635
|
def test_json_object
|
636
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
637
|
+
|
626
638
|
obj = Jeez.new(true, 58)
|
627
639
|
dump_and_load(obj, false)
|
628
640
|
end
|
629
641
|
|
630
642
|
def test_json_object_create_deep
|
643
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
644
|
+
|
631
645
|
obj = One::Two::Three::Deep.new()
|
632
646
|
dump_and_load(obj, false)
|
633
647
|
end
|
@@ -664,6 +678,8 @@ class ObjectJuice < Minitest::Test
|
|
664
678
|
end
|
665
679
|
|
666
680
|
def test_json_anonymous_struct
|
681
|
+
skip 'TruffleRuby fails this spec with `TypeError: allocator undefined for Class`' if RUBY_ENGINE == 'truffleruby'
|
682
|
+
|
667
683
|
s = Struct.new(:x, :y)
|
668
684
|
obj = s.new(1, 2)
|
669
685
|
json = Oj.dump(obj, :indent => 2, :mode => :object)
|
@@ -686,8 +702,10 @@ class ObjectJuice < Minitest::Test
|
|
686
702
|
end
|
687
703
|
|
688
704
|
def test_json_object_object
|
705
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
706
|
+
|
689
707
|
obj = Jeez.new(true, 58)
|
690
|
-
json = Oj.dump(obj, :
|
708
|
+
json = Oj.dump(obj, mode: :object, indent: 2, ignore_under: true)
|
691
709
|
assert(%{{
|
692
710
|
"^o":"ObjectJuice::Jeez",
|
693
711
|
"x":true,
|
@@ -705,6 +723,8 @@ class ObjectJuice < Minitest::Test
|
|
705
723
|
end
|
706
724
|
|
707
725
|
def test_to_hash_object_object
|
726
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
727
|
+
|
708
728
|
obj = Jazz.new(true, 58)
|
709
729
|
json = Oj.dump(obj, :mode => :object, :indent => 2)
|
710
730
|
assert(%{{
|
@@ -724,6 +744,8 @@ class ObjectJuice < Minitest::Test
|
|
724
744
|
end
|
725
745
|
|
726
746
|
def test_as_json_object_object
|
747
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
748
|
+
|
727
749
|
obj = Orange.new(true, 58)
|
728
750
|
json = Oj.dump(obj, :mode => :object, :indent => 2)
|
729
751
|
assert(%{{
|
@@ -743,6 +765,8 @@ class ObjectJuice < Minitest::Test
|
|
743
765
|
end
|
744
766
|
|
745
767
|
def test_object_object_no_cache
|
768
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
769
|
+
|
746
770
|
obj = Jam.new(true, 58)
|
747
771
|
json = Oj.dump(obj, :mode => :object, :indent => 2)
|
748
772
|
assert(%{{
|
@@ -771,6 +795,8 @@ class ObjectJuice < Minitest::Test
|
|
771
795
|
end
|
772
796
|
|
773
797
|
def test_exception
|
798
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
799
|
+
|
774
800
|
err = nil
|
775
801
|
begin
|
776
802
|
raise StandardError.new('A Message')
|
@@ -793,11 +819,39 @@ class ObjectJuice < Minitest::Test
|
|
793
819
|
end
|
794
820
|
end
|
795
821
|
|
822
|
+
class SubX < Exception
|
823
|
+
def initialize
|
824
|
+
super("sub")
|
825
|
+
@xyz = 123
|
826
|
+
end
|
827
|
+
end
|
828
|
+
|
829
|
+
def test_exception_subclass
|
830
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
831
|
+
|
832
|
+
err = nil
|
833
|
+
begin
|
834
|
+
raise SubX.new
|
835
|
+
rescue Exception => e
|
836
|
+
err = e
|
837
|
+
end
|
838
|
+
json = Oj.dump(err, :mode => :object, :indent => 2)
|
839
|
+
#puts "*** #{json}"
|
840
|
+
e2 = Oj.load(json, :mode => :strict)
|
841
|
+
assert_equal(err.class.to_s, e2['^o'])
|
842
|
+
assert_equal(err.message, e2['~mesg'])
|
843
|
+
assert_equal(err.backtrace, e2['~bt'])
|
844
|
+
e2 = Oj.load(json, :mode => :object)
|
845
|
+
assert_equal(e, e2);
|
846
|
+
end
|
847
|
+
|
796
848
|
def test_range_object
|
797
849
|
Oj.default_options = { :mode => :object }
|
798
850
|
json = Oj.dump(1..7, :mode => :object, :indent => 0)
|
799
851
|
if 'rubinius' == $ruby
|
800
852
|
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
853
|
+
elsif 'truffleruby' == $ruby
|
854
|
+
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
801
855
|
else
|
802
856
|
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
803
857
|
end
|
@@ -844,6 +898,14 @@ class ObjectJuice < Minitest::Test
|
|
844
898
|
assert_equal(a2[1].__id__, a2.__id__)
|
845
899
|
end
|
846
900
|
|
901
|
+
def test_circular_array3
|
902
|
+
a = ['^r1']
|
903
|
+
json = Oj.dump(a, mode: :object, circular: true)
|
904
|
+
assert_equal(%{["^i1","\\u005er1"]}, json)
|
905
|
+
a2 = Oj.load(json, mode: :object, circular: true)
|
906
|
+
assert_equal(a, a2)
|
907
|
+
end
|
908
|
+
|
847
909
|
def test_circular_hash2
|
848
910
|
h = { 'a' => 7 }
|
849
911
|
h['b'] = h
|
@@ -855,6 +917,8 @@ class ObjectJuice < Minitest::Test
|
|
855
917
|
end
|
856
918
|
|
857
919
|
def test_circular_object
|
920
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
921
|
+
|
858
922
|
obj = Jeez.new(nil, 58)
|
859
923
|
obj.x = obj
|
860
924
|
json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
|
@@ -863,6 +927,8 @@ class ObjectJuice < Minitest::Test
|
|
863
927
|
end
|
864
928
|
|
865
929
|
def test_circular_object2
|
930
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
931
|
+
|
866
932
|
obj = Jam.new(nil, 58)
|
867
933
|
obj.x = obj
|
868
934
|
json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
|
@@ -885,6 +951,8 @@ class ObjectJuice < Minitest::Test
|
|
885
951
|
end
|
886
952
|
|
887
953
|
def test_circular
|
954
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
955
|
+
|
888
956
|
h = { 'a' => 7 }
|
889
957
|
obj = Jeez.new(h, 58)
|
890
958
|
obj.x['b'] = obj
|
@@ -895,6 +963,8 @@ class ObjectJuice < Minitest::Test
|
|
895
963
|
end
|
896
964
|
|
897
965
|
def test_circular2
|
966
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
967
|
+
|
898
968
|
h = { 'a' => 7 }
|
899
969
|
obj = Jam.new(h, 58)
|
900
970
|
obj.x['b'] = obj
|
@@ -907,6 +977,8 @@ class ObjectJuice < Minitest::Test
|
|
907
977
|
end
|
908
978
|
|
909
979
|
def test_omit_nil
|
980
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
981
|
+
|
910
982
|
jam = Jam.new({'a' => 1, 'b' => nil }, nil)
|
911
983
|
|
912
984
|
json = Oj.dump(jam, :omit_nil => true, :mode => :object)
|
@@ -915,6 +987,11 @@ class ObjectJuice < Minitest::Test
|
|
915
987
|
|
916
988
|
def test_odd_date
|
917
989
|
dump_and_load(Date.new(2012, 6, 19), false)
|
990
|
+
|
991
|
+
Oj.register_odd(Date, Date, :jd, :jd)
|
992
|
+
json = Oj.dump(Date.new(2015, 3, 7), :mode => :object)
|
993
|
+
assert_equal(%|{"^O":"Date","jd":2457089}|, json)
|
994
|
+
dump_and_load(Date.new(2012, 6, 19), false)
|
918
995
|
end
|
919
996
|
|
920
997
|
def test_odd_datetime
|
@@ -939,13 +1016,6 @@ class ObjectJuice < Minitest::Test
|
|
939
1016
|
dump_and_load(s, false)
|
940
1017
|
end
|
941
1018
|
|
942
|
-
def test_odd_date_replaced
|
943
|
-
Oj.register_odd(Date, Date, :jd, :jd)
|
944
|
-
json = Oj.dump(Date.new(2015, 3, 7), :mode => :object)
|
945
|
-
assert_equal(%|{"^O":"Date","jd":2457089}|, json)
|
946
|
-
dump_and_load(Date.new(2012, 6, 19), false)
|
947
|
-
end
|
948
|
-
|
949
1019
|
def test_odd_raw
|
950
1020
|
Oj.register_odd_raw(Raw, Raw, :create, :to_json)
|
951
1021
|
json = Oj.dump(Raw.new(%|{"a":1}|), :mode => :object)
|
@@ -963,16 +1033,22 @@ class ObjectJuice < Minitest::Test
|
|
963
1033
|
end
|
964
1034
|
|
965
1035
|
def test_auto_string
|
1036
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
1037
|
+
|
966
1038
|
s = AutoStrung.new("Pete", true)
|
967
1039
|
dump_and_load(s, false)
|
968
1040
|
end
|
969
1041
|
|
970
1042
|
def test_auto_array
|
1043
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
1044
|
+
|
971
1045
|
a = AutoArray.new([1, 'abc', nil], true)
|
972
1046
|
dump_and_load(a, false)
|
973
1047
|
end
|
974
1048
|
|
975
1049
|
def test_auto_hash
|
1050
|
+
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'
|
1051
|
+
|
976
1052
|
h = AutoHash.new(nil, true)
|
977
1053
|
h['a'] = 1
|
978
1054
|
h['b'] = 2
|
data/test/test_parser.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
%w(lib ext).each do |dir|
|
7
|
+
$: << File.join($oj_dir, dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'minitest'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'stringio'
|
13
|
+
require 'date'
|
14
|
+
require 'bigdecimal'
|
15
|
+
require 'oj'
|
16
|
+
|
17
|
+
class ParserJuice < Minitest::Test
|
18
|
+
|
19
|
+
def test_array
|
20
|
+
p = Oj::Parser.new(:debug)
|
21
|
+
out = p.parse(%|[true, false, null, 123, -1.23, "abc"]|)
|
22
|
+
puts out
|
23
|
+
out = p.parse(%|{"abc": []}|)
|
24
|
+
puts out
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|