oj 2.18.5 → 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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1452 -0
- data/README.md +53 -221
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +54 -72
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +61 -63
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +38 -67
- data/ext/oj/circarray.h +16 -42
- data/ext/oj/code.c +214 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +194 -110
- data/ext/oj/custom.c +1074 -0
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +1276 -2494
- data/ext/oj/dump.h +110 -0
- data/ext/oj/dump_compat.c +897 -0
- data/ext/oj/dump_leaf.c +162 -0
- data/ext/oj/dump_object.c +710 -0
- data/ext/oj/dump_strict.c +399 -0
- data/ext/oj/encode.h +7 -42
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +28 -53
- data/ext/oj/err.h +49 -46
- data/ext/oj/extconf.rb +33 -32
- data/ext/oj/fast.c +1082 -1098
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +919 -0
- data/ext/oj/object.c +545 -625
- data/ext/oj/odd.c +158 -168
- data/ext/oj/odd.h +32 -58
- data/ext/oj/oj.c +1727 -2080
- data/ext/oj/oj.h +334 -259
- data/ext/oj/parse.c +974 -753
- data/ext/oj/parse.h +97 -90
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +103 -0
- data/ext/oj/rails.c +1478 -0
- data/ext/oj/rails.h +18 -0
- data/ext/oj/reader.c +136 -163
- data/ext/oj/reader.h +76 -112
- data/ext/oj/resolve.c +45 -94
- data/ext/oj/resolve.h +7 -34
- data/ext/oj/rxclass.c +144 -0
- data/ext/oj/rxclass.h +26 -0
- data/ext/oj/saj.c +445 -511
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +82 -143
- data/ext/oj/simd.h +10 -0
- data/ext/oj/sparse.c +749 -644
- data/ext/oj/stream_writer.c +329 -0
- data/ext/oj/strict.c +114 -112
- data/ext/oj/string_writer.c +517 -0
- data/ext/oj/trace.c +72 -0
- data/ext/oj/trace.h +55 -0
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +75 -72
- data/ext/oj/val_stack.h +94 -127
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +586 -0
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +8 -1
- data/lib/oj/easy_hash.rb +21 -13
- data/lib/oj/error.rb +10 -12
- data/lib/oj/json.rb +188 -0
- data/lib/oj/mimic.rb +165 -26
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +135 -0
- data/lib/oj/version.rb +2 -3
- data/lib/oj.rb +3 -31
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +94 -0
- data/pages/Modes.md +161 -0
- data/pages/Options.md +337 -0
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +167 -0
- data/pages/Security.md +20 -0
- data/pages/WAB.md +13 -0
- metadata +126 -163
- 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_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activesupport_datetime_test.rb +0 -23
- data/test/bug.rb +0 -51
- data/test/bug2.rb +0 -10
- data/test/bug3.rb +0 -46
- data/test/bug_fast.rb +0 -32
- data/test/bug_load.rb +0 -24
- data/test/crash.rb +0 -111
- data/test/curl/curl_oj.rb +0 -46
- data/test/curl/get_oj.rb +0 -24
- data/test/curl/just_curl.rb +0 -31
- data/test/curl/just_oj.rb +0 -51
- data/test/example.rb +0 -11
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -24
- data/test/helper.rb +0 -27
- data/test/io.rb +0 -48
- data/test/isolated/shared.rb +0 -310
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/mod.rb +0 -16
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -128
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -151
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -128
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -55
- data/test/sample_json.rb +0 -37
- data/test/struct.rb +0 -29
- data/test/test_compat.rb +0 -398
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -458
- data/test/test_file.rb +0 -245
- data/test/test_gc.rb +0 -49
- data/test/test_hash.rb +0 -29
- data/test/test_object.rb +0 -745
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -396
- data/test/test_serializer.rb +0 -59
- data/test/test_strict.rb +0 -254
- data/test/test_various.rb +0 -1383
- data/test/test_writer.rb +0 -308
- data/test/write_timebars.rb +0 -31
data/test/io.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class Handler
|
9
|
-
def initialize
|
10
|
-
@state = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def hash_start
|
14
|
-
@state << {}
|
15
|
-
@state.last
|
16
|
-
end
|
17
|
-
|
18
|
-
def hash_end
|
19
|
-
@state.pop
|
20
|
-
end
|
21
|
-
|
22
|
-
def hash_set(h,k,v)
|
23
|
-
h.store(k,v)
|
24
|
-
end
|
25
|
-
|
26
|
-
def array_start
|
27
|
-
@state << []
|
28
|
-
@state.last
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def array_end
|
33
|
-
@state.pop
|
34
|
-
end
|
35
|
-
|
36
|
-
def array_append(a,v)
|
37
|
-
a << v
|
38
|
-
end
|
39
|
-
|
40
|
-
def error(message, line, column); p "ERROR: #{message}" end
|
41
|
-
end
|
42
|
-
|
43
|
-
handler = Handler.new
|
44
|
-
def handler.add_value(v)
|
45
|
-
p v
|
46
|
-
end
|
47
|
-
|
48
|
-
Oj.sc_parse(handler, StringIO.new('{"a":"b","c":[1,2,{"d":"e"}]}[4,5,6]'))
|
data/test/isolated/shared.rb
DELETED
@@ -1,310 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# The rails tests set this to true. Both Rails and the JSON gem monkey patch the
|
4
|
-
# as_json methods on several base classes. Depending on which one replaces the
|
5
|
-
# method last the behavior will be different. Oj.mimic_JSON abides by the same
|
6
|
-
# conflicting behavior and the tests reflect that.
|
7
|
-
$rails_monkey = false unless defined?($rails_monkey)
|
8
|
-
|
9
|
-
class SharedMimicTest < Minitest::Test
|
10
|
-
class Jam
|
11
|
-
attr_accessor :x, :y
|
12
|
-
|
13
|
-
def initialize(x, y)
|
14
|
-
@x = x
|
15
|
-
@y = y
|
16
|
-
end
|
17
|
-
|
18
|
-
def eql?(o)
|
19
|
-
self.class == o.class && @x == o.x && @y == o.y
|
20
|
-
end
|
21
|
-
alias == eql?
|
22
|
-
|
23
|
-
def as_json()
|
24
|
-
{"json_class" => self.class.to_s,"x" => @x,"y" => @y}
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.json_create(h)
|
28
|
-
self.new(h['x'], h['y'])
|
29
|
-
end
|
30
|
-
|
31
|
-
end # Jam
|
32
|
-
|
33
|
-
def setup
|
34
|
-
@default_options = Oj.default_options
|
35
|
-
@time = Time.at(1400000000).utc
|
36
|
-
@expected_time_string =
|
37
|
-
if defined?(Rails)
|
38
|
-
%{"2014-05-13T16:53:20.000Z"}
|
39
|
-
elsif RUBY_VERSION.start_with?('1.8')
|
40
|
-
%{"Tue May 13 16:53:20 UTC 2014"}
|
41
|
-
else
|
42
|
-
%{"2014-05-13 16:53:20 UTC"}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def teardown
|
47
|
-
Oj.default_options = @default_options
|
48
|
-
end
|
49
|
-
|
50
|
-
# exception
|
51
|
-
def test_exception
|
52
|
-
begin
|
53
|
-
JSON.parse("{")
|
54
|
-
puts "Failed"
|
55
|
-
rescue JSON::ParserError
|
56
|
-
assert(true)
|
57
|
-
rescue Exception
|
58
|
-
assert(false, 'Expected a JSON::ParserError')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# dump
|
63
|
-
def test_dump_string
|
64
|
-
json = JSON.dump([1, true, nil, @time])
|
65
|
-
if $rails_monkey
|
66
|
-
assert_equal(%{[1,true,null,#{@expected_time_string}]}, json)
|
67
|
-
else
|
68
|
-
assert_equal(%{[1,true,null,{"json_class":"Time","s":1400000000,"n":0}]}, json)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_dump_with_options
|
73
|
-
Oj.default_options= {:indent => 2} # JSON this will not change anything
|
74
|
-
json = JSON.dump([1, true, nil, @time])
|
75
|
-
if $rails_monkey
|
76
|
-
assert_equal(%{[
|
77
|
-
1,
|
78
|
-
true,
|
79
|
-
null,
|
80
|
-
#{@expected_time_string}
|
81
|
-
]
|
82
|
-
}, json)
|
83
|
-
else
|
84
|
-
assert_equal(%{[
|
85
|
-
1,
|
86
|
-
true,
|
87
|
-
null,
|
88
|
-
{
|
89
|
-
"json_class":"Time",
|
90
|
-
"s":1400000000,
|
91
|
-
"n\":0
|
92
|
-
}
|
93
|
-
]
|
94
|
-
}, json)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_dump_io
|
99
|
-
s = StringIO.new()
|
100
|
-
json = JSON.dump([1, true, nil, @time], s)
|
101
|
-
assert_equal(s, json)
|
102
|
-
if $rails_monkey
|
103
|
-
assert_equal(%{[1,true,null,#{@expected_time_string}]}, s.string)
|
104
|
-
else
|
105
|
-
assert_equal(%{[1,true,null,{"json_class":"Time","s":1400000000,"n":0}]}, s.string)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
# TBD options
|
109
|
-
|
110
|
-
def test_dump_struct
|
111
|
-
# anonymous Struct not supported by json so name it
|
112
|
-
if Object.const_defined?("Struct::Abc")
|
113
|
-
s = Struct::Abc
|
114
|
-
else
|
115
|
-
s = Struct.new("Abc", :a, :b, :c)
|
116
|
-
end
|
117
|
-
o = s.new(1, 'two', [true, false])
|
118
|
-
json = JSON.dump(o)
|
119
|
-
if o.respond_to?(:as_json)
|
120
|
-
if $rails_monkey
|
121
|
-
assert_equal(%|{"a":1,"b":"two","c":[true,false]}|, json)
|
122
|
-
else
|
123
|
-
assert_equal(%|{"json_class":"Struct::Abc","v":[1,"two",[true,false]]}|, json)
|
124
|
-
end
|
125
|
-
else
|
126
|
-
j = '"' + o.to_s.gsub('"', '\\"') + '"'
|
127
|
-
assert_equal(j, json)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# load
|
132
|
-
def test_load_string
|
133
|
-
json = %{{"a":1,"b":[true,false]}}
|
134
|
-
obj = JSON.load(json)
|
135
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_load_io
|
139
|
-
json = %{{"a":1,"b":[true,false]}}
|
140
|
-
obj = JSON.load(StringIO.new(json))
|
141
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_load_proc
|
145
|
-
Oj.mimic_JSON
|
146
|
-
children = []
|
147
|
-
json = %{{"a":1,"b":[true,false]}}
|
148
|
-
if 'rubinius' == $ruby || '1.8.7' == RUBY_VERSION
|
149
|
-
obj = JSON.load(json) {|x| children << x }
|
150
|
-
else
|
151
|
-
p = Proc.new {|x| children << x }
|
152
|
-
obj = JSON.load(json, p)
|
153
|
-
end
|
154
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
155
|
-
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
|
156
|
-
[true, false, [true, false], 1, { 'a' => 1, 'b' => [true, false]}] == children,
|
157
|
-
"children don't match")
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_parse_with_quirks_mode
|
161
|
-
json = %{null}
|
162
|
-
assert_equal(nil, JSON.parse(json, :quirks_mode => true))
|
163
|
-
assert_raises(JSON::ParserError) { JSON.parse(json, :quirks_mode => false) }
|
164
|
-
assert_raises(JSON::ParserError) { JSON.parse(json) }
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_parse_with_empty_string
|
168
|
-
Oj.mimic_JSON
|
169
|
-
assert_raises(JSON::ParserError) { JSON.parse(' ') }
|
170
|
-
assert_raises(JSON::ParserError) { JSON.parse("\t\t\n ") }
|
171
|
-
end
|
172
|
-
|
173
|
-
# []
|
174
|
-
def test_bracket_load
|
175
|
-
json = %{{"a":1,"b":[true,false]}}
|
176
|
-
obj = JSON[json]
|
177
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_bracket_dump
|
181
|
-
json = JSON[[1, true, nil]]
|
182
|
-
assert_equal(%{[1,true,null]}, json)
|
183
|
-
end
|
184
|
-
|
185
|
-
# generate
|
186
|
-
def test_generate
|
187
|
-
json = JSON.generate({ 'a' => 1, 'b' => [true, false]})
|
188
|
-
assert(%{{"a":1,"b":[true,false]}} == json ||
|
189
|
-
%{{"b":[true,false],"a":1}} == json)
|
190
|
-
end
|
191
|
-
def test_generate_options
|
192
|
-
json = JSON.generate({ 'a' => 1, 'b' => [true, false]},
|
193
|
-
:indent => "--",
|
194
|
-
:array_nl => "\n",
|
195
|
-
:object_nl => "#\n",
|
196
|
-
:space => "*",
|
197
|
-
:space_before => "~")
|
198
|
-
assert(%{{#
|
199
|
-
--"a"~:*1,#
|
200
|
-
--"b"~:*[
|
201
|
-
----true,
|
202
|
-
----false
|
203
|
-
--]#
|
204
|
-
}} == json ||
|
205
|
-
%{{#
|
206
|
-
--"b"~:*[
|
207
|
-
----true,
|
208
|
-
----false
|
209
|
-
--],#
|
210
|
-
--"a"~:*1#
|
211
|
-
}} == json)
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
# fast_generate
|
216
|
-
def test_fast_generate
|
217
|
-
json = JSON.generate({ 'a' => 1, 'b' => [true, false]})
|
218
|
-
assert(%{{"a":1,"b":[true,false]}} == json ||
|
219
|
-
%{{"b":[true,false],"a":1}} == json)
|
220
|
-
end
|
221
|
-
|
222
|
-
# pretty_generate
|
223
|
-
def test_pretty_generate
|
224
|
-
json = JSON.pretty_generate({ 'a' => 1, 'b' => [true, false]})
|
225
|
-
assert(%{{
|
226
|
-
"a": 1,
|
227
|
-
"b": [
|
228
|
-
true,
|
229
|
-
false
|
230
|
-
]
|
231
|
-
}} == json ||
|
232
|
-
%{{
|
233
|
-
"b": [
|
234
|
-
true,
|
235
|
-
false
|
236
|
-
],
|
237
|
-
"a": 1
|
238
|
-
}} == json)
|
239
|
-
end
|
240
|
-
|
241
|
-
# parse
|
242
|
-
def test_parse
|
243
|
-
json = %{{"a":1,"b":[true,false]}}
|
244
|
-
obj = JSON.parse(json)
|
245
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
246
|
-
end
|
247
|
-
def test_parse_sym_names
|
248
|
-
json = %{{"a":1,"b":[true,false]}}
|
249
|
-
obj = JSON.parse(json, :symbolize_names => true)
|
250
|
-
assert_equal({ :a => 1, :b => [true, false]}, obj)
|
251
|
-
end
|
252
|
-
def test_parse_additions
|
253
|
-
jam = Jam.new(true, 58)
|
254
|
-
json = Oj.dump(jam, :mode => :compat, :use_to_json => true)
|
255
|
-
obj = JSON.parse(json)
|
256
|
-
assert_equal(jam, obj)
|
257
|
-
obj = JSON.parse(json, :create_additions => true)
|
258
|
-
assert_equal(jam, obj)
|
259
|
-
obj = JSON.parse(json, :create_additions => false)
|
260
|
-
assert_equal({'json_class' => 'SharedMimicTest::Jam', 'x' => true, 'y' => 58}, obj)
|
261
|
-
json.gsub!('json_class', 'kson_class')
|
262
|
-
JSON.create_id = 'kson_class'
|
263
|
-
obj = JSON.parse(json, :create_additions => true)
|
264
|
-
JSON.create_id = 'json_class'
|
265
|
-
assert_equal(jam, obj)
|
266
|
-
end
|
267
|
-
def test_parse_bang
|
268
|
-
json = %{{"a":1,"b":[true,false]}}
|
269
|
-
obj = JSON.parse!(json)
|
270
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
271
|
-
end
|
272
|
-
|
273
|
-
# recurse_proc
|
274
|
-
def test_recurse_proc
|
275
|
-
children = []
|
276
|
-
JSON.recurse_proc({ 'a' => 1, 'b' => [true, false]}) { |x| children << x }
|
277
|
-
# JRuby 1.7.0 rb_yield() is broken and converts the [true, false] array into true
|
278
|
-
unless 'jruby' == $ruby && '1.9.3' == RUBY_VERSION
|
279
|
-
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
|
280
|
-
[true, false, [true, false], 1, { 'b' => [true, false], 'a' => 1}] == children)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
# make sure to_json is defined for object.
|
285
|
-
def test_mimic_to_json
|
286
|
-
{'a' => 1}.to_json()
|
287
|
-
Object.new().to_json()
|
288
|
-
end
|
289
|
-
end # SharedMimicTest
|
290
|
-
|
291
|
-
if defined?(ActiveSupport)
|
292
|
-
class SharedMimicRailsTest < SharedMimicTest
|
293
|
-
def test_activesupport_exception
|
294
|
-
begin
|
295
|
-
ActiveSupport::JSON.decode("{")
|
296
|
-
puts "Failed"
|
297
|
-
rescue ActiveSupport::JSON.parse_error
|
298
|
-
assert(true)
|
299
|
-
rescue Exception
|
300
|
-
assert(false, 'Expected a JSON::ParserError')
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_activesupport_encode
|
305
|
-
Oj.default_options= {:indent => 0}
|
306
|
-
json = ActiveSupport::JSON.encode([1, true, nil])
|
307
|
-
assert_equal(%{[1,true,null]}, json)
|
308
|
-
end
|
309
|
-
end # SharedMimicRailsTest
|
310
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
require 'oj'
|
8
|
-
|
9
|
-
class ObjectFolder < Minitest::Test
|
10
|
-
class Raccoon
|
11
|
-
attr_accessor :name
|
12
|
-
|
13
|
-
def initialize(name)
|
14
|
-
@name = name
|
15
|
-
end
|
16
|
-
|
17
|
-
def as_json(options={})
|
18
|
-
{:name => @name}.merge(options)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
@default_options = Oj.default_options
|
24
|
-
end
|
25
|
-
|
26
|
-
def teardown
|
27
|
-
Oj.default_options = @default_options
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_as_json_options
|
31
|
-
Oj.mimic_JSON()
|
32
|
-
raccoon = Raccoon.new('Rocket')
|
33
|
-
json = raccoon.to_json()
|
34
|
-
assert_equal(json, '{"name":"Rocket"}')
|
35
|
-
|
36
|
-
json = raccoon.to_json(:occupation => 'bounty hunter')
|
37
|
-
# depending on the ruby version the order of the hash members maybe different.
|
38
|
-
if (json.start_with?('{"name'))
|
39
|
-
assert_equal(json, '{"name":"Rocket","occupation":"bounty hunter"}')
|
40
|
-
else
|
41
|
-
assert_equal(json, '{"occupation":"bounty hunter","name":"Rocket"}')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class MimicDefine < Minitest::Test
|
9
|
-
def test_mimic_define
|
10
|
-
assert(defined?(JSON).nil?)
|
11
|
-
Oj.mimic_JSON
|
12
|
-
|
13
|
-
# Test constants
|
14
|
-
assert(!defined?(JSON).nil?)
|
15
|
-
assert(!defined?(JSON::ParserError).nil?)
|
16
|
-
assert(Object.respond_to?(:to_json))
|
17
|
-
|
18
|
-
# Test loaded features
|
19
|
-
assert(!require('json'))
|
20
|
-
|
21
|
-
begin
|
22
|
-
require('json_spec')
|
23
|
-
assert(false, '** should raise LoadError')
|
24
|
-
rescue LoadError
|
25
|
-
assert(true)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end # MimicSingle
|
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'rails/all'
|
10
|
-
rescue LoadError => e
|
11
|
-
puts "Rails are not in the gemfile, skipping tests"
|
12
|
-
Process.exit
|
13
|
-
end
|
14
|
-
|
15
|
-
Oj.mimic_JSON
|
16
|
-
|
17
|
-
require 'isolated/shared'
|
18
|
-
|
19
|
-
$rails_monkey = true
|
20
|
-
|
21
|
-
class MimicRailsAfter < SharedMimicRailsTest
|
22
|
-
end # MimicRailsAfter
|
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
Oj.mimic_JSON
|
9
|
-
begin
|
10
|
-
require 'rails/all'
|
11
|
-
rescue LoadError => e
|
12
|
-
puts "Rails are not in the gemfile, skipping tests"
|
13
|
-
Process.exit
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'isolated/shared'
|
17
|
-
|
18
|
-
$rails_monkey = true
|
19
|
-
|
20
|
-
class MimicRailsBefore < SharedMimicRailsTest
|
21
|
-
end # MimicRailsBefore
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
require 'oj/active_support_helper'
|
8
|
-
|
9
|
-
class ObjectFolder < Minitest::Test
|
10
|
-
def setup
|
11
|
-
@default_options = Oj.default_options
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
Oj.default_options = @default_options
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_as_json
|
19
|
-
Oj.mimic_JSON()
|
20
|
-
dt = DateTime.now()
|
21
|
-
|
22
|
-
json = dt.to_json()
|
23
|
-
|
24
|
-
puts json
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class MimicRedefine < Minitest::Test
|
9
|
-
def test_mimic_redefine
|
10
|
-
require 'json'
|
11
|
-
parser_error = JSON::ParserError
|
12
|
-
Oj.mimic_JSON
|
13
|
-
assert_equal(parser_error, JSON::ParserError)
|
14
|
-
end
|
15
|
-
end # MimicSingle
|
data/test/mod.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
%w(lib ext test).each do |dir|
|
5
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'oj'
|
9
|
-
|
10
|
-
|
11
|
-
Thread.new do
|
12
|
-
string_io = StringIO.new('{"foo":"bar"}')
|
13
|
-
Oj.load(string_io)
|
14
|
-
string_io.rewind
|
15
|
-
puts string_io.read
|
16
|
-
end.join
|
data/test/perf.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
|
2
|
-
class Perf
|
3
|
-
|
4
|
-
def initialize()
|
5
|
-
@items = []
|
6
|
-
end
|
7
|
-
|
8
|
-
def add(title, op, &blk)
|
9
|
-
@items << Item.new(title, op, &blk)
|
10
|
-
end
|
11
|
-
|
12
|
-
def before(title, &blk)
|
13
|
-
@items.each do |i|
|
14
|
-
if title == i.title
|
15
|
-
i.set_before(&blk)
|
16
|
-
break
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def run(iter)
|
22
|
-
base = Item.new(nil, nil) { }
|
23
|
-
base.run(iter, 0.0)
|
24
|
-
@items.each do |i|
|
25
|
-
i.run(iter, base.duration)
|
26
|
-
if i.error.nil?
|
27
|
-
puts "#{i.title}.#{i.op} #{iter} times in %0.3f seconds or %0.3f #{i.op}/sec." % [i.duration, iter / i.duration]
|
28
|
-
else
|
29
|
-
puts "***** #{i.title}.#{i.op} failed! #{i.error}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
summary()
|
33
|
-
end
|
34
|
-
|
35
|
-
def summary()
|
36
|
-
fastest = nil
|
37
|
-
slowest = nil
|
38
|
-
width = 6
|
39
|
-
@items.each do |i|
|
40
|
-
next if i.duration.nil?
|
41
|
-
width = i.title.size if width < i.title.size
|
42
|
-
end
|
43
|
-
iva = @items.clone
|
44
|
-
iva.delete_if { |i| i.duration.nil? }
|
45
|
-
iva = iva.sort_by { |i| i.duration }
|
46
|
-
puts
|
47
|
-
puts "Summary:"
|
48
|
-
puts "%*s time (secs) rate (ops/sec)" % [width, 'System']
|
49
|
-
puts "#{'-' * width} ----------- --------------"
|
50
|
-
iva.each do |i|
|
51
|
-
if i.duration.nil?
|
52
|
-
else
|
53
|
-
puts "%*s %11.3f %14.3f" % [width, i.title, i.duration, i.rate ]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
puts
|
57
|
-
puts "Comparison Matrix\n(performance factor, 2.0 means row is twice as fast as column)"
|
58
|
-
puts ([' ' * width] + iva.map { |i| "%*s" % [width, i.title] }).join(' ')
|
59
|
-
puts (['-' * width] + iva.map { |i| '-' * width }).join(' ')
|
60
|
-
iva.each do |i|
|
61
|
-
line = ["%*s" % [width, i.title]]
|
62
|
-
iva.each do |o|
|
63
|
-
line << "%*.2f" % [width, o.duration / i.duration]
|
64
|
-
end
|
65
|
-
puts line.join(' ')
|
66
|
-
end
|
67
|
-
puts
|
68
|
-
end
|
69
|
-
|
70
|
-
class Item
|
71
|
-
attr_accessor :title
|
72
|
-
attr_accessor :op
|
73
|
-
attr_accessor :blk
|
74
|
-
attr_accessor :duration
|
75
|
-
attr_accessor :rate
|
76
|
-
attr_accessor :error
|
77
|
-
|
78
|
-
def initialize(title, op, &blk)
|
79
|
-
@title = title
|
80
|
-
@blk = blk
|
81
|
-
@op = op
|
82
|
-
@duration = nil
|
83
|
-
@rate = nil
|
84
|
-
@error = nil
|
85
|
-
@before = nil
|
86
|
-
end
|
87
|
-
|
88
|
-
def set_before(&blk)
|
89
|
-
@before = blk
|
90
|
-
end
|
91
|
-
|
92
|
-
def run(iter, base)
|
93
|
-
begin
|
94
|
-
GC.start
|
95
|
-
@before.call unless @before.nil?
|
96
|
-
start = Time.now
|
97
|
-
iter.times { @blk.call }
|
98
|
-
@duration = Time.now - start - base
|
99
|
-
@duration = 0.0 if @duration < 0.0
|
100
|
-
@rate = iter / @duration
|
101
|
-
rescue Exception => e
|
102
|
-
@error = "#{e.class}: #{e.message}"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end # Item
|
107
|
-
end # Perf
|