oj 3.7.4 → 3.13.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1360 -0
- data/README.md +31 -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 +790 -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 +1073 -1088
- data/ext/oj/intern.c +298 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +469 -436
- data/ext/oj/object.c +532 -599
- data/ext/oj/odd.c +154 -138
- data/ext/oj/odd.h +37 -38
- data/ext/oj/oj.c +1333 -986
- data/ext/oj/oj.h +336 -316
- data/ext/oj/parse.c +1002 -846
- data/ext/oj/parse.h +92 -87
- data/ext/oj/parser.c +1587 -0
- data/ext/oj/parser.h +102 -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 +596 -0
- data/ext/oj/saj2.h +23 -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 +1207 -0
- data/ext/oj/usual.h +68 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +60 -68
- 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 +9 -8
- 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 +78 -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 +21 -8
- data/test/json_gem/json_parser_test.rb +8 -1
- 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 +145 -7
- data/test/test_fast.rb +62 -2
- data/test/test_file.rb +23 -7
- data/test/test_gc.rb +11 -0
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +1 -2
- data/test/test_object.rb +43 -12
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.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 +3 -5
- data/test/test_strict.rb +26 -1
- data/test/test_various.rb +86 -65
- data/test/test_wab.rb +2 -0
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +10 -1
- data/test/tests_mimic.rb +9 -0
- data/test/tests_mimic_addition.rb +9 -0
- data/test/zoo.rb +13 -0
- metadata +63 -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_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
|
|
@@ -46,4 +48,13 @@ class GCTest < Minitest::Test
|
|
|
46
48
|
json = Oj.dump(g, :mode => :object)
|
|
47
49
|
Oj.object_load(json)
|
|
48
50
|
end
|
|
51
|
+
|
|
52
|
+
def test_parse_gc
|
|
53
|
+
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]]]]]]]}'
|
|
54
|
+
|
|
55
|
+
50.times do
|
|
56
|
+
data = Oj.load(json)
|
|
57
|
+
assert_equal(json, Oj.dump(data))
|
|
58
|
+
end
|
|
59
|
+
end
|
|
49
60
|
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
|
|
@@ -70,4 +70,3 @@ class IntegerRangeTest < Minitest::Test
|
|
|
70
70
|
assert_equal(exp, Oj.dump(test, integer_range: false))
|
|
71
71
|
end
|
|
72
72
|
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)
|
|
@@ -687,7 +688,7 @@ class ObjectJuice < Minitest::Test
|
|
|
687
688
|
|
|
688
689
|
def test_json_object_object
|
|
689
690
|
obj = Jeez.new(true, 58)
|
|
690
|
-
json = Oj.dump(obj, :
|
|
691
|
+
json = Oj.dump(obj, mode: :object, indent: 2, ignore_under: true)
|
|
691
692
|
assert(%{{
|
|
692
693
|
"^o":"ObjectJuice::Jeez",
|
|
693
694
|
"x":true,
|
|
@@ -793,13 +794,37 @@ class ObjectJuice < Minitest::Test
|
|
|
793
794
|
end
|
|
794
795
|
end
|
|
795
796
|
|
|
797
|
+
class SubX < Exception
|
|
798
|
+
def initialize
|
|
799
|
+
super("sub")
|
|
800
|
+
@xyz = 123
|
|
801
|
+
end
|
|
802
|
+
end
|
|
803
|
+
|
|
804
|
+
def test_exception_subclass
|
|
805
|
+
err = nil
|
|
806
|
+
begin
|
|
807
|
+
raise SubX.new
|
|
808
|
+
rescue Exception => e
|
|
809
|
+
err = e
|
|
810
|
+
end
|
|
811
|
+
json = Oj.dump(err, :mode => :object, :indent => 2)
|
|
812
|
+
#puts "*** #{json}"
|
|
813
|
+
e2 = Oj.load(json, :mode => :strict)
|
|
814
|
+
assert_equal(err.class.to_s, e2['^o'])
|
|
815
|
+
assert_equal(err.message, e2['~mesg'])
|
|
816
|
+
assert_equal(err.backtrace, e2['~bt'])
|
|
817
|
+
e2 = Oj.load(json, :mode => :object)
|
|
818
|
+
assert_equal(e, e2);
|
|
819
|
+
end
|
|
820
|
+
|
|
796
821
|
def test_range_object
|
|
797
822
|
Oj.default_options = { :mode => :object }
|
|
798
823
|
json = Oj.dump(1..7, :mode => :object, :indent => 0)
|
|
799
|
-
if '
|
|
800
|
-
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
|
801
|
-
else
|
|
824
|
+
if 'ruby' == $ruby
|
|
802
825
|
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
|
826
|
+
else
|
|
827
|
+
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
|
803
828
|
end
|
|
804
829
|
dump_and_load(1..7, false)
|
|
805
830
|
dump_and_load(1..1, false)
|
|
@@ -844,6 +869,14 @@ class ObjectJuice < Minitest::Test
|
|
|
844
869
|
assert_equal(a2[1].__id__, a2.__id__)
|
|
845
870
|
end
|
|
846
871
|
|
|
872
|
+
def test_circular_array3
|
|
873
|
+
a = ['^r1']
|
|
874
|
+
json = Oj.dump(a, mode: :object, circular: true)
|
|
875
|
+
assert_equal(%{["^i1","\\u005er1"]}, json)
|
|
876
|
+
a2 = Oj.load(json, mode: :object, circular: true)
|
|
877
|
+
assert_equal(a, a2)
|
|
878
|
+
end
|
|
879
|
+
|
|
847
880
|
def test_circular_hash2
|
|
848
881
|
h = { 'a' => 7 }
|
|
849
882
|
h['b'] = h
|
|
@@ -915,6 +948,11 @@ class ObjectJuice < Minitest::Test
|
|
|
915
948
|
|
|
916
949
|
def test_odd_date
|
|
917
950
|
dump_and_load(Date.new(2012, 6, 19), false)
|
|
951
|
+
|
|
952
|
+
Oj.register_odd(Date, Date, :jd, :jd)
|
|
953
|
+
json = Oj.dump(Date.new(2015, 3, 7), :mode => :object)
|
|
954
|
+
assert_equal(%|{"^O":"Date","jd":2457089}|, json)
|
|
955
|
+
dump_and_load(Date.new(2012, 6, 19), false)
|
|
918
956
|
end
|
|
919
957
|
|
|
920
958
|
def test_odd_datetime
|
|
@@ -939,13 +977,6 @@ class ObjectJuice < Minitest::Test
|
|
|
939
977
|
dump_and_load(s, false)
|
|
940
978
|
end
|
|
941
979
|
|
|
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
980
|
def test_odd_raw
|
|
950
981
|
Oj.register_odd_raw(Raw, Raw, :create, :to_json)
|
|
951
982
|
json = Oj.dump(Raw.new(%|{"a":1}|), :mode => :object)
|
data/test/test_parser.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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 'test_parser_usual'
|
|
11
|
+
require 'test_parser_saj'
|
|
@@ -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
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
$: << File.dirname(__FILE__)
|
|
5
|
+
|
|
6
|
+
require 'helper'
|
|
7
|
+
|
|
8
|
+
$json = %|{
|
|
9
|
+
"array": [
|
|
10
|
+
{
|
|
11
|
+
"num" : 3,
|
|
12
|
+
"string": "message",
|
|
13
|
+
"hash" : {
|
|
14
|
+
"h2" : {
|
|
15
|
+
"a" : [ 1, 2, 3 ]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"boolean" : true
|
|
21
|
+
}|
|
|
22
|
+
|
|
23
|
+
class AllSaj < Oj::Saj
|
|
24
|
+
attr_accessor :calls
|
|
25
|
+
|
|
26
|
+
def initialize()
|
|
27
|
+
@calls = []
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def hash_start(key)
|
|
31
|
+
@calls << [:hash_start, key]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def hash_end(key)
|
|
35
|
+
@calls << [:hash_end, key]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def array_start(key)
|
|
39
|
+
@calls << [:array_start, key]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def array_end(key)
|
|
43
|
+
@calls << [:array_end, key]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def add_value(value, key)
|
|
47
|
+
@calls << [:add_value, value, key]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def error(message, line, column)
|
|
51
|
+
@calls << [:error, message, line, column]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end # AllSaj
|
|
55
|
+
|
|
56
|
+
class LocSaj
|
|
57
|
+
attr_accessor :calls
|
|
58
|
+
|
|
59
|
+
def initialize()
|
|
60
|
+
@calls = []
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def hash_start(key, line, column)
|
|
64
|
+
@calls << [:hash_start, key, line, column]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def hash_end(key, line, column)
|
|
68
|
+
@calls << [:hash_end, key, line, column]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def array_start(key, line, column)
|
|
72
|
+
@calls << [:array_start, key, line, column]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def array_end(key, line, column)
|
|
76
|
+
@calls << [:array_end, key, line, column]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def add_value(value, key, line, column)
|
|
80
|
+
@calls << [:add_value, value, key, line, column]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end # LocSaj
|
|
84
|
+
|
|
85
|
+
class SajTest < Minitest::Test
|
|
86
|
+
|
|
87
|
+
def test_nil
|
|
88
|
+
handler = AllSaj.new()
|
|
89
|
+
json = %{null}
|
|
90
|
+
p = Oj::Parser.new(:saj)
|
|
91
|
+
p.handler = handler
|
|
92
|
+
p.parse(json)
|
|
93
|
+
assert_equal([[:add_value, nil, nil]], handler.calls)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_true
|
|
97
|
+
handler = AllSaj.new()
|
|
98
|
+
json = %{true}
|
|
99
|
+
p = Oj::Parser.new(:saj)
|
|
100
|
+
p.handler = handler
|
|
101
|
+
p.parse(json)
|
|
102
|
+
assert_equal([[:add_value, true, nil]], handler.calls)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_false
|
|
106
|
+
handler = AllSaj.new()
|
|
107
|
+
json = %{false}
|
|
108
|
+
p = Oj::Parser.new(:saj)
|
|
109
|
+
p.handler = handler
|
|
110
|
+
p.parse(json)
|
|
111
|
+
assert_equal([[:add_value, false, nil]], handler.calls)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_string
|
|
115
|
+
handler = AllSaj.new()
|
|
116
|
+
json = %{"a string"}
|
|
117
|
+
p = Oj::Parser.new(:saj)
|
|
118
|
+
p.handler = handler
|
|
119
|
+
p.parse(json)
|
|
120
|
+
assert_equal([[:add_value, 'a string', nil]], handler.calls)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_fixnum
|
|
124
|
+
handler = AllSaj.new()
|
|
125
|
+
json = %{12345}
|
|
126
|
+
p = Oj::Parser.new(:saj)
|
|
127
|
+
p.handler = handler
|
|
128
|
+
p.parse(json)
|
|
129
|
+
assert_equal([[:add_value, 12345, nil]], handler.calls)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_float
|
|
133
|
+
handler = AllSaj.new()
|
|
134
|
+
json = %{12345.6789}
|
|
135
|
+
p = Oj::Parser.new(:saj)
|
|
136
|
+
p.handler = handler
|
|
137
|
+
p.parse(json)
|
|
138
|
+
assert_equal([[:add_value, 12345.6789, nil]], handler.calls)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_float_exp
|
|
142
|
+
handler = AllSaj.new()
|
|
143
|
+
json = %{12345.6789e7}
|
|
144
|
+
p = Oj::Parser.new(:saj)
|
|
145
|
+
p.handler = handler
|
|
146
|
+
p.parse(json)
|
|
147
|
+
assert_equal(1, handler.calls.size)
|
|
148
|
+
assert_equal(:add_value, handler.calls[0][0])
|
|
149
|
+
assert_equal((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_bignum
|
|
153
|
+
handler = AllSaj.new()
|
|
154
|
+
json = %{-11.899999999999999}
|
|
155
|
+
p = Oj::Parser.new(:saj)
|
|
156
|
+
p.handler = handler
|
|
157
|
+
p.parse(json)
|
|
158
|
+
assert_equal(1, handler.calls.size)
|
|
159
|
+
assert_equal(:add_value, handler.calls[0][0])
|
|
160
|
+
assert_equal(-118999, (handler.calls[0][1] * 10000).to_i)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_bignum_loc
|
|
164
|
+
handler = LocSaj.new()
|
|
165
|
+
json = <<~JSON
|
|
166
|
+
{
|
|
167
|
+
"width": 192.33800000000002,
|
|
168
|
+
"xaxis": {
|
|
169
|
+
"anchor": "y"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
JSON
|
|
173
|
+
|
|
174
|
+
p = Oj::Parser.new(:saj)
|
|
175
|
+
p.handler = handler
|
|
176
|
+
p.parse(json)
|
|
177
|
+
assert_equal(6, handler.calls.size)
|
|
178
|
+
assert_equal(1_923_380, (handler.calls[1][1] * 10000).to_i)
|
|
179
|
+
handler.calls[1][1] = 1_923_380
|
|
180
|
+
assert_equal([[:hash_start, nil, 1, 1],
|
|
181
|
+
[:add_value, 1923380, 'width', 2, 30],
|
|
182
|
+
[:hash_start, 'xaxis', 3, 12],
|
|
183
|
+
[:add_value, 'y', 'anchor', 4, 17],
|
|
184
|
+
[:hash_end, 'xaxis', 5, 3],
|
|
185
|
+
[:hash_end, nil, 6, 1]],
|
|
186
|
+
handler.calls)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def test_array_empty
|
|
190
|
+
handler = AllSaj.new()
|
|
191
|
+
json = %{[]}
|
|
192
|
+
p = Oj::Parser.new(:saj)
|
|
193
|
+
p.handler = handler
|
|
194
|
+
p.parse(json)
|
|
195
|
+
assert_equal([[:array_start, nil],
|
|
196
|
+
[:array_end, nil]], handler.calls)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_array
|
|
200
|
+
handler = AllSaj.new()
|
|
201
|
+
json = %{[true,false]}
|
|
202
|
+
p = Oj::Parser.new(:saj)
|
|
203
|
+
p.handler = handler
|
|
204
|
+
p.parse(json)
|
|
205
|
+
assert_equal([[:array_start, nil],
|
|
206
|
+
[:add_value, true, nil],
|
|
207
|
+
[:add_value, false, nil],
|
|
208
|
+
[:array_end, nil]], handler.calls)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_hash_empty
|
|
212
|
+
handler = AllSaj.new()
|
|
213
|
+
json = %{{}}
|
|
214
|
+
p = Oj::Parser.new(:saj)
|
|
215
|
+
p.handler = handler
|
|
216
|
+
p.parse(json)
|
|
217
|
+
assert_equal([[:hash_start, nil],
|
|
218
|
+
[:hash_end, nil]], handler.calls)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def test_hash
|
|
222
|
+
handler = AllSaj.new()
|
|
223
|
+
json = %{{"one":true,"two":false}}
|
|
224
|
+
p = Oj::Parser.new(:saj)
|
|
225
|
+
p.handler = handler
|
|
226
|
+
p.parse(json)
|
|
227
|
+
assert_equal([[:hash_start, nil],
|
|
228
|
+
[:add_value, true, 'one'],
|
|
229
|
+
[:add_value, false, 'two'],
|
|
230
|
+
[:hash_end, nil]], handler.calls)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def test_full
|
|
234
|
+
handler = AllSaj.new()
|
|
235
|
+
Oj.saj_parse(handler, $json)
|
|
236
|
+
assert_equal([[:hash_start, nil],
|
|
237
|
+
[:array_start, 'array'],
|
|
238
|
+
[:hash_start, nil],
|
|
239
|
+
[:add_value, 3, 'num'],
|
|
240
|
+
[:add_value, 'message', 'string'],
|
|
241
|
+
[:hash_start, 'hash'],
|
|
242
|
+
[:hash_start, 'h2'],
|
|
243
|
+
[:array_start, 'a'],
|
|
244
|
+
[:add_value, 1, nil],
|
|
245
|
+
[:add_value, 2, nil],
|
|
246
|
+
[:add_value, 3, nil],
|
|
247
|
+
[:array_end, 'a'],
|
|
248
|
+
[:hash_end, 'h2'],
|
|
249
|
+
[:hash_end, 'hash'],
|
|
250
|
+
[:hash_end, nil],
|
|
251
|
+
[:array_end, 'array'],
|
|
252
|
+
[:add_value, true, 'boolean'],
|
|
253
|
+
[:hash_end, nil]], handler.calls)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def test_multiple
|
|
257
|
+
handler = AllSaj.new()
|
|
258
|
+
json = %|[true][false]|
|
|
259
|
+
p = Oj::Parser.new(:saj)
|
|
260
|
+
p.handler = handler
|
|
261
|
+
p.parse(json)
|
|
262
|
+
assert_equal([
|
|
263
|
+
[:array_start, nil],
|
|
264
|
+
[:add_value, true, nil],
|
|
265
|
+
[:array_end, nil],
|
|
266
|
+
[:array_start, nil],
|
|
267
|
+
[:add_value, false, nil],
|
|
268
|
+
[:array_end, nil],
|
|
269
|
+
], handler.calls)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def test_io
|
|
273
|
+
handler = AllSaj.new()
|
|
274
|
+
json = %| [true,false] |
|
|
275
|
+
p = Oj::Parser.new(:saj)
|
|
276
|
+
p.handler = handler
|
|
277
|
+
p.load(StringIO.new(json))
|
|
278
|
+
assert_equal([
|
|
279
|
+
[:array_start, nil],
|
|
280
|
+
[:add_value, true, nil],
|
|
281
|
+
[:add_value, false, nil],
|
|
282
|
+
[:array_end, nil],
|
|
283
|
+
], handler.calls)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def test_file
|
|
287
|
+
handler = AllSaj.new()
|
|
288
|
+
p = Oj::Parser.new(:saj)
|
|
289
|
+
p.handler = handler
|
|
290
|
+
p.file('saj_test.json')
|
|
291
|
+
assert_equal([
|
|
292
|
+
[:array_start, nil],
|
|
293
|
+
[:add_value, true, nil],
|
|
294
|
+
[:add_value, false, nil],
|
|
295
|
+
[:array_end, nil],
|
|
296
|
+
], handler.calls)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def test_default
|
|
300
|
+
handler = AllSaj.new()
|
|
301
|
+
json = %|[true]|
|
|
302
|
+
Oj::Parser.saj.handler = handler
|
|
303
|
+
Oj::Parser.saj.parse(json)
|
|
304
|
+
assert_equal([
|
|
305
|
+
[:array_start, nil],
|
|
306
|
+
[:add_value, true, nil],
|
|
307
|
+
[:array_end, nil],
|
|
308
|
+
], handler.calls)
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def test_loc
|
|
312
|
+
handler = LocSaj.new()
|
|
313
|
+
Oj::Parser.saj.handler = handler
|
|
314
|
+
Oj::Parser.saj.parse($json)
|
|
315
|
+
assert_equal([[:hash_start, nil, 1, 1],
|
|
316
|
+
[:array_start, 'array', 2, 12],
|
|
317
|
+
[:hash_start, nil, 3, 5],
|
|
318
|
+
[:add_value, 3, 'num', 4, 18],
|
|
319
|
+
[:add_value, 'message', 'string', 5, 25],
|
|
320
|
+
[:hash_start, 'hash', 6, 17],
|
|
321
|
+
[:hash_start, 'h2', 7, 17],
|
|
322
|
+
[:array_start, 'a', 8, 17],
|
|
323
|
+
[:add_value, 1, nil, 8, 20],
|
|
324
|
+
[:add_value, 2, nil, 8, 23],
|
|
325
|
+
[:add_value, 3, nil, 8, 26],
|
|
326
|
+
[:array_end, 'a', 8, 27],
|
|
327
|
+
[:hash_end, 'h2', 9, 9],
|
|
328
|
+
[:hash_end, 'hash', 10, 7],
|
|
329
|
+
[:hash_end, nil, 11, 5],
|
|
330
|
+
[:array_end, 'array', 12, 3],
|
|
331
|
+
[:add_value, true, 'boolean', 13, 18],
|
|
332
|
+
[:hash_end, nil, 14, 1]], handler.calls)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
end
|