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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/oj/fast.c +3 -6
- data/ext/oj/mimic_json.c +3 -6
- data/ext/oj/oj.c +2 -4
- data/ext/oj/parse.c +15 -5
- data/ext/oj/parser.c +1 -1
- data/ext/oj/parser.h +2 -0
- data/ext/oj/rails.c +1 -2
- data/ext/oj/saj.c +3 -6
- data/ext/oj/scp.c +3 -6
- data/ext/oj/stream_writer.c +1 -7
- data/ext/oj/strict.c +2 -4
- data/ext/oj/string_writer.c +1 -3
- data/lib/oj/version.rb +1 -1
- metadata +3 -98
- data/test/_test_active.rb +0 -75
- data/test/_test_active_mimic.rb +0 -95
- data/test/_test_mimic_rails.rb +0 -123
- data/test/activerecord/result_test.rb +0 -31
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -542
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -52
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -536
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -26
- data/test/helper.rb +0 -39
- data/test/isolated/shared.rb +0 -309
- 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_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -155
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -21
- data/test/json_gem/json_fixtures_test.rb +0 -36
- data/test/json_gem/json_generator_test.rb +0 -413
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -34
- data/test/perf.rb +0 -102
- data/test/perf_compat.rb +0 -128
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -162
- data/test/perf_file.rb +0 -62
- data/test/perf_object.rb +0 -134
- data/test/perf_once.rb +0 -59
- data/test/perf_parser.rb +0 -183
- data/test/perf_saj.rb +0 -101
- data/test/perf_scp.rb +0 -140
- data/test/perf_simple.rb +0 -289
- data/test/perf_strict.rb +0 -137
- data/test/perf_wab.rb +0 -129
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -13
- data/test/sample/dir.rb +0 -18
- data/test/sample/doc.rb +0 -35
- data/test/sample/file.rb +0 -47
- data/test/sample/group.rb +0 -15
- data/test/sample/hasprops.rb +0 -15
- data/test/sample/layer.rb +0 -11
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -9
- data/test/sample/shape.rb +0 -34
- data/test/sample/text.rb +0 -19
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -567
- data/test/test_custom.rb +0 -555
- data/test/test_debian.rb +0 -50
- data/test/test_fast.rb +0 -526
- data/test/test_file.rb +0 -250
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1030
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -337
- data/test/test_parser_usual.rb +0 -255
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -188
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -441
- data/test/test_various.rb +0 -801
- data/test/test_wab.rb +0 -311
- data/test/test_writer.rb +0 -396
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
data/test/files.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -wW2
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
if $PROGRAM_NAME == __FILE__
|
5
|
-
$LOAD_PATH << '.'
|
6
|
-
$LOAD_PATH << '..'
|
7
|
-
$LOAD_PATH << '../lib'
|
8
|
-
$LOAD_PATH << '../ext'
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'sample/file'
|
12
|
-
require 'sample/dir'
|
13
|
-
|
14
|
-
def files(dir)
|
15
|
-
d = Sample::Dir.new(dir)
|
16
|
-
Dir.new(dir).each do |fn|
|
17
|
-
next if fn.start_with?('.')
|
18
|
-
|
19
|
-
filename = File.join(dir, fn)
|
20
|
-
# filename = '.' == dir ? fn : File.join(dir, fn)
|
21
|
-
d << if File.directory?(filename)
|
22
|
-
files(filename)
|
23
|
-
else
|
24
|
-
Sample::File.new(filename)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
# pp d
|
28
|
-
d
|
29
|
-
end
|
data/test/foo.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
$LOAD_PATH << '.'
|
5
|
-
$LOAD_PATH << File.join(__dir__, '../lib')
|
6
|
-
$LOAD_PATH << File.join(__dir__, '../ext')
|
7
|
-
|
8
|
-
require 'oj'
|
9
|
-
|
10
|
-
reader, writer = IO.pipe
|
11
|
-
|
12
|
-
thread =
|
13
|
-
Thread.new do
|
14
|
-
5.times do |id|
|
15
|
-
Oj.to_stream(writer, { "id" => id })
|
16
|
-
sleep(1)
|
17
|
-
end
|
18
|
-
|
19
|
-
writer.close
|
20
|
-
end
|
21
|
-
|
22
|
-
p = Oj::Parser.new(:usual)
|
23
|
-
p.load(reader) { |data| puts "#{Time.now} -- ID: #{data["id"]}" }
|
24
|
-
|
25
|
-
reader.close
|
26
|
-
thread.join
|
data/test/helper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
|
4
|
-
# required. That can be set in the RUBYOPT environment variable.
|
5
|
-
# export RUBYOPT=-w
|
6
|
-
|
7
|
-
$VERBOSE = true
|
8
|
-
|
9
|
-
%w(lib ext test).each do |dir|
|
10
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'minitest'
|
14
|
-
require 'minitest/autorun'
|
15
|
-
require 'stringio'
|
16
|
-
require 'date'
|
17
|
-
require 'bigdecimal'
|
18
|
-
require 'oj'
|
19
|
-
|
20
|
-
def verify_gc_compaction
|
21
|
-
# This method was added in Ruby 3.0.0. Calling it this way asks the GC to
|
22
|
-
# move objects around, helping to find object movement bugs.
|
23
|
-
if defined?(GC.verify_compaction_references) == 'method' && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
24
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2.0')
|
25
|
-
GC.verify_compaction_references(expand_heap: true, toward: :empty)
|
26
|
-
else
|
27
|
-
GC.verify_compaction_references(double_heap: true, toward: :empty)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
$ruby = RUBY_DESCRIPTION.split(' ')[0]
|
33
|
-
$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
|
34
|
-
|
35
|
-
class Range
|
36
|
-
def to_hash
|
37
|
-
{ 'begin' => self.begin, 'end' => self.end, 'exclude_end' => exclude_end? }
|
38
|
-
end
|
39
|
-
end
|
data/test/isolated/shared.rb
DELETED
@@ -1,309 +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
|
-
else
|
40
|
-
%{"2014-05-13 16:53:20 UTC"}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def teardown
|
45
|
-
Oj.default_options = @default_options
|
46
|
-
end
|
47
|
-
|
48
|
-
# exception
|
49
|
-
def test_exception
|
50
|
-
begin
|
51
|
-
JSON.parse("{")
|
52
|
-
puts "Failed"
|
53
|
-
rescue JSON::ParserError
|
54
|
-
assert(true)
|
55
|
-
rescue Exception
|
56
|
-
assert(false, 'Expected a JSON::ParserError')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# dump
|
61
|
-
def test_dump_string
|
62
|
-
json = JSON.dump([1, true, nil, @time])
|
63
|
-
if $rails_monkey
|
64
|
-
assert_equal(%{[1,true,null,#{@expected_time_string}]}, json)
|
65
|
-
else
|
66
|
-
assert_equal(%{[1,true,null,{"json_class":"Time","s":1400000000,"n":0}]}, json)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_dump_with_options
|
71
|
-
Oj.default_options= {:indent => 2} # JSON this will not change anything
|
72
|
-
json = JSON.dump([1, true, nil, @time])
|
73
|
-
if $rails_monkey
|
74
|
-
assert_equal(%{[
|
75
|
-
1,
|
76
|
-
true,
|
77
|
-
null,
|
78
|
-
#{@expected_time_string}
|
79
|
-
]
|
80
|
-
}, json)
|
81
|
-
else
|
82
|
-
assert_equal(%{[
|
83
|
-
1,
|
84
|
-
true,
|
85
|
-
null,
|
86
|
-
{
|
87
|
-
"json_class":"Time",
|
88
|
-
"s":1400000000,
|
89
|
-
"n\":0
|
90
|
-
}
|
91
|
-
]
|
92
|
-
}, json)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_dump_io
|
97
|
-
s = StringIO.new()
|
98
|
-
json = JSON.dump([1, true, nil, @time], s)
|
99
|
-
assert_equal(s, json)
|
100
|
-
if $rails_monkey
|
101
|
-
assert_equal(%{[1,true,null,#{@expected_time_string}]}, s.string)
|
102
|
-
else
|
103
|
-
assert_equal(%{[1,true,null,{"json_class":"Time","s":1400000000,"n":0}]}, s.string)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
# TBD options
|
107
|
-
|
108
|
-
def test_dump_struct
|
109
|
-
# anonymous Struct not supported by json so name it
|
110
|
-
if Object.const_defined?("Struct::Abc")
|
111
|
-
s = Struct::Abc
|
112
|
-
else
|
113
|
-
s = Struct.new("Abc", :a, :b, :c)
|
114
|
-
end
|
115
|
-
o = s.new(1, 'two', [true, false])
|
116
|
-
json = JSON.dump(o)
|
117
|
-
if o.respond_to?(:as_json)
|
118
|
-
if $rails_monkey
|
119
|
-
assert_equal(%|{"a":1,"b":"two","c":[true,false]}|, json)
|
120
|
-
else
|
121
|
-
assert_equal(%|{"json_class":"Struct::Abc","v":[1,"two",[true,false]]}|, json)
|
122
|
-
end
|
123
|
-
else
|
124
|
-
j = '"' + o.to_s.gsub('"', '\\"') + '"'
|
125
|
-
assert_equal(j, json)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# load
|
130
|
-
def test_load_string
|
131
|
-
json = %{{"a":1,"b":[true,false]}}
|
132
|
-
obj = JSON.load(json)
|
133
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_load_io
|
137
|
-
json = %{{"a":1,"b":[true,false]}}
|
138
|
-
obj = JSON.load(StringIO.new(json))
|
139
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_load_proc
|
143
|
-
Oj.mimic_JSON
|
144
|
-
children = []
|
145
|
-
json = %{{"a":1,"b":[true,false]}}
|
146
|
-
if 'rubinius' == $ruby
|
147
|
-
obj = JSON.load(json) {|x| children << x }
|
148
|
-
else
|
149
|
-
p = Proc.new {|x| children << x }
|
150
|
-
obj = JSON.load(json, p)
|
151
|
-
end
|
152
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
153
|
-
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
|
154
|
-
[true, false, [true, false], 1, { 'a' => 1, 'b' => [true, false]}] == children,
|
155
|
-
"children don't match")
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_parse_with_quirks_mode
|
159
|
-
json = %{null}
|
160
|
-
assert_equal(nil, JSON.parse(json, :quirks_mode => true))
|
161
|
-
assert_raises(JSON::ParserError) { JSON.parse(json, :quirks_mode => false) }
|
162
|
-
assert_raises(JSON::ParserError) { JSON.parse(json) }
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_parse_with_empty_string
|
166
|
-
Oj.mimic_JSON
|
167
|
-
assert_raises(JSON::ParserError) { JSON.parse(' ') }
|
168
|
-
assert_raises(JSON::ParserError) { JSON.parse("\t\t\n ") }
|
169
|
-
end
|
170
|
-
|
171
|
-
# []
|
172
|
-
def test_bracket_load
|
173
|
-
json = %{{"a":1,"b":[true,false]}}
|
174
|
-
obj = JSON[json]
|
175
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_bracket_dump
|
179
|
-
json = JSON[[1, true, nil]]
|
180
|
-
assert_equal(%{[1,true,null]}, json)
|
181
|
-
end
|
182
|
-
|
183
|
-
# generate
|
184
|
-
def test_generate
|
185
|
-
json = JSON.generate({ 'a' => 1, 'b' => [true, false]})
|
186
|
-
assert(%{{"a":1,"b":[true,false]}} == json ||
|
187
|
-
%{{"b":[true,false],"a":1}} == json)
|
188
|
-
end
|
189
|
-
def test_generate_options
|
190
|
-
json = JSON.generate({ 'a' => 1, 'b' => [true, false]},
|
191
|
-
:indent => "--",
|
192
|
-
:array_nl => "\n",
|
193
|
-
:object_nl => "#\n",
|
194
|
-
:space => "*",
|
195
|
-
:space_before => "~")
|
196
|
-
assert(%{{#
|
197
|
-
--"a"~:*1,#
|
198
|
-
--"b"~:*[
|
199
|
-
----true,
|
200
|
-
----false
|
201
|
-
--]#
|
202
|
-
}} == json ||
|
203
|
-
%{{#
|
204
|
-
--"b"~:*[
|
205
|
-
----true,
|
206
|
-
----false
|
207
|
-
--],#
|
208
|
-
--"a"~:*1#
|
209
|
-
}} == json)
|
210
|
-
end
|
211
|
-
|
212
|
-
# fast_generate
|
213
|
-
def test_fast_generate
|
214
|
-
json = JSON.generate({ 'a' => 1, 'b' => [true, false]})
|
215
|
-
assert(%{{"a":1,"b":[true,false]}} == json ||
|
216
|
-
%{{"b":[true,false],"a":1}} == json)
|
217
|
-
end
|
218
|
-
|
219
|
-
# pretty_generate
|
220
|
-
def test_pretty_generate
|
221
|
-
json = JSON.pretty_generate({ 'a' => 1, 'b' => [true, false]})
|
222
|
-
assert(%{{
|
223
|
-
"a": 1,
|
224
|
-
"b": [
|
225
|
-
true,
|
226
|
-
false
|
227
|
-
]
|
228
|
-
}} == json ||
|
229
|
-
%{{
|
230
|
-
"b": [
|
231
|
-
true,
|
232
|
-
false
|
233
|
-
],
|
234
|
-
"a": 1
|
235
|
-
}} == json)
|
236
|
-
end
|
237
|
-
|
238
|
-
# parse
|
239
|
-
def test_parse
|
240
|
-
json = %{{"a":1,"b":[true,false]}}
|
241
|
-
obj = JSON.parse(json)
|
242
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
243
|
-
end
|
244
|
-
def test_parse_sym_names
|
245
|
-
json = %{{"a":1,"b":[true,false]}}
|
246
|
-
obj = JSON.parse(json, :symbolize_names => true)
|
247
|
-
assert_equal({ :a => 1, :b => [true, false]}, obj)
|
248
|
-
end
|
249
|
-
def test_parse_additions
|
250
|
-
jam = Jam.new(true, 58)
|
251
|
-
json = Oj.dump(jam, :mode => :compat, :use_to_json => true)
|
252
|
-
obj = JSON.parse(json)
|
253
|
-
assert_equal(jam, obj)
|
254
|
-
obj = JSON.parse(json, :create_additions => true)
|
255
|
-
assert_equal(jam, obj)
|
256
|
-
obj = JSON.parse(json, :create_additions => false)
|
257
|
-
assert_equal({'json_class' => 'SharedMimicTest::Jam', 'x' => true, 'y' => 58}, obj)
|
258
|
-
json.gsub!('json_class', 'kson_class')
|
259
|
-
JSON.create_id = 'kson_class'
|
260
|
-
obj = JSON.parse(json, :create_additions => true)
|
261
|
-
JSON.create_id = 'json_class'
|
262
|
-
assert_equal(jam, obj)
|
263
|
-
|
264
|
-
assert_nothing_raised { JSON.create_id = nil }
|
265
|
-
end
|
266
|
-
def test_parse_bang
|
267
|
-
json = %{{"a":1,"b":[true,false]}}
|
268
|
-
obj = JSON.parse!(json)
|
269
|
-
assert_equal({ 'a' => 1, 'b' => [true, false]}, obj)
|
270
|
-
end
|
271
|
-
|
272
|
-
# recurse_proc
|
273
|
-
def test_recurse_proc
|
274
|
-
children = []
|
275
|
-
JSON.recurse_proc({ 'a' => 1, 'b' => [true, false]}) { |x| children << x }
|
276
|
-
# JRuby 1.7.0 rb_yield() is broken and converts the [true, false] array into true
|
277
|
-
unless 'jruby' == $ruby
|
278
|
-
assert([1, true, false, [true, false], { 'a' => 1, 'b' => [true, false]}] == children ||
|
279
|
-
[true, false, [true, false], 1, { 'b' => [true, false], 'a' => 1}] == children)
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
# make sure to_json is defined for object.
|
284
|
-
def test_mimic_to_json
|
285
|
-
{'a' => 1}.to_json()
|
286
|
-
Object.new().to_json()
|
287
|
-
end
|
288
|
-
end # SharedMimicTest
|
289
|
-
|
290
|
-
if defined?(ActiveSupport)
|
291
|
-
class SharedMimicRailsTest < SharedMimicTest
|
292
|
-
def test_activesupport_exception
|
293
|
-
begin
|
294
|
-
ActiveSupport::JSON.decode("{")
|
295
|
-
puts "Failed"
|
296
|
-
rescue ActiveSupport::JSON.parse_error
|
297
|
-
assert(true)
|
298
|
-
rescue Exception
|
299
|
-
assert(false, 'Expected a JSON::ParserError')
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_activesupport_encode
|
304
|
-
Oj.default_options= {:indent => 0}
|
305
|
-
json = ActiveSupport::JSON.encode([1, true, nil])
|
306
|
-
assert_equal(%{[1,true,null]}, json)
|
307
|
-
end
|
308
|
-
end # SharedMimicRailsTest
|
309
|
-
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,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
|