oj 3.6.4 → 3.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/dump.c +37 -27
- data/ext/oj/dump.h +1 -0
- data/ext/oj/dump_compat.c +11 -7
- data/ext/oj/fast.c +67 -33
- data/ext/oj/rails.c +11 -6
- data/ext/oj/wab.c +14 -9
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +46 -55
- data/test/test_various.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4e0a767653f34a793b28037b299f5580e6b24cec56edbc7c01add6067a8a8f
|
4
|
+
data.tar.gz: ec009f0e9ce5bb255dd11325ccfbeef78d9cb35bb0e0bdba9cc718e3f511e85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c457ef279848a3ccaacb4c28e60f6433f5a5735fcec526d29cda2557ebef7edb112d0d9b548027832eff669ccf74a795d3fda77bc59d25babb9637f9f81bc433
|
7
|
+
data.tar.gz: 397a8d2c6666228766180aca8482c9f528fa31c240638708d68c92ccc1d96ac2f3d513ad4a0e838012c04ba536328063b7a7e00e63366fd1f86fc408d3af5f7e
|
data/ext/oj/dump.c
CHANGED
@@ -341,25 +341,30 @@ oj_check_circular(VALUE obj, Out out) {
|
|
341
341
|
|
342
342
|
void
|
343
343
|
oj_dump_time(VALUE obj, Out out, int withZone) {
|
344
|
-
char
|
345
|
-
char
|
346
|
-
long
|
347
|
-
char
|
348
|
-
int
|
349
|
-
long
|
344
|
+
char buf[64];
|
345
|
+
char *b = buf + sizeof(buf) - 1;
|
346
|
+
long size;
|
347
|
+
char *dot;
|
348
|
+
int neg = 0;
|
349
|
+
long one = 1000000000;
|
350
|
+
time_t sec;
|
351
|
+
long long nsec;
|
352
|
+
|
350
353
|
#if HAS_RB_TIME_TIMESPEC
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
+
{
|
355
|
+
struct timespec ts = rb_time_timespec(obj);
|
356
|
+
sec = ts.tv_sec;
|
357
|
+
nsec = ts.tv_nsec;
|
358
|
+
}
|
354
359
|
#else
|
355
|
-
|
360
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
356
361
|
#if HAS_NANO_TIME
|
357
|
-
|
362
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
358
363
|
#else
|
359
|
-
|
364
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
|
360
365
|
#endif
|
361
366
|
#endif
|
362
|
-
|
367
|
+
|
363
368
|
*b-- = '\0';
|
364
369
|
if (withZone) {
|
365
370
|
long tzsecs = NUM2LONG(rb_funcall2(obj, oj_utc_offset_id, 0, 0));
|
@@ -438,24 +443,29 @@ oj_dump_ruby_time(VALUE obj, Out out) {
|
|
438
443
|
|
439
444
|
void
|
440
445
|
oj_dump_xml_time(VALUE obj, Out out) {
|
441
|
-
char
|
442
|
-
struct tm
|
443
|
-
long
|
446
|
+
char buf[64];
|
447
|
+
struct tm *tm;
|
448
|
+
long one = 1000000000;
|
449
|
+
time_t sec;
|
450
|
+
long long nsec;
|
451
|
+
long tzsecs = NUM2LONG(rb_funcall2(obj, oj_utc_offset_id, 0, 0));
|
452
|
+
int tzhour, tzmin;
|
453
|
+
char tzsign = '+';
|
454
|
+
|
444
455
|
#if HAS_RB_TIME_TIMESPEC
|
445
|
-
|
446
|
-
|
447
|
-
|
456
|
+
{
|
457
|
+
struct timespec ts = rb_time_timespec(obj);
|
458
|
+
sec = ts.tv_sec;
|
459
|
+
nsec = ts.tv_nsec;
|
460
|
+
}
|
448
461
|
#else
|
449
|
-
|
462
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
450
463
|
#if HAS_NANO_TIME
|
451
|
-
|
464
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
452
465
|
#else
|
453
|
-
|
466
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
|
454
467
|
#endif
|
455
468
|
#endif
|
456
|
-
long tzsecs = NUM2LONG(rb_funcall2(obj, oj_utc_offset_id, 0, 0));
|
457
|
-
int tzhour, tzmin;
|
458
|
-
char tzsign = '+';
|
459
469
|
|
460
470
|
assure_size(out, 36);
|
461
471
|
if (9 > out->opts->sec_prec) {
|
@@ -524,7 +534,7 @@ oj_dump_xml_time(VALUE obj, Out out) {
|
|
524
534
|
}
|
525
535
|
sprintf(buf, format,
|
526
536
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
527
|
-
tm->tm_hour, tm->tm_min, tm->tm_sec, nsec);
|
537
|
+
tm->tm_hour, tm->tm_min, tm->tm_sec, (long)nsec);
|
528
538
|
oj_dump_cstr(buf, len, 0, 0, out);
|
529
539
|
} else {
|
530
540
|
char format[64] = "%04d-%02d-%02dT%02d:%02d:%02d.%09ld%c%02d:%02d";
|
@@ -536,7 +546,7 @@ oj_dump_xml_time(VALUE obj, Out out) {
|
|
536
546
|
}
|
537
547
|
sprintf(buf, format,
|
538
548
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
539
|
-
tm->tm_hour, tm->tm_min, tm->tm_sec, nsec,
|
549
|
+
tm->tm_hour, tm->tm_min, tm->tm_sec, (long)nsec,
|
540
550
|
tzsign, tzhour, tzmin);
|
541
551
|
oj_dump_cstr(buf, len, 0, 0, out);
|
542
552
|
}
|
data/ext/oj/dump.h
CHANGED
@@ -51,6 +51,7 @@ extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
|
|
51
51
|
extern int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *format);
|
52
52
|
|
53
53
|
extern bool oj_dump_ignore(Options opts, VALUE obj);
|
54
|
+
extern time_t oj_sec_from_time_hard_way(VALUE obj);
|
54
55
|
|
55
56
|
inline static void
|
56
57
|
assure_size(Out out, size_t len) {
|
data/ext/oj/dump_compat.c
CHANGED
@@ -189,7 +189,6 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
189
189
|
} else {
|
190
190
|
fill_indent(out, d2);
|
191
191
|
}
|
192
|
-
// TBD for child as_ok check the type, time is to_s while others are to_json
|
193
192
|
oj_dump_compat_val(rb_ary_entry(a, i), d2, out, true);
|
194
193
|
if (i < cnt) {
|
195
194
|
*out->cur++ = ',';
|
@@ -472,16 +471,21 @@ time_alt(VALUE obj, int depth, Out out) {
|
|
472
471
|
{ "n", 1, Qundef, 0, Qundef },
|
473
472
|
{ NULL, 0, Qnil },
|
474
473
|
};
|
474
|
+
time_t sec;
|
475
|
+
long long nsec;
|
476
|
+
|
475
477
|
#if HAS_RB_TIME_TIMESPEC
|
476
|
-
|
477
|
-
|
478
|
-
|
478
|
+
{
|
479
|
+
struct timespec ts = rb_time_timespec(obj);
|
480
|
+
sec = ts.tv_sec;
|
481
|
+
nsec = ts.tv_nsec;
|
482
|
+
}
|
479
483
|
#else
|
480
|
-
|
484
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
481
485
|
#if HAS_NANO_TIME
|
482
|
-
|
486
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
483
487
|
#else
|
484
|
-
|
488
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
|
485
489
|
#endif
|
486
490
|
#endif
|
487
491
|
|
data/ext/oj/fast.c
CHANGED
@@ -115,7 +115,7 @@ static VALUE doc_each_value(int argc, VALUE *argv, VALUE self);
|
|
115
115
|
static VALUE doc_dump(int argc, VALUE *argv, VALUE self);
|
116
116
|
static VALUE doc_size(VALUE self);
|
117
117
|
|
118
|
-
VALUE oj_doc_class =
|
118
|
+
VALUE oj_doc_class = Qundef;
|
119
119
|
|
120
120
|
// This is only for CentOS 5.4 with Ruby 1.9.3-p0.
|
121
121
|
#ifdef NEEDS_STPCPY
|
@@ -358,7 +358,7 @@ leaf_float_value(Leaf leaf) {
|
|
358
358
|
|
359
359
|
static VALUE
|
360
360
|
leaf_array_value(Doc doc, Leaf leaf) {
|
361
|
-
VALUE a = rb_ary_new();
|
361
|
+
volatile VALUE a = rb_ary_new();
|
362
362
|
|
363
363
|
if (0 != leaf->elements) {
|
364
364
|
Leaf first = leaf->elements->next;
|
@@ -374,12 +374,12 @@ leaf_array_value(Doc doc, Leaf leaf) {
|
|
374
374
|
|
375
375
|
static VALUE
|
376
376
|
leaf_hash_value(Doc doc, Leaf leaf) {
|
377
|
-
VALUE h = rb_hash_new();
|
377
|
+
volatile VALUE h = rb_hash_new();
|
378
378
|
|
379
379
|
if (0 != leaf->elements) {
|
380
|
-
Leaf
|
381
|
-
Leaf
|
382
|
-
VALUE key;
|
380
|
+
Leaf first = leaf->elements->next;
|
381
|
+
Leaf e = first;
|
382
|
+
volatile VALUE key;
|
383
383
|
|
384
384
|
do {
|
385
385
|
key = rb_str_new2(e->key);
|
@@ -778,17 +778,51 @@ free_doc_cb(void *x) {
|
|
778
778
|
}
|
779
779
|
}
|
780
780
|
|
781
|
+
static void
|
782
|
+
mark_leaf(Leaf leaf) {
|
783
|
+
switch (leaf->value_type) {
|
784
|
+
case COL_VAL:
|
785
|
+
if (NULL != leaf->elements) {
|
786
|
+
Leaf first = leaf->elements->next;
|
787
|
+
Leaf e = first;
|
788
|
+
|
789
|
+
do {
|
790
|
+
mark_leaf(e);
|
791
|
+
e = e->next;
|
792
|
+
} while (e != first);
|
793
|
+
}
|
794
|
+
break;
|
795
|
+
case RUBY_VAL:
|
796
|
+
rb_gc_mark(leaf->value);
|
797
|
+
break;
|
798
|
+
|
799
|
+
default:
|
800
|
+
break;
|
801
|
+
}
|
802
|
+
}
|
803
|
+
|
804
|
+
static void
|
805
|
+
mark_doc(void *ptr) {
|
806
|
+
if (NULL != ptr) {
|
807
|
+
Doc doc = (Doc)ptr;
|
808
|
+
|
809
|
+
rb_gc_mark(doc->self);
|
810
|
+
mark_leaf(doc->data);
|
811
|
+
}
|
812
|
+
}
|
813
|
+
|
781
814
|
static VALUE
|
782
815
|
parse_json(VALUE clas, char *json, bool given, bool allocated) {
|
783
816
|
struct _ParseInfo pi;
|
784
|
-
VALUE
|
817
|
+
volatile VALUE result = Qnil;
|
785
818
|
Doc doc;
|
786
819
|
int ex = 0;
|
820
|
+
volatile VALUE self;
|
787
821
|
|
788
822
|
if (given) {
|
789
823
|
doc = ALLOCA_N(struct _Doc, 1);
|
790
824
|
} else {
|
791
|
-
doc =
|
825
|
+
doc = ALLOC(struct _Doc);
|
792
826
|
}
|
793
827
|
/* skip UTF-8 BOM if present */
|
794
828
|
if (0xEF == (uint8_t)*json && 0xBB == (uint8_t)json[1] && 0xBF == (uint8_t)json[2]) {
|
@@ -814,17 +848,16 @@ parse_json(VALUE clas, char *json, bool given, bool allocated) {
|
|
814
848
|
#endif
|
815
849
|
// last arg is free func void* func(void*)
|
816
850
|
#if HAS_DATA_OBJECT_WRAP
|
817
|
-
|
851
|
+
self = rb_data_object_wrap(clas, doc, mark_doc, free_doc_cb);
|
818
852
|
#else
|
819
|
-
|
853
|
+
self = rb_data_object_alloc(clas, doc, mark_doc, free_doc_cb);
|
820
854
|
#endif
|
821
|
-
|
855
|
+
doc->self = self;
|
822
856
|
doc->json = json;
|
823
857
|
DATA_PTR(doc->self) = doc;
|
824
858
|
result = rb_protect(protect_open_proc, (VALUE)&pi, &ex);
|
825
859
|
if (given || 0 != ex) {
|
826
|
-
|
827
|
-
DATA_PTR(doc->self) = 0;
|
860
|
+
DATA_PTR(doc->self) = NULL;
|
828
861
|
doc_free(pi.doc);
|
829
862
|
if (allocated && 0 != ex) { // will jump so caller will not free
|
830
863
|
xfree(json);
|
@@ -1118,11 +1151,11 @@ each_value(Doc doc, Leaf leaf) {
|
|
1118
1151
|
*/
|
1119
1152
|
static VALUE
|
1120
1153
|
doc_open(VALUE clas, VALUE str) {
|
1121
|
-
char
|
1122
|
-
size_t
|
1123
|
-
VALUE obj;
|
1124
|
-
int
|
1125
|
-
int
|
1154
|
+
char *json;
|
1155
|
+
size_t len;
|
1156
|
+
volatile VALUE obj;
|
1157
|
+
int given = rb_block_given_p();
|
1158
|
+
int allocate;
|
1126
1159
|
|
1127
1160
|
Check_Type(str, T_STRING);
|
1128
1161
|
len = RSTRING_LEN(str) + 1;
|
@@ -1160,13 +1193,13 @@ doc_open(VALUE clas, VALUE str) {
|
|
1160
1193
|
*/
|
1161
1194
|
static VALUE
|
1162
1195
|
doc_open_file(VALUE clas, VALUE filename) {
|
1163
|
-
char
|
1164
|
-
char
|
1165
|
-
FILE
|
1166
|
-
size_t
|
1167
|
-
VALUE obj;
|
1168
|
-
int
|
1169
|
-
int
|
1196
|
+
char *path;
|
1197
|
+
char *json;
|
1198
|
+
FILE *f;
|
1199
|
+
size_t len;
|
1200
|
+
volatile VALUE obj;
|
1201
|
+
int given = rb_block_given_p();
|
1202
|
+
int allocate;
|
1170
1203
|
|
1171
1204
|
Check_Type(filename, T_STRING);
|
1172
1205
|
path = StringValuePtr(filename);
|
@@ -1261,6 +1294,7 @@ doc_where(VALUE self) {
|
|
1261
1294
|
*p++ = '/';
|
1262
1295
|
}
|
1263
1296
|
*--p = '\0';
|
1297
|
+
|
1264
1298
|
return rb_str_new(path, p - path);
|
1265
1299
|
}
|
1266
1300
|
}
|
@@ -1275,9 +1309,9 @@ doc_where(VALUE self) {
|
|
1275
1309
|
*/
|
1276
1310
|
static VALUE
|
1277
1311
|
doc_local_key(VALUE self) {
|
1278
|
-
Doc
|
1279
|
-
Leaf
|
1280
|
-
VALUE key = Qnil;
|
1312
|
+
Doc doc = self_doc(self);
|
1313
|
+
Leaf leaf = *doc->where;
|
1314
|
+
volatile VALUE key = Qnil;
|
1281
1315
|
|
1282
1316
|
if (T_HASH == leaf->parent_type) {
|
1283
1317
|
key = rb_str_new2(leaf->key);
|
@@ -1361,10 +1395,10 @@ doc_type(int argc, VALUE *argv, VALUE self) {
|
|
1361
1395
|
*/
|
1362
1396
|
static VALUE
|
1363
1397
|
doc_fetch(int argc, VALUE *argv, VALUE self) {
|
1364
|
-
Doc
|
1365
|
-
Leaf
|
1366
|
-
VALUE val = Qnil;
|
1367
|
-
const char
|
1398
|
+
Doc doc;
|
1399
|
+
Leaf leaf;
|
1400
|
+
volatile VALUE val = Qnil;
|
1401
|
+
const char *path = 0;
|
1368
1402
|
|
1369
1403
|
doc = self_doc(self);
|
1370
1404
|
if (1 <= argc) {
|
@@ -1586,7 +1620,7 @@ doc_dump(int argc, VALUE *argv, VALUE self) {
|
|
1586
1620
|
}
|
1587
1621
|
}
|
1588
1622
|
if (0 != (leaf = get_doc_leaf(doc, path))) {
|
1589
|
-
VALUE rjson;
|
1623
|
+
volatile VALUE rjson;
|
1590
1624
|
|
1591
1625
|
if (0 == filename) {
|
1592
1626
|
char buf[4096];
|
data/ext/oj/rails.c
CHANGED
@@ -301,16 +301,21 @@ dump_sec_nano(VALUE obj, time_t sec, long nsec, Out out) {
|
|
301
301
|
|
302
302
|
static void
|
303
303
|
dump_time(VALUE obj, int depth, Out out, bool as_ok) {
|
304
|
+
time_t sec;
|
305
|
+
long long nsec;
|
306
|
+
|
304
307
|
#if HAS_RB_TIME_TIMESPEC
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
+
{
|
309
|
+
struct timespec ts = rb_time_timespec(obj);
|
310
|
+
sec = ts.tv_sec;
|
311
|
+
nsec = ts.tv_nsec;
|
312
|
+
}
|
308
313
|
#else
|
309
|
-
|
314
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
310
315
|
#if HAS_NANO_TIME
|
311
|
-
|
316
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
312
317
|
#else
|
313
|
-
|
318
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
|
314
319
|
#endif
|
315
320
|
#endif
|
316
321
|
dump_sec_nano(obj, sec, nsec, out);
|
data/ext/oj/wab.c
CHANGED
@@ -193,21 +193,26 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
193
193
|
|
194
194
|
static void
|
195
195
|
dump_time(VALUE obj, Out out) {
|
196
|
-
char
|
197
|
-
struct tm
|
196
|
+
char buf[64];
|
197
|
+
struct tm *tm;
|
198
|
+
int len;
|
199
|
+
time_t sec;
|
200
|
+
long long nsec;
|
201
|
+
|
198
202
|
#if HAS_RB_TIME_TIMESPEC
|
199
|
-
|
200
|
-
|
201
|
-
|
203
|
+
{
|
204
|
+
struct timespec ts = rb_time_timespec(obj);
|
205
|
+
sec = ts.tv_sec;
|
206
|
+
nsec = ts.tv_nsec;
|
207
|
+
}
|
202
208
|
#else
|
203
|
-
|
209
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
204
210
|
#if HAS_NANO_TIME
|
205
|
-
|
211
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
206
212
|
#else
|
207
|
-
|
213
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
|
208
214
|
#endif
|
209
215
|
#endif
|
210
|
-
int len;
|
211
216
|
|
212
217
|
assure_size(out, 36);
|
213
218
|
// 2012-01-05T23:58:07.123456000Z
|
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -4,64 +4,55 @@ $: << '.'
|
|
4
4
|
$: << '../lib'
|
5
5
|
$: << '../ext'
|
6
6
|
|
7
|
-
require '
|
8
|
-
require 'active_support/core_ext'
|
9
|
-
require 'active_support/json/encoding.rb'
|
10
|
-
require 'json'
|
7
|
+
require 'oj'
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
Oj.default_options = {mode: :strict}
|
10
|
+
json = Oj.dump({ aggregations: { hashtags: { buckets: Array.new(100) { { key: 'foo', count: 100 } } } } }, mode: :strict)
|
11
|
+
|
12
|
+
def expect(a,b)
|
13
|
+
puts "*** #{a} != #{b}" unless a == b
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def dig(obj, *path)
|
17
|
+
return obj if path.empty?
|
18
|
+
|
19
|
+
if obj.is_a?(Array)
|
20
|
+
obj.each { |v|
|
21
|
+
r = dig(v, *path)
|
22
|
+
return r unless r.nil?
|
23
|
+
}
|
22
24
|
end
|
25
|
+
return nil unless obj.is_a?(Hash)
|
26
|
+
|
27
|
+
dig(obj[path[0]], *path[1..-1])
|
23
28
|
end
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
puts "*** boo #{JSON.generate(boo)}"
|
55
|
-
|
56
|
-
Oj.default_options = {trace: true}
|
57
|
-
puts hash_with_time.to_json
|
58
|
-
# => {"foo":"2018-06-28T09:07:40.464Z"}
|
59
|
-
puts JSON.generate(hash_with_time)
|
60
|
-
# => {"foo":"2018-06-28T09:07:40.464Z"}
|
61
|
-
puts hash_with_time.to_json
|
62
|
-
|
63
|
-
puts JSON.generate({ foo: Foo.new }.with_indifferent_access)
|
64
|
-
puts JSON.generate({ foo: Foo.new })
|
65
|
-
# => {"foo":{}}
|
66
|
-
puts({ foo: Foo.new }.to_json)
|
67
|
-
# => {"foo":{}}
|
30
|
+
1000.times do |i|
|
31
|
+
Oj::Doc.open(json) do |doc|
|
32
|
+
# this always passes
|
33
|
+
doc.each_child('/aggregations/hashtags/buckets') do |bucket|
|
34
|
+
expect(bucket.fetch('key'), 'foo')
|
35
|
+
expect(bucket.fetch('count'), 100)
|
36
|
+
end
|
37
|
+
|
38
|
+
# load any other json using Oj.load
|
39
|
+
# this will pass
|
40
|
+
other = Oj.load(json)
|
41
|
+
dig(other, 'aggregations', 'hashtags', 'buckets').each do |bucket|
|
42
|
+
expect(bucket.fetch('key'), 'foo')
|
43
|
+
expect(bucket.fetch('count'), 100)
|
44
|
+
end
|
45
|
+
GC.start
|
46
|
+
doc.each_child('/aggregations/hashtags/buckets') do |bucket|
|
47
|
+
# This is where it fails!!!! It will be some other object (even an rspec matcher in some cases)
|
48
|
+
expect(bucket.fetch('key'), 'foo')
|
49
|
+
expect(bucket.fetch('count'), 100)
|
50
|
+
end
|
51
|
+
|
52
|
+
# this always passes if it gets this far
|
53
|
+
dig(other, 'aggregations', 'hashtags', 'buckets').each do |bucket|
|
54
|
+
expect(bucket.fetch('key'), 'foo')
|
55
|
+
expect(bucket.fetch('count'), 100)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/test_various.rb
CHANGED
@@ -407,6 +407,12 @@ class Juice < Minitest::Test
|
|
407
407
|
assert_equal('null', json)
|
408
408
|
end
|
409
409
|
|
410
|
+
def test_time_neg
|
411
|
+
t = Time.parse("1900-01-01 00:18:59 UTC")
|
412
|
+
json = Oj.dump(t, :mode => :custom, :time_format => :unix)
|
413
|
+
assert_equal('-2208987661.000000000', json)
|
414
|
+
end
|
415
|
+
|
410
416
|
# Class
|
411
417
|
def test_class_null
|
412
418
|
json = Oj.dump(Juice, :mode => :null)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|