oj 2.18.3 → 3.13.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1324 -0
- data/README.md +51 -204
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +49 -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 -68
- data/ext/oj/circarray.h +16 -42
- data/ext/oj/code.c +221 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +231 -107
- data/ext/oj/custom.c +1125 -0
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +935 -2513
- data/ext/oj/dump.h +108 -0
- data/ext/oj/dump_compat.c +936 -0
- data/ext/oj/dump_leaf.c +164 -0
- data/ext/oj/dump_object.c +761 -0
- data/ext/oj/dump_strict.c +410 -0
- data/ext/oj/encode.h +7 -42
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -54
- data/ext/oj/err.h +52 -46
- data/ext/oj/extconf.rb +21 -30
- data/ext/oj/fast.c +1097 -1080
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +893 -0
- data/ext/oj/object.c +549 -620
- data/ext/oj/odd.c +155 -167
- data/ext/oj/odd.h +37 -63
- data/ext/oj/oj.c +1661 -2063
- data/ext/oj/oj.h +341 -270
- data/ext/oj/parse.c +974 -737
- data/ext/oj/parse.h +105 -97
- data/ext/oj/parser.c +1526 -0
- data/ext/oj/parser.h +90 -0
- data/ext/oj/rails.c +1504 -0
- data/ext/oj/rails.h +18 -0
- data/ext/oj/reader.c +141 -163
- data/ext/oj/reader.h +75 -113
- data/ext/oj/resolve.c +45 -93
- data/ext/oj/resolve.h +7 -34
- data/ext/oj/rxclass.c +143 -0
- data/ext/oj/rxclass.h +26 -0
- data/ext/oj/saj.c +447 -511
- data/ext/oj/saj2.c +348 -0
- data/ext/oj/scp.c +91 -138
- data/ext/oj/sparse.c +793 -644
- data/ext/oj/stream_writer.c +331 -0
- data/ext/oj/strict.c +145 -109
- data/ext/oj/string_writer.c +493 -0
- data/ext/oj/trace.c +72 -0
- data/ext/oj/trace.h +28 -0
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +62 -70
- data/ext/oj/val_stack.h +95 -129
- data/ext/oj/validate.c +51 -0
- data/ext/oj/wab.c +622 -0
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +17 -8
- data/lib/oj/error.rb +10 -11
- data/lib/oj/json.rb +176 -0
- data/lib/oj/mimic.rb +158 -19
- data/lib/oj/state.rb +132 -0
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +1 -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/JsonGem.md +94 -0
- data/pages/Modes.md +161 -0
- data/pages/Options.md +327 -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
- data/test/activerecord/result_test.rb +32 -0
- data/test/activesupport4/decoding_test.rb +108 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +133 -0
- data/test/activesupport5/encoding_test.rb +500 -0
- data/test/activesupport5/encoding_test_cases.rb +98 -0
- data/test/activesupport5/test_helper.rb +72 -0
- data/test/activesupport5/time_zone_test_helpers.rb +39 -0
- 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 +9 -0
- data/test/baz.rb +16 -0
- data/test/bug.rb +11 -46
- data/test/foo.rb +69 -16
- data/test/helper.rb +10 -1
- data/test/isolated/shared.rb +12 -8
- data/test/isolated/test_mimic_rails_after.rb +3 -3
- data/test/isolated/test_mimic_rails_before.rb +3 -3
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +153 -0
- data/test/json_gem/json_encoding_test.rb +107 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +397 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +26 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_compat.rb +30 -28
- data/test/perf_dump.rb +50 -0
- data/test/perf_object.rb +1 -1
- 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 +30 -19
- data/test/perf_wab.rb +131 -0
- data/test/prec.rb +23 -0
- data/test/sample.rb +0 -1
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +219 -102
- data/test/test_custom.rb +533 -0
- data/test/test_fast.rb +107 -35
- data/test/test_file.rb +19 -25
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +72 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +357 -70
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +245 -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 +39 -2
- data/test/test_strict.rb +186 -7
- data/test/test_various.rb +160 -774
- data/test/test_wab.rb +307 -0
- data/test/test_writer.rb +90 -2
- data/test/tests.rb +24 -0
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- data/test/zoo.rb +13 -0
- metadata +194 -56
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
- data/test/activesupport_datetime_test.rb +0 -23
- 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/io.rb +0 -48
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/mod.rb +0 -16
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/struct.rb +0 -29
- data/test/test_serializer.rb +0 -59
- data/test/write_timebars.rb +0 -31
data/test/crash.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$VERBOSE = true
|
5
|
-
|
6
|
-
%w(lib ext test).each do |dir|
|
7
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'sqlite3'
|
11
|
-
require 'active_record'
|
12
|
-
require 'oj'
|
13
|
-
require 'representable'
|
14
|
-
require 'representable/json'
|
15
|
-
require 'multi_json'
|
16
|
-
MultiJson.use(:oj)
|
17
|
-
Oj.default_options = {mode: :object, indent: 2}
|
18
|
-
|
19
|
-
#ActiveRecord::Base.logger = Logger.new(STDERR)
|
20
|
-
|
21
|
-
ActiveRecord::Base.establish_connection(
|
22
|
-
:adapter => "sqlite3",
|
23
|
-
:database => ":memory:"
|
24
|
-
)
|
25
|
-
|
26
|
-
ActiveRecord::Schema.define do
|
27
|
-
create_table :users do |t|
|
28
|
-
t.string "first_name"
|
29
|
-
t.string "last_name"
|
30
|
-
t.string "picture"
|
31
|
-
t.integer "state", null: false
|
32
|
-
t.integer "visible", default: 1, null: false
|
33
|
-
t.integer "role", null: false
|
34
|
-
t.string "position"
|
35
|
-
t.integer "responded", default: 0
|
36
|
-
t.string "slug"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class User < ActiveRecord::Base
|
41
|
-
end
|
42
|
-
User.find_or_create_by(first_name: "John", last_name: "Smith",role:1,id:1,state: 0)
|
43
|
-
User.find_or_create_by(first_name: "John", last_name: "Smith",role:1,id:2,state: 0)
|
44
|
-
|
45
|
-
|
46
|
-
class PersonDecorator < Representable::Decorator
|
47
|
-
include Representable::JSON
|
48
|
-
include Representable::Hash
|
49
|
-
|
50
|
-
property :id
|
51
|
-
|
52
|
-
property :first_name
|
53
|
-
|
54
|
-
property :last_name,
|
55
|
-
default: nil
|
56
|
-
|
57
|
-
property :name,
|
58
|
-
getter: ->(_){ "#{first_name} #{last_name}".strip },
|
59
|
-
writeable: false
|
60
|
-
|
61
|
-
property :visible,
|
62
|
-
render_filter: lambda{ |value, _| !value.zero? },
|
63
|
-
parse_filter: lambda{ |value, _| value ? 1 : 0 },
|
64
|
-
default: 1
|
65
|
-
|
66
|
-
property :role,
|
67
|
-
render_filter: lambda{ |value, _| { 1 => 'staff', 2 => 'manager' }[value].to_s },
|
68
|
-
writeable: false
|
69
|
-
|
70
|
-
property :position
|
71
|
-
|
72
|
-
nested :image, skip_render: lambda{ |options| options[:represented].picture.nil? } do
|
73
|
-
property :picture, as: :url, writeable: false
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
class PersonViewModel
|
79
|
-
|
80
|
-
def initialize(person, organization)
|
81
|
-
@users = User.all
|
82
|
-
@person = person
|
83
|
-
@organization = organization
|
84
|
-
end
|
85
|
-
|
86
|
-
def to_json(options={})
|
87
|
-
PersonDecorator.represent(@users.to_a)
|
88
|
-
end
|
89
|
-
|
90
|
-
def json_with_decorator(options={})
|
91
|
-
PersonDecorator.new(person).to_json
|
92
|
-
end
|
93
|
-
|
94
|
-
def person
|
95
|
-
@person
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class EmployeeViewModel < PersonViewModel
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
employee = User.find(1)
|
104
|
-
emp_json = EmployeeViewModel.new(employee,nil)
|
105
|
-
puts emp_json.to_json.to_json
|
106
|
-
puts emp_json.json_with_decorator
|
107
|
-
Oj.mimic_JSON
|
108
|
-
# when i use Oj.mimic_JSON script crash
|
109
|
-
# when i dont use Oj.mimic_JSON then dont use correct decorator
|
110
|
-
puts Oj.dump(emp_json)
|
111
|
-
puts Oj.dump(emp_json.to_json)
|
data/test/curl/curl_oj.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#$VERBOSE = true
|
5
|
-
|
6
|
-
$: << File.dirname(__FILE__)
|
7
|
-
$: << File.expand_path("../../ext")
|
8
|
-
$: << File.expand_path("../../lib")
|
9
|
-
$: << File.expand_path("../../../curb/ext")
|
10
|
-
$: << File.expand_path("../../../curb/lib")
|
11
|
-
|
12
|
-
require 'curb'
|
13
|
-
require 'oj'
|
14
|
-
|
15
|
-
$cnt = 0
|
16
|
-
|
17
|
-
$url = "localhost:7660/data.json"
|
18
|
-
|
19
|
-
begin
|
20
|
-
while true
|
21
|
-
before = GC.count
|
22
|
-
curl = Curl::Easy.new($url)
|
23
|
-
curl.ssl_verify_host = false
|
24
|
-
curl.http_get
|
25
|
-
if before != GC.count
|
26
|
-
puts " did a GC in curl #{GC.count}"
|
27
|
-
before = GC.count
|
28
|
-
end
|
29
|
-
=begin
|
30
|
-
data = Oj.load(curl.body, symbol_keys: true, mode: :strict)
|
31
|
-
puts " did a GC in Oj #{GC.count}" if before != GC.count
|
32
|
-
|
33
|
-
if data[:data].nil? or data[:data].any? { |e| e.empty? }
|
34
|
-
puts "body: #{curl.body}"
|
35
|
-
raise "FAILED"
|
36
|
-
end
|
37
|
-
=end
|
38
|
-
$cnt += 1
|
39
|
-
print "\r #{$cnt}"
|
40
|
-
end
|
41
|
-
rescue Exception => e
|
42
|
-
puts "#{e.class}: #{e.message}"
|
43
|
-
puts "url: #{$url}"
|
44
|
-
#puts "data: #{data}"
|
45
|
-
#puts "data[data]: #{data[:data]}"
|
46
|
-
end
|
data/test/curl/get_oj.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$VERBOSE = true
|
5
|
-
|
6
|
-
$: << File.dirname(__FILE__)
|
7
|
-
$: << File.expand_path("../../ext")
|
8
|
-
$: << File.expand_path("../../lib")
|
9
|
-
|
10
|
-
require 'net/http'
|
11
|
-
require 'uri'
|
12
|
-
require 'oj'
|
13
|
-
|
14
|
-
$url = URI.parse("http://localhost:7660/data.json")
|
15
|
-
|
16
|
-
$cnt = 0
|
17
|
-
|
18
|
-
while true
|
19
|
-
response = Net::HTTP.get_response($url)
|
20
|
-
data = Oj.load(response.body, symbol_keys: true, mode: :strict)
|
21
|
-
raise "FAILED" if data[:data].any? { |e| e.empty? }
|
22
|
-
$cnt += 1
|
23
|
-
print "\r #{$cnt}"
|
24
|
-
end
|
data/test/curl/just_curl.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#$VERBOSE = true
|
5
|
-
|
6
|
-
$: << File.dirname(__FILE__)
|
7
|
-
#$: << File.expand_path("../../../curb/ext")
|
8
|
-
#$: << File.expand_path("../../../curb/lib")
|
9
|
-
|
10
|
-
require 'curb'
|
11
|
-
|
12
|
-
$cnt = 0
|
13
|
-
$url = "localhost:7660/data.json"
|
14
|
-
|
15
|
-
begin
|
16
|
-
while true
|
17
|
-
before = GC.count
|
18
|
-
curl = Curl::Easy.new($url)
|
19
|
-
curl.ssl_verify_host = false
|
20
|
-
curl.http_get
|
21
|
-
if before != GC.count
|
22
|
-
puts " did a GC in curl #{GC.count}"
|
23
|
-
before = GC.count
|
24
|
-
end
|
25
|
-
$cnt += 1
|
26
|
-
print "\r #{$cnt}"
|
27
|
-
end
|
28
|
-
rescue Exception => e
|
29
|
-
puts "#{e.class}: #{e.message}"
|
30
|
-
puts "url: #{$url}"
|
31
|
-
end
|
data/test/curl/just_oj.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$VERBOSE = true
|
5
|
-
|
6
|
-
$: << File.dirname(__FILE__)
|
7
|
-
$: << File.expand_path("../../ext")
|
8
|
-
$: << File.expand_path("../../lib")
|
9
|
-
|
10
|
-
require 'oj'
|
11
|
-
|
12
|
-
$json = %|
|
13
|
-
{
|
14
|
-
"data" : [ {
|
15
|
-
"action" : "login",
|
16
|
-
"event" : "user",
|
17
|
-
"field" : "login",
|
18
|
-
"value" : "foobar",
|
19
|
-
"info" : "Authenticated \\"Foo Bar\\"",
|
20
|
-
"id" : "585929918297f2740ed9f5f0",
|
21
|
-
"_metadata" : {
|
22
|
-
"version" : "1"
|
23
|
-
},
|
24
|
-
"timestamp" : "2016-12-20T07:52:33",
|
25
|
-
"key_id" : "4"
|
26
|
-
} ],
|
27
|
-
"info" : {
|
28
|
-
"view" : "partial",
|
29
|
-
"limit" : 500,
|
30
|
-
"offset" : 2000,
|
31
|
-
"results" : 500,
|
32
|
-
"ordering" : "timestamp desc,id",
|
33
|
-
"previous" : "https://api.server.com/some/path/event?calculate_total=false&draft=base&order_by=timestamp_desc&order_by=id&subdraft=none&offset=1500&limit=500",
|
34
|
-
"next" : "https://api.server.com/some/path/event?calculate_total=false&draft=base&order_by=timestamp_desc&order_by=id&subdraft=none&offset=2500&limit=500",
|
35
|
-
"draft" : "base",
|
36
|
-
"subdraft" : "none",
|
37
|
-
"total_results" : 100000
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
|
41
|
-
|
42
|
-
$cnt = 0
|
43
|
-
|
44
|
-
while true
|
45
|
-
before = GC.count
|
46
|
-
data = Oj.load($json, symbol_keys: true, mode: :strict)
|
47
|
-
puts " did a GC in Oj #{GC.count} - #{$cnt}" if before != GC.count
|
48
|
-
raise "FAILED" if data[:data].any? { |e| e.empty? }
|
49
|
-
$cnt += 1
|
50
|
-
print "\r #{$cnt}" if 0 == ($cnt % 10000)
|
51
|
-
end
|
data/test/example.rb
DELETED
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]'))
|
@@ -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
|
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/rails.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$VERBOSE = true
|
5
|
-
|
6
|
-
here = File.expand_path(File.dirname(__FILE__))
|
7
|
-
$: << File.dirname(__FILE__)
|
8
|
-
$: << File.join(File.dirname(here), 'ext')
|
9
|
-
$: << File.join(File.dirname(here), 'lib')
|
10
|
-
|
11
|
-
require "active_record"
|
12
|
-
require "minitest/autorun"
|
13
|
-
require "logger"
|
14
|
-
require 'sidekiq/testing'
|
15
|
-
require "rspec/mocks/minitest_integration"
|
16
|
-
require 'oj'
|
17
|
-
|
18
|
-
Oj.mimic_JSON
|
19
|
-
|
20
|
-
Sidekiq::Testing.inline!
|
21
|
-
|
22
|
-
# Ensure backward compatibility with Minitest 4
|
23
|
-
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
24
|
-
|
25
|
-
# This connection will do for database-independent bug reports.
|
26
|
-
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
27
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
28
|
-
|
29
|
-
ActiveRecord::Schema.define do
|
30
|
-
create_table :posts, force: true do |t|
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Post < ActiveRecord::Base
|
35
|
-
end
|
36
|
-
|
37
|
-
class MyWorker
|
38
|
-
include Sidekiq::Worker
|
39
|
-
|
40
|
-
def perform(post)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class BugTest < Minitest::Test
|
45
|
-
def test_as_json
|
46
|
-
Post.arel_table
|
47
|
-
dbl = instance_double("Post", id: 1)
|
48
|
-
MyWorker.perform_async dbl
|
49
|
-
end
|
50
|
-
end
|
data/test/russian.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
%w(lib ext test).each do |dir|
|
7
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'oj'
|
11
|
-
|
12
|
-
s = %|{"response":[{"id":7250,"from_id":1382722,"owner_id":1382722,"date":1415964230,"post_type":"post","text":"Сдается комната в 2-х комнатной квартире с декабря месяца в Люберцах. (р-он Красная Горка)\nСдается желательно семейной паре (можно рассмотреть и другие варианты). \nв комнате одна большая . Стол, Шкаф, комод.\nДля проживания все есть. в Соседней комнате проживают два парня (из Чувашии)\nДо города можно доехать на маршрутке (20 мин.) на против дома остановка, на электричке (до электрички 15-20 мин. пешком) или на автобусе\nЦена 15 тыс. за комнату + коммунальные услуги\nЗвоните 8\/903\/012-34-25 венера","comments":{"count":0},"likes":{"count":1},"reposts":{"count":0}}]}|
|
13
|
-
|
14
|
-
r = Oj.load(s)
|
15
|
-
|
16
|
-
text = r["response"][0]["text"]
|
17
|
-
puts "#{text}"
|
18
|
-
puts "#{text.encoding}"
|
data/test/struct.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
|
5
|
-
# required. That can be set in the RUBYOPT environment variable.
|
6
|
-
# export RUBYOPT=-w
|
7
|
-
|
8
|
-
$VERBOSE = true
|
9
|
-
|
10
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
11
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
12
|
-
|
13
|
-
require 'oj'
|
14
|
-
|
15
|
-
A = Struct.new(:a,:b,:c,:d)
|
16
|
-
B = Struct.new(:e,:f)
|
17
|
-
|
18
|
-
obj = [A.new(55, B.new(1, 'X'), B.new(2, 'Y'), 3)]
|
19
|
-
|
20
|
-
s = Oj.dump(obj, :mode => :object)
|
21
|
-
|
22
|
-
100000.times do
|
23
|
-
Oj.load(s, :mode => :object)
|
24
|
-
# ds = Oj.dump(o, :mode => :object)
|
25
|
-
# if ds != s
|
26
|
-
# puts ds
|
27
|
-
# raise "holy crap"
|
28
|
-
# end
|
29
|
-
end
|
data/test/test_serializer.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
%w(lib ext test).each do |dir|
|
7
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'minitest'
|
11
|
-
require 'minitest/autorun'
|
12
|
-
require 'oj'
|
13
|
-
|
14
|
-
Oj.mimic_JSON
|
15
|
-
|
16
|
-
require 'rails/all'
|
17
|
-
require 'active_model'
|
18
|
-
require 'active_model_serializers'
|
19
|
-
require 'active_support/json'
|
20
|
-
|
21
|
-
#Oj.mimic_JSON
|
22
|
-
|
23
|
-
class Category
|
24
|
-
include ActiveModel::Model
|
25
|
-
include ActiveModel::SerializerSupport
|
26
|
-
|
27
|
-
attr_accessor :id, :name
|
28
|
-
|
29
|
-
def initialize(id, name)
|
30
|
-
@id = id
|
31
|
-
@name = name
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class CategorySerializer < ActiveModel::Serializer
|
36
|
-
attributes :id, :name
|
37
|
-
end
|
38
|
-
|
39
|
-
class MimicRails < Minitest::Test
|
40
|
-
|
41
|
-
def test_dump_object
|
42
|
-
Oj.default_options= {:indent => 0}
|
43
|
-
category = Category.new(1, 'test')
|
44
|
-
serializer = CategorySerializer.new(category)
|
45
|
-
|
46
|
-
json = serializer.to_json()
|
47
|
-
puts "*** serializer.to_json() #{serializer.to_json()}"
|
48
|
-
assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
|
49
|
-
|
50
|
-
json = serializer.as_json()
|
51
|
-
puts "*** serializer.as_json() #{serializer.as_json()}"
|
52
|
-
assert_equal({"category" => {:id => 1, :name => "test"}}, json)
|
53
|
-
|
54
|
-
json = JSON.dump(serializer)
|
55
|
-
puts "*** JSON.dump(serializer) #{JSON.dump(serializer)}"
|
56
|
-
assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
|
57
|
-
end
|
58
|
-
|
59
|
-
end # MimicRails
|
data/test/write_timebars.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
%w(lib ext).each do |dir|
|
5
|
-
$LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'stringio'
|
9
|
-
require 'oj'
|
10
|
-
|
11
|
-
|
12
|
-
filename = File.join(File.dirname(__FILE__), 'day.json')
|
13
|
-
File.open(filename, "w") do |f|
|
14
|
-
w = Oj::StreamWriter.new(f, :indent => -1)
|
15
|
-
390.times do |i|
|
16
|
-
w.push_object()
|
17
|
-
w.push_value(12, 'msgType')
|
18
|
-
w.push_value(1, 'version')
|
19
|
-
w.push_value(1_400_074_200 + i * 60, 'bar')
|
20
|
-
w.push_value('TBC', 'source')
|
21
|
-
w.push_array('timebars')
|
22
|
-
w.push_object()
|
23
|
-
w.push_value('aapl_24', 'asset')
|
24
|
-
w.push_value(91.87, 'close')
|
25
|
-
w.pop()
|
26
|
-
w.pop()
|
27
|
-
w.pop()
|
28
|
-
end
|
29
|
-
f.write("\n")
|
30
|
-
end
|
31
|
-
|