oj 3.9.1 → 3.16.11

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 (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1452 -0
  3. data/README.md +21 -6
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +50 -68
  6. data/ext/oj/cache.c +329 -0
  7. data/ext/oj/cache.h +22 -0
  8. data/ext/oj/cache8.c +60 -62
  9. data/ext/oj/cache8.h +9 -36
  10. data/ext/oj/circarray.c +38 -42
  11. data/ext/oj/circarray.h +12 -13
  12. data/ext/oj/code.c +158 -179
  13. data/ext/oj/code.h +20 -22
  14. data/ext/oj/compat.c +145 -205
  15. data/ext/oj/custom.c +740 -880
  16. data/ext/oj/debug.c +126 -0
  17. data/ext/oj/dump.c +1145 -844
  18. data/ext/oj/dump.h +71 -57
  19. data/ext/oj/dump_compat.c +575 -655
  20. data/ext/oj/dump_leaf.c +96 -186
  21. data/ext/oj/dump_object.c +533 -660
  22. data/ext/oj/dump_strict.c +306 -340
  23. data/ext/oj/encode.h +4 -33
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +28 -28
  26. data/ext/oj/err.h +39 -42
  27. data/ext/oj/extconf.rb +28 -7
  28. data/ext/oj/fast.c +1052 -1113
  29. data/ext/oj/intern.c +313 -0
  30. data/ext/oj/intern.h +22 -0
  31. data/ext/oj/mem.c +318 -0
  32. data/ext/oj/mem.h +53 -0
  33. data/ext/oj/mimic_json.c +471 -430
  34. data/ext/oj/object.c +532 -580
  35. data/ext/oj/odd.c +156 -142
  36. data/ext/oj/odd.h +25 -26
  37. data/ext/oj/oj.c +1346 -961
  38. data/ext/oj/oj.h +307 -290
  39. data/ext/oj/parse.c +954 -858
  40. data/ext/oj/parse.h +74 -72
  41. data/ext/oj/parser.c +1600 -0
  42. data/ext/oj/parser.h +103 -0
  43. data/ext/oj/rails.c +819 -836
  44. data/ext/oj/rails.h +8 -11
  45. data/ext/oj/reader.c +136 -147
  46. data/ext/oj/reader.h +69 -83
  47. data/ext/oj/resolve.c +41 -63
  48. data/ext/oj/resolve.h +4 -6
  49. data/ext/oj/rxclass.c +69 -72
  50. data/ext/oj/rxclass.h +12 -13
  51. data/ext/oj/saj.c +440 -485
  52. data/ext/oj/saj2.c +584 -0
  53. data/ext/oj/saj2.h +23 -0
  54. data/ext/oj/scp.c +79 -118
  55. data/ext/oj/simd.h +10 -0
  56. data/ext/oj/sparse.c +739 -709
  57. data/ext/oj/stream_writer.c +141 -175
  58. data/ext/oj/strict.c +103 -128
  59. data/ext/oj/string_writer.c +244 -261
  60. data/ext/oj/trace.c +34 -41
  61. data/ext/oj/trace.h +42 -15
  62. data/ext/oj/usual.c +1218 -0
  63. data/ext/oj/usual.h +69 -0
  64. data/ext/oj/util.c +107 -107
  65. data/ext/oj/util.h +4 -3
  66. data/ext/oj/val_stack.c +61 -78
  67. data/ext/oj/val_stack.h +80 -114
  68. data/ext/oj/validate.c +46 -0
  69. data/ext/oj/wab.c +316 -361
  70. data/lib/oj/active_support_helper.rb +1 -3
  71. data/lib/oj/bag.rb +8 -1
  72. data/lib/oj/easy_hash.rb +9 -9
  73. data/lib/oj/error.rb +1 -2
  74. data/lib/oj/json.rb +162 -150
  75. data/lib/oj/mimic.rb +54 -20
  76. data/lib/oj/saj.rb +20 -6
  77. data/lib/oj/schandler.rb +5 -4
  78. data/lib/oj/state.rb +12 -8
  79. data/lib/oj/version.rb +1 -2
  80. data/lib/oj.rb +2 -8
  81. data/pages/Compatibility.md +1 -1
  82. data/pages/Encoding.md +1 -1
  83. data/pages/InstallOptions.md +20 -0
  84. data/pages/JsonGem.md +15 -0
  85. data/pages/Modes.md +9 -3
  86. data/pages/Options.md +62 -12
  87. data/pages/Parser.md +309 -0
  88. data/pages/Rails.md +73 -22
  89. metadata +68 -192
  90. data/ext/oj/hash.c +0 -163
  91. data/ext/oj/hash.h +0 -46
  92. data/ext/oj/hash_test.c +0 -512
  93. data/test/_test_active.rb +0 -76
  94. data/test/_test_active_mimic.rb +0 -96
  95. data/test/_test_mimic_rails.rb +0 -126
  96. data/test/activerecord/result_test.rb +0 -27
  97. data/test/activesupport4/decoding_test.rb +0 -108
  98. data/test/activesupport4/encoding_test.rb +0 -531
  99. data/test/activesupport4/test_helper.rb +0 -41
  100. data/test/activesupport5/decoding_test.rb +0 -125
  101. data/test/activesupport5/encoding_test.rb +0 -485
  102. data/test/activesupport5/encoding_test_cases.rb +0 -90
  103. data/test/activesupport5/test_helper.rb +0 -50
  104. data/test/activesupport5/time_zone_test_helpers.rb +0 -24
  105. data/test/bar.rb +0 -25
  106. data/test/files.rb +0 -29
  107. data/test/foo.rb +0 -21
  108. data/test/helper.rb +0 -26
  109. data/test/isolated/shared.rb +0 -308
  110. data/test/isolated/test_mimic_after.rb +0 -13
  111. data/test/isolated/test_mimic_alone.rb +0 -12
  112. data/test/isolated/test_mimic_as_json.rb +0 -45
  113. data/test/isolated/test_mimic_before.rb +0 -13
  114. data/test/isolated/test_mimic_define.rb +0 -28
  115. data/test/isolated/test_mimic_rails_after.rb +0 -22
  116. data/test/isolated/test_mimic_rails_before.rb +0 -21
  117. data/test/isolated/test_mimic_redefine.rb +0 -15
  118. data/test/json_gem/json_addition_test.rb +0 -216
  119. data/test/json_gem/json_common_interface_test.rb +0 -148
  120. data/test/json_gem/json_encoding_test.rb +0 -107
  121. data/test/json_gem/json_ext_parser_test.rb +0 -20
  122. data/test/json_gem/json_fixtures_test.rb +0 -35
  123. data/test/json_gem/json_generator_test.rb +0 -383
  124. data/test/json_gem/json_generic_object_test.rb +0 -90
  125. data/test/json_gem/json_parser_test.rb +0 -470
  126. data/test/json_gem/json_string_matching_test.rb +0 -42
  127. data/test/json_gem/test_helper.rb +0 -18
  128. data/test/perf.rb +0 -107
  129. data/test/perf_compat.rb +0 -130
  130. data/test/perf_fast.rb +0 -164
  131. data/test/perf_file.rb +0 -64
  132. data/test/perf_object.rb +0 -138
  133. data/test/perf_saj.rb +0 -109
  134. data/test/perf_scp.rb +0 -151
  135. data/test/perf_simple.rb +0 -287
  136. data/test/perf_strict.rb +0 -145
  137. data/test/perf_wab.rb +0 -131
  138. data/test/sample/change.rb +0 -14
  139. data/test/sample/dir.rb +0 -19
  140. data/test/sample/doc.rb +0 -36
  141. data/test/sample/file.rb +0 -48
  142. data/test/sample/group.rb +0 -16
  143. data/test/sample/hasprops.rb +0 -16
  144. data/test/sample/layer.rb +0 -12
  145. data/test/sample/line.rb +0 -20
  146. data/test/sample/oval.rb +0 -10
  147. data/test/sample/rect.rb +0 -10
  148. data/test/sample/shape.rb +0 -35
  149. data/test/sample/text.rb +0 -20
  150. data/test/sample.rb +0 -54
  151. data/test/sample_json.rb +0 -37
  152. data/test/test_compat.rb +0 -509
  153. data/test/test_custom.rb +0 -503
  154. data/test/test_debian.rb +0 -53
  155. data/test/test_fast.rb +0 -470
  156. data/test/test_file.rb +0 -239
  157. data/test/test_gc.rb +0 -49
  158. data/test/test_hash.rb +0 -29
  159. data/test/test_integer_range.rb +0 -73
  160. data/test/test_null.rb +0 -376
  161. data/test/test_object.rb +0 -1018
  162. data/test/test_saj.rb +0 -186
  163. data/test/test_scp.rb +0 -433
  164. data/test/test_strict.rb +0 -410
  165. data/test/test_various.rb +0 -741
  166. data/test/test_wab.rb +0 -307
  167. data/test/test_writer.rb +0 -380
  168. data/test/tests.rb +0 -24
  169. data/test/tests_mimic.rb +0 -14
  170. data/test/tests_mimic_addition.rb +0 -7
  171. data/test/zoo.rb +0 -13
data/test/test_saj.rb DELETED
@@ -1,186 +0,0 @@
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 SajTest < Minitest::Test
57
-
58
- def setup
59
- @default_options = Oj.default_options
60
- end
61
-
62
- def teardown
63
- Oj.default_options = @default_options
64
- end
65
-
66
- def test_nil
67
- handler = AllSaj.new()
68
- json = %{null}
69
- Oj.saj_parse(handler, json)
70
- assert_equal([[:add_value, nil, nil]], handler.calls)
71
- end
72
-
73
- def test_true
74
- handler = AllSaj.new()
75
- json = %{true}
76
- Oj.saj_parse(handler, json)
77
- assert_equal([[:add_value, true, nil]], handler.calls)
78
- end
79
-
80
- def test_false
81
- handler = AllSaj.new()
82
- json = %{false}
83
- Oj.saj_parse(handler, json)
84
- assert_equal([[:add_value, false, nil]], handler.calls)
85
- end
86
-
87
- def test_string
88
- handler = AllSaj.new()
89
- json = %{"a string"}
90
- Oj.saj_parse(handler, json)
91
- assert_equal([[:add_value, 'a string', nil]], handler.calls)
92
- end
93
-
94
- def test_fixnum
95
- handler = AllSaj.new()
96
- json = %{12345}
97
- Oj.saj_parse(handler, json)
98
- assert_equal([[:add_value, 12345, nil]], handler.calls)
99
- end
100
-
101
- def test_float
102
- handler = AllSaj.new()
103
- json = %{12345.6789}
104
- Oj.saj_parse(handler, json)
105
- assert_equal([[:add_value, 12345.6789, nil]], handler.calls)
106
- end
107
-
108
- def test_float_exp
109
- handler = AllSaj.new()
110
- json = %{12345.6789e7}
111
- Oj.saj_parse(handler, json)
112
- assert_equal(1, handler.calls.size)
113
- assert_equal(:add_value, handler.calls[0][0])
114
- assert_equal((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
115
- end
116
-
117
- def test_array_empty
118
- handler = AllSaj.new()
119
- json = %{[]}
120
- Oj.saj_parse(handler, json)
121
- assert_equal([[:array_start, nil],
122
- [:array_end, nil]], handler.calls)
123
- end
124
-
125
- def test_array
126
- handler = AllSaj.new()
127
- json = %{[true,false]}
128
- Oj.saj_parse(handler, json)
129
- assert_equal([[:array_start, nil],
130
- [:add_value, true, nil],
131
- [:add_value, false, nil],
132
- [:array_end, nil]], handler.calls)
133
- end
134
-
135
- def test_hash_empty
136
- handler = AllSaj.new()
137
- json = %{{}}
138
- Oj.saj_parse(handler, json)
139
- assert_equal([[:hash_start, nil],
140
- [:hash_end, nil]], handler.calls)
141
- end
142
-
143
- def test_hash
144
- handler = AllSaj.new()
145
- json = %{{"one":true,"two":false}}
146
- Oj.saj_parse(handler, json)
147
- assert_equal([[:hash_start, nil],
148
- [:add_value, true, 'one'],
149
- [:add_value, false, 'two'],
150
- [:hash_end, nil]], handler.calls)
151
- end
152
-
153
- def test_full
154
- handler = AllSaj.new()
155
- Oj.saj_parse(handler, $json)
156
- assert_equal([[:hash_start, nil],
157
- [:array_start, 'array'],
158
- [:hash_start, nil],
159
- [:add_value, 3, 'num'],
160
- [:add_value, 'message', 'string'],
161
- [:hash_start, 'hash'],
162
- [:hash_start, 'h2'],
163
- [:array_start, 'a'],
164
- [:add_value, 1, nil],
165
- [:add_value, 2, nil],
166
- [:add_value, 3, nil],
167
- [:array_end, 'a'],
168
- [:hash_end, 'h2'],
169
- [:hash_end, 'hash'],
170
- [:hash_end, nil],
171
- [:array_end, 'array'],
172
- [:add_value, true, 'boolean'],
173
- [:hash_end, nil]], handler.calls)
174
- end
175
-
176
- def test_fixnum_bad
177
- handler = AllSaj.new()
178
- json = %{12345xyz}
179
- Oj.saj_parse(handler, json)
180
- assert_equal([:add_value, 12345, nil], handler.calls.first)
181
- type, message, line, column = handler.calls.last
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)
184
- end
185
-
186
- end
data/test/test_scp.rb DELETED
@@ -1,433 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- $: << File.dirname(__FILE__)
5
-
6
- require 'helper'
7
- require 'socket'
8
- require 'stringio'
9
-
10
- $json = %{{
11
- "array": [
12
- {
13
- "num" : 3,
14
- "string": "message",
15
- "hash" : {
16
- "h2" : {
17
- "a" : [ 1, 2, 3 ]
18
- }
19
- }
20
- }
21
- ],
22
- "boolean" : true
23
- }}
24
-
25
- class NoHandler < Oj::ScHandler
26
- def initialize()
27
- end
28
- end
29
-
30
- class AllHandler < Oj::ScHandler
31
- attr_accessor :calls
32
-
33
- def initialize()
34
- @calls = []
35
- end
36
-
37
- def hash_start()
38
- @calls << [:hash_start]
39
- {}
40
- end
41
-
42
- def hash_end()
43
- @calls << [:hash_end]
44
- end
45
-
46
- def hash_key(key)
47
- @calls << [:hash_key, key]
48
- return 'too' if 'two' == key
49
- return :symbol if 'symbol' == key
50
- key
51
- end
52
-
53
- def array_start()
54
- @calls << [:array_start]
55
- []
56
- end
57
-
58
- def array_end()
59
- @calls << [:array_end]
60
- end
61
-
62
- def add_value(value)
63
- @calls << [:add_value, value]
64
- end
65
-
66
- def hash_set(h, key, value)
67
- @calls << [:hash_set, key, value]
68
- end
69
-
70
- def array_append(a, value)
71
- @calls << [:array_append, value]
72
- end
73
-
74
- end # AllHandler
75
-
76
- class Closer < AllHandler
77
- attr_accessor :io
78
- def initialize(io)
79
- super()
80
- @io = io
81
- end
82
-
83
- def hash_start()
84
- @calls << [:hash_start]
85
- @io.close
86
- {}
87
- end
88
-
89
- def hash_set(h, key, value)
90
- @calls << [:hash_set, key, value]
91
- @io.close
92
- end
93
-
94
- end # Closer
95
-
96
- class ScpTest < Minitest::Test
97
-
98
- def setup
99
- @default_options = Oj.default_options
100
- end
101
-
102
- def teardown
103
- Oj.default_options = @default_options
104
- end
105
-
106
- def test_nil
107
- handler = AllHandler.new()
108
- json = %{null}
109
- Oj.sc_parse(handler, json)
110
- assert_equal([[:add_value, nil]], handler.calls)
111
- end
112
-
113
- def test_true
114
- handler = AllHandler.new()
115
- json = %{true}
116
- Oj.sc_parse(handler, json)
117
- assert_equal([[:add_value, true]], handler.calls)
118
- end
119
-
120
- def test_false
121
- handler = AllHandler.new()
122
- json = %{false}
123
- Oj.sc_parse(handler, json)
124
- assert_equal([[:add_value, false]], handler.calls)
125
- end
126
-
127
- def test_string
128
- handler = AllHandler.new()
129
- json = %{"a string"}
130
- Oj.sc_parse(handler, json)
131
- assert_equal([[:add_value, 'a string']], handler.calls)
132
- end
133
-
134
- def test_fixnum
135
- handler = AllHandler.new()
136
- json = %{12345}
137
- Oj.sc_parse(handler, json)
138
- assert_equal([[:add_value, 12345]], handler.calls)
139
- end
140
-
141
- def test_float
142
- handler = AllHandler.new()
143
- json = %{12345.6789}
144
- Oj.sc_parse(handler, json)
145
- assert_equal([[:add_value, 12345.6789]], handler.calls)
146
- end
147
-
148
- def test_float_exp
149
- handler = AllHandler.new()
150
- json = %{12345.6789e7}
151
- Oj.sc_parse(handler, json)
152
- assert_equal(1, handler.calls.size)
153
- assert_equal(:add_value, handler.calls[0][0])
154
- assert_equal((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
155
- end
156
-
157
- def test_array_empty
158
- handler = AllHandler.new()
159
- json = %{[]}
160
- Oj.sc_parse(handler, json)
161
- assert_equal([[:array_start],
162
- [:array_end],
163
- [:add_value, []]], handler.calls)
164
- end
165
-
166
- def test_array
167
- handler = AllHandler.new()
168
- json = %{[true,false]}
169
- Oj.sc_parse(handler, json)
170
- assert_equal([[:array_start],
171
- [:array_append, true],
172
- [:array_append, false],
173
- [:array_end],
174
- [:add_value, []]], handler.calls)
175
- end
176
-
177
- def test_hash_empty
178
- handler = AllHandler.new()
179
- json = %{{}}
180
- Oj.sc_parse(handler, json)
181
- assert_equal([[:hash_start],
182
- [:hash_end],
183
- [:add_value, {}]], handler.calls)
184
- end
185
-
186
- def test_hash
187
- handler = AllHandler.new()
188
- json = %{{"one":true,"two":false}}
189
- Oj.sc_parse(handler, json)
190
- assert_equal([[:hash_start],
191
- [:hash_key, 'one'],
192
- [:hash_set, 'one', true],
193
- [:hash_key, 'two'],
194
- [:hash_set, 'too', false],
195
- [:hash_end],
196
- [:add_value, {}]], handler.calls)
197
- end
198
-
199
- def test_hash_sym
200
- handler = AllHandler.new()
201
- json = %{{"one":true,"two":false}}
202
- Oj.sc_parse(handler, json, :symbol_keys => true)
203
- assert_equal([[:hash_start],
204
- [:hash_key, 'one'],
205
- [:hash_set, 'one', true],
206
- [:hash_key, 'two'],
207
- [:hash_set, 'too', false],
208
- [:hash_end],
209
- [:add_value, {}]], handler.calls)
210
- end
211
-
212
- def test_symbol_hash_key_without_symbol_keys
213
- handler = AllHandler.new()
214
- json = %{{"one":true,"symbol":false}}
215
- Oj.sc_parse(handler, json)
216
- assert_equal([[:hash_start],
217
- [:hash_key, 'one'],
218
- [:hash_set, 'one', true],
219
- [:hash_key, 'symbol'],
220
- [:hash_set, :symbol, false],
221
- [:hash_end],
222
- [:add_value, {}]], handler.calls)
223
- end
224
-
225
- def test_full
226
- handler = AllHandler.new()
227
- Oj.sc_parse(handler, $json)
228
- assert_equal([[:hash_start],
229
- [:hash_key, 'array'],
230
- [:array_start],
231
- [:hash_start],
232
- [:hash_key, 'num'],
233
- [:hash_set, "num", 3],
234
- [:hash_key, 'string'],
235
- [:hash_set, "string", "message"],
236
- [:hash_key, 'hash'],
237
- [:hash_start],
238
- [:hash_key, 'h2'],
239
- [:hash_start],
240
- [:hash_key, 'a'],
241
- [:array_start],
242
- [:array_append, 1],
243
- [:array_append, 2],
244
- [:array_append, 3],
245
- [:array_end],
246
- [:hash_set, "a", []],
247
- [:hash_end],
248
- [:hash_set, "h2", {}],
249
- [:hash_end],
250
- [:hash_set, "hash", {}],
251
- [:hash_end],
252
- [:array_append, {}],
253
- [:array_end],
254
- [:hash_set, "array", []],
255
- [:hash_key, 'boolean'],
256
- [:hash_set, "boolean", true],
257
- [:hash_end],
258
- [:add_value, {}]], handler.calls)
259
- end
260
-
261
- def test_double
262
- handler = AllHandler.new()
263
- json = %{{"one":true,"two":false}{"three":true,"four":false}}
264
- Oj.sc_parse(handler, json)
265
- assert_equal([[:hash_start],
266
- [:hash_key, 'one'],
267
- [:hash_set, 'one', true],
268
- [:hash_key, 'two'],
269
- [:hash_set, 'too', false],
270
- [:hash_end],
271
- [:add_value, {}],
272
- [:hash_start],
273
- [:hash_key, 'three'],
274
- [:hash_set, 'three', true],
275
- [:hash_key, 'four'],
276
- [:hash_set, 'four', false],
277
- [:hash_end],
278
- [:add_value, {}]], handler.calls)
279
- end
280
-
281
- def test_double_io
282
- handler = AllHandler.new()
283
- json = %{{"one":true,"two":false}{"three":true,"four":false}}
284
- Oj.sc_parse(handler, StringIO.new(json))
285
- assert_equal([[:hash_start],
286
- [:hash_key, 'one'],
287
- [:hash_set, 'one', true],
288
- [:hash_key, 'two'],
289
- [:hash_set, 'too', false],
290
- [:hash_end],
291
- [:add_value, {}],
292
- [:hash_start],
293
- [:hash_key, 'three'],
294
- [:hash_set, 'three', true],
295
- [:hash_key, 'four'],
296
- [:hash_set, 'four', false],
297
- [:hash_end],
298
- [:add_value, {}]], handler.calls)
299
- end
300
-
301
- def test_none
302
- handler = NoHandler.new()
303
- Oj.sc_parse(handler, $json)
304
- end
305
-
306
- def test_fixnum_bad
307
- handler = AllHandler.new()
308
- json = %{12345xyz}
309
- assert_raises Oj::ParseError do
310
- Oj.sc_parse(handler, json)
311
- end
312
- end
313
-
314
- def test_null_string
315
- handler = AllHandler.new()
316
- json = %{"\0"}
317
- assert_raises Oj::ParseError do
318
- Oj.sc_parse(handler, json)
319
- end
320
- end
321
-
322
- def test_pipe
323
- # Windows does not support fork
324
- return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
325
-
326
- handler = AllHandler.new()
327
- json = %{{"one":true,"two":false}}
328
- IO.pipe do |read_io, write_io|
329
- if fork
330
- write_io.close
331
- Oj.sc_parse(handler, read_io) {|v| p v}
332
- read_io.close
333
- assert_equal([[:hash_start],
334
- [:hash_key, 'one'],
335
- [:hash_set, 'one', true],
336
- [:hash_key, 'two'],
337
- [:hash_set, 'too', false],
338
- [:hash_end],
339
- [:add_value, {}]], handler.calls)
340
- else
341
- read_io.close
342
- write_io.write json
343
- write_io.close
344
- Process.exit(0)
345
- end
346
- end
347
- end
348
-
349
- def test_bad_bignum
350
- if '2.4.0' < RUBY_VERSION
351
- handler = AllHandler.new()
352
- json = %|{"big":-e123456789}|
353
- assert_raises Exception do # Can be either Oj::ParseError or ArgumentError depending on Ruby version
354
- Oj.sc_parse(handler, json)
355
- end
356
- end
357
- end
358
-
359
- def test_pipe_close
360
- # Windows does not support fork
361
- return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
362
-
363
- json = %{{"one":true,"two":false}}
364
- IO.pipe do |read_io, write_io|
365
- if fork
366
- write_io.close
367
- handler = Closer.new(read_io)
368
- err = nil
369
- begin
370
- Oj.sc_parse(handler, read_io)
371
- read_io.close
372
- rescue Exception => e
373
- err = e.class.to_s
374
- end
375
- assert_equal("IOError", err)
376
- assert_equal([[:hash_start],
377
- [:hash_key, 'one'],
378
- [:hash_set, 'one', true]], handler.calls)
379
- else
380
- read_io.close
381
- write_io.write json[0..11]
382
- sleep(0.1)
383
- begin
384
- write_io.write json[12..-1]
385
- rescue Exception => e
386
- # ignore, should fail to write
387
- end
388
- write_io.close
389
- Process.exit(0)
390
- end
391
- end
392
- end
393
-
394
- def test_socket_close
395
- json = %{{"one":true,"two":false}}
396
- begin
397
- server = TCPServer.new(8080)
398
- rescue
399
- # Not able to open a socket to run the test. Might be Travis.
400
- return
401
- end
402
- Thread.start(json) do |j|
403
- c = server.accept()
404
- c.puts json[0..11]
405
- 10.times {
406
- break if c.closed?
407
- sleep(0.1)
408
- }
409
- unless c.closed?
410
- c.puts json[12..-1]
411
- c.close
412
- end
413
- end
414
- begin
415
- sock = TCPSocket.new('localhost', 8080)
416
- rescue
417
- # Not able to open a socket to run the test. Might be Travis.
418
- return
419
- end
420
- handler = Closer.new(sock)
421
- err = nil
422
- begin
423
- Oj.sc_parse(handler, sock)
424
- rescue Exception => e
425
- err = e.class.to_s
426
- end
427
- assert_equal("IOError", err)
428
- assert_equal([[:hash_start],
429
- [:hash_key, 'one'],
430
- [:hash_set, 'one', true]], handler.calls)
431
- end
432
-
433
- end