oj 3.16.9 → 3.16.10

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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/oj/fast.c +3 -6
  4. data/ext/oj/mimic_json.c +3 -6
  5. data/ext/oj/oj.c +2 -4
  6. data/ext/oj/parse.c +15 -5
  7. data/ext/oj/parser.c +1 -1
  8. data/ext/oj/parser.h +2 -0
  9. data/ext/oj/rails.c +1 -2
  10. data/ext/oj/saj.c +3 -6
  11. data/ext/oj/scp.c +3 -6
  12. data/ext/oj/stream_writer.c +1 -7
  13. data/ext/oj/strict.c +2 -4
  14. data/ext/oj/string_writer.c +1 -3
  15. data/lib/oj/version.rb +1 -1
  16. metadata +3 -98
  17. data/test/_test_active.rb +0 -75
  18. data/test/_test_active_mimic.rb +0 -95
  19. data/test/_test_mimic_rails.rb +0 -123
  20. data/test/activerecord/result_test.rb +0 -31
  21. data/test/activesupport6/abstract_unit.rb +0 -44
  22. data/test/activesupport6/decoding_test.rb +0 -133
  23. data/test/activesupport6/encoding_test.rb +0 -542
  24. data/test/activesupport6/encoding_test_cases.rb +0 -98
  25. data/test/activesupport6/test_common.rb +0 -17
  26. data/test/activesupport6/test_helper.rb +0 -163
  27. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  28. data/test/activesupport7/abstract_unit.rb +0 -52
  29. data/test/activesupport7/decoding_test.rb +0 -125
  30. data/test/activesupport7/encoding_test.rb +0 -536
  31. data/test/activesupport7/encoding_test_cases.rb +0 -104
  32. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  33. data/test/files.rb +0 -29
  34. data/test/foo.rb +0 -26
  35. data/test/helper.rb +0 -39
  36. data/test/isolated/shared.rb +0 -309
  37. data/test/isolated/test_mimic_after.rb +0 -13
  38. data/test/isolated/test_mimic_alone.rb +0 -12
  39. data/test/isolated/test_mimic_as_json.rb +0 -45
  40. data/test/isolated/test_mimic_before.rb +0 -13
  41. data/test/isolated/test_mimic_define.rb +0 -28
  42. data/test/isolated/test_mimic_rails_after.rb +0 -22
  43. data/test/isolated/test_mimic_rails_before.rb +0 -21
  44. data/test/isolated/test_mimic_redefine.rb +0 -15
  45. data/test/json_gem/json_addition_test.rb +0 -216
  46. data/test/json_gem/json_common_interface_test.rb +0 -155
  47. data/test/json_gem/json_encoding_test.rb +0 -107
  48. data/test/json_gem/json_ext_parser_test.rb +0 -21
  49. data/test/json_gem/json_fixtures_test.rb +0 -36
  50. data/test/json_gem/json_generator_test.rb +0 -413
  51. data/test/json_gem/json_generic_object_test.rb +0 -90
  52. data/test/json_gem/json_parser_test.rb +0 -477
  53. data/test/json_gem/json_string_matching_test.rb +0 -42
  54. data/test/json_gem/test_helper.rb +0 -30
  55. data/test/mem.rb +0 -34
  56. data/test/perf.rb +0 -102
  57. data/test/perf_compat.rb +0 -128
  58. data/test/perf_dump.rb +0 -50
  59. data/test/perf_fast.rb +0 -162
  60. data/test/perf_file.rb +0 -62
  61. data/test/perf_object.rb +0 -134
  62. data/test/perf_once.rb +0 -59
  63. data/test/perf_parser.rb +0 -183
  64. data/test/perf_saj.rb +0 -101
  65. data/test/perf_scp.rb +0 -140
  66. data/test/perf_simple.rb +0 -289
  67. data/test/perf_strict.rb +0 -137
  68. data/test/perf_wab.rb +0 -129
  69. data/test/prec.rb +0 -23
  70. data/test/sample/change.rb +0 -13
  71. data/test/sample/dir.rb +0 -18
  72. data/test/sample/doc.rb +0 -35
  73. data/test/sample/file.rb +0 -47
  74. data/test/sample/group.rb +0 -15
  75. data/test/sample/hasprops.rb +0 -15
  76. data/test/sample/layer.rb +0 -11
  77. data/test/sample/line.rb +0 -20
  78. data/test/sample/oval.rb +0 -10
  79. data/test/sample/rect.rb +0 -9
  80. data/test/sample/shape.rb +0 -34
  81. data/test/sample/text.rb +0 -19
  82. data/test/sample.rb +0 -54
  83. data/test/sample_json.rb +0 -37
  84. data/test/test_compat.rb +0 -567
  85. data/test/test_custom.rb +0 -555
  86. data/test/test_debian.rb +0 -50
  87. data/test/test_fast.rb +0 -526
  88. data/test/test_file.rb +0 -250
  89. data/test/test_gc.rb +0 -60
  90. data/test/test_generate.rb +0 -21
  91. data/test/test_hash.rb +0 -39
  92. data/test/test_integer_range.rb +0 -72
  93. data/test/test_null.rb +0 -376
  94. data/test/test_object.rb +0 -1030
  95. data/test/test_parser.rb +0 -11
  96. data/test/test_parser_debug.rb +0 -27
  97. data/test/test_parser_saj.rb +0 -337
  98. data/test/test_parser_usual.rb +0 -255
  99. data/test/test_rails.rb +0 -35
  100. data/test/test_saj.rb +0 -188
  101. data/test/test_scp.rb +0 -431
  102. data/test/test_strict.rb +0 -441
  103. data/test/test_various.rb +0 -801
  104. data/test/test_wab.rb +0 -311
  105. data/test/test_writer.rb +0 -396
  106. data/test/tests.rb +0 -33
  107. data/test/tests_mimic.rb +0 -23
  108. data/test/tests_mimic_addition.rb +0 -16
data/test/test_parser.rb DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
- @oj_dir = File.dirname(File.expand_path(__dir__))
6
- %w(lib ext).each do |dir|
7
- $LOAD_PATH << File.join(@oj_dir, dir)
8
- end
9
-
10
- require 'test_parser_usual'
11
- require 'test_parser_saj'
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
- @oj_dir = File.dirname(File.expand_path(__dir__))
6
- %w[lib ext].each do |dir|
7
- $LOAD_PATH << 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
@@ -1,337 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
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
-
29
- super
30
- end
31
-
32
- def hash_start(key)
33
- @calls << [:hash_start, key]
34
- end
35
-
36
- def hash_end(key)
37
- @calls << [:hash_end, key]
38
- end
39
-
40
- def array_start(key)
41
- @calls << [:array_start, key]
42
- end
43
-
44
- def array_end(key)
45
- @calls << [:array_end, key]
46
- end
47
-
48
- def add_value(value, key)
49
- @calls << [:add_value, value, key]
50
- end
51
-
52
- def error(message, line, column)
53
- @calls << [:error, message, line, column]
54
- end
55
-
56
- end # AllSaj
57
-
58
- class LocSaj
59
- attr_accessor :calls
60
-
61
- def initialize
62
- @calls = []
63
- end
64
-
65
- def hash_start(key, line, column)
66
- @calls << [:hash_start, key, line, column]
67
- end
68
-
69
- def hash_end(key, line, column)
70
- @calls << [:hash_end, key, line, column]
71
- end
72
-
73
- def array_start(key, line, column)
74
- @calls << [:array_start, key, line, column]
75
- end
76
-
77
- def array_end(key, line, column)
78
- @calls << [:array_end, key, line, column]
79
- end
80
-
81
- def add_value(value, key, line, column)
82
- @calls << [:add_value, value, key, line, column]
83
- end
84
-
85
- end # LocSaj
86
-
87
- class SajTest < Minitest::Test
88
-
89
- def test_nil
90
- handler = AllSaj.new()
91
- json = %{null}
92
- p = Oj::Parser.new(:saj)
93
- p.handler = handler
94
- p.parse(json)
95
- assert_equal([[:add_value, nil, nil]], handler.calls)
96
- end
97
-
98
- def test_true
99
- handler = AllSaj.new()
100
- json = %{true}
101
- p = Oj::Parser.new(:saj)
102
- p.handler = handler
103
- p.parse(json)
104
- assert_equal([[:add_value, true, nil]], handler.calls)
105
- end
106
-
107
- def test_false
108
- handler = AllSaj.new()
109
- json = %{false}
110
- p = Oj::Parser.new(:saj)
111
- p.handler = handler
112
- p.parse(json)
113
- assert_equal([[:add_value, false, nil]], handler.calls)
114
- end
115
-
116
- def test_string
117
- handler = AllSaj.new()
118
- json = %{"a string"}
119
- p = Oj::Parser.new(:saj)
120
- p.handler = handler
121
- p.parse(json)
122
- assert_equal([[:add_value, 'a string', nil]], handler.calls)
123
- end
124
-
125
- def test_fixnum
126
- handler = AllSaj.new()
127
- json = %{12345}
128
- p = Oj::Parser.new(:saj)
129
- p.handler = handler
130
- p.parse(json)
131
- assert_equal([[:add_value, 12_345, nil]], handler.calls)
132
- end
133
-
134
- def test_float
135
- handler = AllSaj.new()
136
- json = %{12345.6789}
137
- p = Oj::Parser.new(:saj)
138
- p.handler = handler
139
- p.parse(json)
140
- assert_equal([[:add_value, 12_345.6789, nil]], handler.calls)
141
- end
142
-
143
- def test_float_exp
144
- handler = AllSaj.new()
145
- json = %{12345.6789e7}
146
- p = Oj::Parser.new(:saj)
147
- p.handler = handler
148
- p.parse(json)
149
- assert_equal(1, handler.calls.size)
150
- assert_equal(:add_value, handler.calls[0][0])
151
- assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
152
- end
153
-
154
- def test_bignum
155
- handler = AllSaj.new()
156
- json = %{-11.899999999999999}
157
- p = Oj::Parser.new(:saj)
158
- p.handler = handler
159
- p.parse(json)
160
- assert_equal(1, handler.calls.size)
161
- assert_equal(:add_value, handler.calls[0][0])
162
- assert_equal(-118_999, (handler.calls[0][1] * 10_000).to_i)
163
- end
164
-
165
- def test_bignum_loc
166
- handler = LocSaj.new()
167
- json = <<~JSON
168
- {
169
- "width": 192.33800000000002,
170
- "xaxis": {
171
- "anchor": "y"
172
- }
173
- }
174
- JSON
175
-
176
- p = Oj::Parser.new(:saj)
177
- p.handler = handler
178
- p.parse(json)
179
- assert_equal(6, handler.calls.size)
180
- assert_equal(1_923_380, (handler.calls[1][1] * 10_000).to_i)
181
- handler.calls[1][1] = 1_923_380
182
- assert_equal([[:hash_start, nil, 1, 1],
183
- [:add_value, 1_923_380, 'width', 2, 30],
184
- [:hash_start, 'xaxis', 3, 12],
185
- [:add_value, 'y', 'anchor', 4, 17],
186
- [:hash_end, 'xaxis', 5, 3],
187
- [:hash_end, nil, 6, 1]],
188
- handler.calls)
189
- end
190
-
191
- def test_array_empty
192
- handler = AllSaj.new()
193
- json = %{[]}
194
- p = Oj::Parser.new(:saj)
195
- p.handler = handler
196
- p.parse(json)
197
- assert_equal([[:array_start, nil],
198
- [:array_end, nil]], handler.calls)
199
- end
200
-
201
- def test_array
202
- handler = AllSaj.new()
203
- json = %{[true,false]}
204
- p = Oj::Parser.new(:saj)
205
- p.handler = handler
206
- p.parse(json)
207
- assert_equal([[:array_start, nil],
208
- [:add_value, true, nil],
209
- [:add_value, false, nil],
210
- [:array_end, nil]], handler.calls)
211
- end
212
-
213
- def test_hash_empty
214
- handler = AllSaj.new()
215
- json = %{{}}
216
- p = Oj::Parser.new(:saj)
217
- p.handler = handler
218
- p.parse(json)
219
- assert_equal([[:hash_start, nil],
220
- [:hash_end, nil]], handler.calls)
221
- end
222
-
223
- def test_hash
224
- handler = AllSaj.new()
225
- json = %{{"one":true,"two":false}}
226
- p = Oj::Parser.new(:saj)
227
- p.handler = handler
228
- p.parse(json)
229
- assert_equal([[:hash_start, nil],
230
- [:add_value, true, 'one'],
231
- [:add_value, false, 'two'],
232
- [:hash_end, nil]], handler.calls)
233
- end
234
-
235
- def test_full
236
- handler = AllSaj.new()
237
- Oj.saj_parse(handler, $json)
238
- assert_equal([[:hash_start, nil],
239
- [:array_start, 'array'],
240
- [:hash_start, nil],
241
- [:add_value, 3, 'num'],
242
- [:add_value, 'message', 'string'],
243
- [:hash_start, 'hash'],
244
- [:hash_start, 'h2'],
245
- [:array_start, 'a'],
246
- [:add_value, 1, nil],
247
- [:add_value, 2, nil],
248
- [:add_value, 3, nil],
249
- [:array_end, 'a'],
250
- [:hash_end, 'h2'],
251
- [:hash_end, 'hash'],
252
- [:hash_end, nil],
253
- [:array_end, 'array'],
254
- [:add_value, true, 'boolean'],
255
- [:hash_end, nil]], handler.calls)
256
- end
257
-
258
- def test_multiple
259
- handler = AllSaj.new()
260
- json = %|[true][false]|
261
- p = Oj::Parser.new(:saj)
262
- p.handler = handler
263
- p.parse(json)
264
- assert_equal([
265
- [:array_start, nil],
266
- [:add_value, true, nil],
267
- [:array_end, nil],
268
- [:array_start, nil],
269
- [:add_value, false, nil],
270
- [:array_end, nil],
271
- ], handler.calls)
272
- end
273
-
274
- def test_io
275
- handler = AllSaj.new()
276
- json = %| [true,false] |
277
- p = Oj::Parser.new(:saj)
278
- p.handler = handler
279
- p.load(StringIO.new(json))
280
- assert_equal([
281
- [:array_start, nil],
282
- [:add_value, true, nil],
283
- [:add_value, false, nil],
284
- [:array_end, nil],
285
- ], handler.calls)
286
- end
287
-
288
- def test_file
289
- handler = AllSaj.new()
290
- p = Oj::Parser.new(:saj)
291
- p.handler = handler
292
- p.file('saj_test.json')
293
- assert_equal([
294
- [:array_start, nil],
295
- [:add_value, true, nil],
296
- [:add_value, false, nil],
297
- [:array_end, nil],
298
- ], handler.calls)
299
- end
300
-
301
- def test_default
302
- handler = AllSaj.new()
303
- json = %|[true]|
304
- Oj::Parser.saj.handler = handler
305
- Oj::Parser.saj.parse(json)
306
- assert_equal([
307
- [:array_start, nil],
308
- [:add_value, true, nil],
309
- [:array_end, nil],
310
- ], handler.calls)
311
- end
312
-
313
- def test_loc
314
- handler = LocSaj.new()
315
- Oj::Parser.saj.handler = handler
316
- Oj::Parser.saj.parse($json)
317
- assert_equal([[:hash_start, nil, 1, 1],
318
- [:array_start, 'array', 2, 12],
319
- [:hash_start, nil, 3, 5],
320
- [:add_value, 3, 'num', 4, 18],
321
- [:add_value, 'message', 'string', 5, 25],
322
- [:hash_start, 'hash', 6, 17],
323
- [:hash_start, 'h2', 7, 17],
324
- [:array_start, 'a', 8, 17],
325
- [:add_value, 1, nil, 8, 20],
326
- [:add_value, 2, nil, 8, 23],
327
- [:add_value, 3, nil, 8, 26],
328
- [:array_end, 'a', 8, 27],
329
- [:hash_end, 'h2', 9, 9],
330
- [:hash_end, 'hash', 10, 7],
331
- [:hash_end, nil, 11, 5],
332
- [:array_end, 'array', 12, 3],
333
- [:add_value, true, 'boolean', 13, 18],
334
- [:hash_end, nil, 14, 1]], handler.calls)
335
- end
336
-
337
- end
@@ -1,255 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- class UsualTest < Minitest::Test
9
-
10
- def test_nil
11
- p = Oj::Parser.new(:usual)
12
- doc = p.parse('nil')
13
- assert_nil(doc)
14
- end
15
-
16
- def test_primitive
17
- p = Oj::Parser.new(:usual)
18
- [
19
- ['true', true],
20
- ['false', false],
21
- ['123', 123],
22
- ['1.25', 1.25],
23
- ['"abc"', 'abc'],
24
- ].each { |x|
25
- doc = p.parse(x[0])
26
- assert_equal(x[1], doc)
27
- }
28
- end
29
-
30
- def test_big
31
- p = Oj::Parser.new(:usual)
32
- doc = p.parse('12345678901234567890123456789')
33
- assert_equal(BigDecimal, doc.class)
34
- doc = p.parse('1234567890.1234567890123456789')
35
- assert_equal(BigDecimal, doc.class)
36
- end
37
-
38
- def test_array
39
- p = Oj::Parser.new(:usual)
40
- [
41
- ['[]', []],
42
- ['[false]', [false]],
43
- ['[true,false]', [true, false]],
44
- ['[[]]', [[]]],
45
- ['[true,[],false]', [true, [], false]],
46
- ['[true,[true],false]', [true, [true], false]],
47
- ].each { |x|
48
- doc = p.parse(x[0])
49
- assert_equal(x[1], doc)
50
- }
51
- end
52
-
53
- def test_hash
54
- p = Oj::Parser.new(:usual)
55
- [
56
- ['{}', {}],
57
- ['{"a": null}', {'a' => nil}],
58
- ['{"t": true, "f": false, "s": "abc"}', {'t' => true, 'f' => false, 's' => 'abc'}],
59
- ['{"a": {}}', {'a' => {}}],
60
- ['{"a": {"b": 2}}', {'a' => {'b' => 2}}],
61
- ['{"a": [true]}', {'a' => [true]}],
62
- ].each { |x|
63
- doc = p.parse(x[0])
64
- assert_equal(x[1], doc)
65
- }
66
- end
67
-
68
- def test_symbol_keys
69
- p = Oj::Parser.new(:usual)
70
- refute(p.symbol_keys)
71
- p.symbol_keys = true
72
- doc = p.parse('{"a": true, "b": false}')
73
- assert_equal({a: true, b: false}, doc)
74
- end
75
-
76
- def test_strings
77
- p = Oj::Parser.new(:usual)
78
- doc = p.parse('{"ぴ": "", "ぴ ": "x", "c": "ぴーたー", "d": " ぴーたー "}')
79
- assert_equal({'ぴ' => '', 'ぴ ' => 'x', 'c' => 'ぴーたー', 'd' => ' ぴーたー '}, doc)
80
- end
81
-
82
- def test_capacity
83
- p = Oj::Parser.new(:usual, capacity: 1000)
84
- assert_equal(4096, p.capacity)
85
- p.capacity = 5000
86
- assert_equal(5000, p.capacity)
87
- end
88
-
89
- def test_decimal
90
- p = Oj::Parser.new(:usual)
91
- assert_equal(:auto, p.decimal)
92
- doc = p.parse('1.234567890123456789')
93
- assert_equal(BigDecimal, doc.class)
94
- assert_equal('0.1234567890123456789e1', doc.to_s)
95
- doc = p.parse('1.25')
96
- assert_equal(Float, doc.class)
97
-
98
- p.decimal = :float
99
- assert_equal(:float, p.decimal)
100
- doc = p.parse('1.234567890123456789')
101
- assert_equal(Float, doc.class)
102
-
103
- p.decimal = :bigdecimal
104
- assert_equal(:bigdecimal, p.decimal)
105
- doc = p.parse('1.234567890123456789')
106
- assert_equal(BigDecimal, doc.class)
107
- doc = p.parse('1.25')
108
- assert_equal(BigDecimal, doc.class)
109
- assert_equal('0.125e1', doc.to_s)
110
-
111
- p.decimal = :ruby
112
- assert_equal(:ruby, p.decimal)
113
- doc = p.parse('1.234567890123456789')
114
- assert_equal(Float, doc.class)
115
- end
116
-
117
- def test_multi_parse
118
- p = Oj::Parser.new(:usual)
119
- out = []
120
- p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| out.push(j) }
121
- assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
122
- end
123
-
124
- def test_multi_load
125
- p = Oj::Parser.new(:usual)
126
- out = []
127
- r, w = IO.pipe
128
- thread = Thread.new do
129
- ['{"a":1}', '{"b":{"x"', ':2}}{"c":', '3}'].each { |seg|
130
- w.write(seg)
131
- sleep(0.1)
132
- }
133
- w.close
134
- end
135
- p.load(r) { |j| out.push(j) }
136
- r.close
137
- thread.join
138
- assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
139
- end
140
-
141
- def test_omit_null
142
- p = Oj::Parser.new(:usual)
143
- p.omit_null = true
144
- doc = p.parse('{"a":true,"b":null}')
145
- assert_equal({'a'=>true}, doc)
146
-
147
- p.omit_null = false
148
- doc = p.parse('{"a":true,"b":null}')
149
- assert_equal({'a'=>true, 'b'=>nil}, doc)
150
- end
151
-
152
- class MyArray < Array
153
- end
154
-
155
- def test_array_class
156
- p = Oj::Parser.new(:usual)
157
- p.array_class = MyArray
158
- assert_equal(MyArray, p.array_class)
159
- doc = p.parse('[true]')
160
- assert_equal(MyArray, doc.class)
161
- end
162
-
163
- class MyHash < Hash
164
- end
165
-
166
- def test_hash_class
167
- p = Oj::Parser.new(:usual)
168
- p.hash_class = MyHash
169
- assert_equal(MyHash, p.hash_class)
170
- doc = p.parse('{"a":true}')
171
- assert_equal(MyHash, doc.class)
172
- end
173
-
174
- def test_empty
175
- p = Oj::Parser.new(:usual)
176
- p.raise_on_empty = false
177
- doc = p.parse(' ')
178
- assert_nil(doc)
179
-
180
- p.raise_on_empty = true
181
- assert_raises(Oj::ParseError) { p.parse(' ') }
182
- end
183
-
184
- class MyClass
185
- attr_accessor :a
186
- attr_accessor :b
187
-
188
- def to_s
189
- "#{self.class}{a: #{@a} b: #{b}}"
190
- end
191
- end
192
-
193
- class MyClass2 < MyClass
194
- def self.json_create(arg)
195
- obj = new
196
- obj.a = arg['a']
197
- obj.b = arg['b']
198
- obj
199
- end
200
- end
201
-
202
- def test_create_id
203
- p = Oj::Parser.new(:usual)
204
- p.create_id = '^'
205
- doc = p.parse('{"a":true}')
206
- assert_equal(Hash, doc.class)
207
- doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
208
- assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
209
-
210
- doc = p.parse('{"a":true,"^":"UsualTest::MyClass2","b":false}')
211
- assert_equal('UsualTest::MyClass2{a: true b: false}', doc.to_s)
212
-
213
- p.hash_class = MyHash
214
- assert_equal(MyHash, p.hash_class)
215
- doc = p.parse('{"a":true}')
216
- assert_equal(MyHash, doc.class)
217
-
218
- doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
219
- assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
220
-
221
- p.create_id = 'class'
222
- doc = p.parse('{"a":true,"class":"UsualTest::MyClass","b":false}')
223
- assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
224
- end
225
-
226
- def test_missing_class
227
- p = Oj::Parser.new(:usual, create_id: '^')
228
- json = '{"a":true,"^":"Auto","b":false}'
229
- doc = p.parse(json)
230
- assert_equal(Hash, doc.class)
231
-
232
- p.missing_class = :auto
233
- doc = p.parse(json)
234
- # Auto should be defined after parsing
235
- assert_equal(Auto, doc.class)
236
- end
237
-
238
- def test_class_cache
239
- p = Oj::Parser.new(:usual)
240
- p.create_id = '^'
241
- p.class_cache = true
242
- p.missing_class = :auto
243
- json = '{"a":true,"^":"Auto2","b":false}'
244
- doc = p.parse(json)
245
- assert_equal(Auto2, doc.class)
246
-
247
- doc = p.parse(json)
248
- assert_equal(Auto2, doc.class)
249
- end
250
-
251
- def test_default_parser
252
- doc = Oj::Parser.usual.parse('{"a":true,"b":null}')
253
- assert_equal({'a'=>true, 'b'=>nil}, doc)
254
- end
255
- end
data/test/test_rails.rb DELETED
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- class RailsJuice < Minitest::Test
9
-
10
- def test_bigdecimal_dump
11
- orig = Oj.default_options
12
- Oj.default_options = { mode: :rails, bigdecimal_as_decimal: true }
13
- bd = BigDecimal('123')
14
- json = Oj.dump(bd)
15
- Oj.default_options = orig
16
-
17
- assert_equal('0.123e3', json.downcase)
18
-
19
- json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: false)
20
- assert_equal('"0.123e3"', json.downcase)
21
-
22
- json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: true)
23
- assert_equal('0.123e3', json.downcase)
24
- end
25
-
26
- def test_invalid_encoding
27
- assert_raises(EncodingError) {
28
- Oj.dump("\"\xf3j", mode: :rails)
29
- }
30
- assert_raises(EncodingError) {
31
- Oj.dump("\xf3j", mode: :rails)
32
- }
33
- end
34
-
35
- end