oj 2.9.6 → 2.9.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa935c82f850cb8bacad4b1dfdbeebdfd0af777f
4
- data.tar.gz: 1bf95c9767bb1ee814871a859fd2312fbe00dd28
3
+ metadata.gz: 46cf0f951fe71b68f7df69debe2b80be4fa37539
4
+ data.tar.gz: 3988bbf389028c52969cdd2702671b37d78a7f9f
5
5
  SHA512:
6
- metadata.gz: 10e76efb7219459edcc77fec2518dc1c9e036cfa7a2f7c3d49942b3b26085d3b45a25fae451c934eadc087656abc7d2678813de3be7496e5665bb9f7c6278d05
7
- data.tar.gz: 4643da9813d1664bbbf06bd6ca7a29e3a9c5fac54d0750ac0fc05e25ea6c72cbab825eaf5901cd029eccff9f00eeb7e3d6fcc3c761a37793452f85b81685540e
6
+ metadata.gz: 0a2e47552a218ebe9d1c0e58e134fa1a5eb36ad0754e72c638d15a528ff12093b5cc1a7587ab61c4491ea046a4c5186562f2f0916f936485a6b31296ba37de0a
7
+ data.tar.gz: d996faa5d574f3e5146e872bb4e863f2a286d6b9017d2679db7d570154341f4d0813bd06db5bf672e704d73a184c14769e653280a032e6286286035e71acd76d
data/README.md CHANGED
@@ -26,7 +26,26 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
26
26
 
27
27
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
28
28
 
29
- ### Current Release 2.9.6
29
+ ### Current Release 2.9.7
30
+
31
+ - Changed dump to use raw / and raw \n in output instead of escaping.
32
+
33
+ - Changed the writer to always put a new line at the end of a top level JSON
34
+ object. It makes output easier to view and edit with minimal impact on size.
35
+
36
+ - TBD Worked around the file.gets look ahead caching as long as it is not
37
+ called while parsing (of course).
38
+
39
+ - Thanks to lautis for a new parse option. quirks_mode allows Oj to behave
40
+ quirky like the JSON gem. Actually the JSON gem has it backwards with quirky
41
+ mode supporting the JSON spec and non-quirky limiting parsing to objects and
42
+ arrays. Oj stays consistent with the JSON gem to avoid confusion.
43
+
44
+ - Fixed problem with sc_parse not terminating the string when loaded from a file.
45
+
46
+ - Thanks go to dchelimsky for expanding the code sample for the ScHandler.
47
+
48
+ ### Release 2.9.6
30
49
 
31
50
  - Fixed bug using StringIO with SCParser.
32
51
 
@@ -112,8 +112,8 @@ static void dump_leaf_hash(Leaf leaf, int depth, Out out);
112
112
  static const char hex_chars[17] = "0123456789abcdef";
113
113
 
114
114
  static char hibit_friendly_chars[256] = "\
115
- 66666666222622666666666666666666\
116
- 11211111111111121111111111111111\
115
+ 66666666221622666666666666666666\
116
+ 11211111111111111111111111111111\
117
117
  11111111111111111111111111112111\
118
118
  11111111111111111111111111111111\
119
119
  11111111111111111111111111111111\
@@ -2313,7 +2313,7 @@ oj_str_writer_pop(StrWriter sw) {
2313
2313
  *sw->out.cur++ = ']';
2314
2314
  break;
2315
2315
  }
2316
- if (0 == sw->depth && 0 < sw->out.indent) {
2316
+ if (0 == sw->depth) {
2317
2317
  *sw->out.cur++ = '\n';
2318
2318
  }
2319
2319
  }
@@ -67,6 +67,7 @@ ID oj_instance_variables_id;
67
67
  ID oj_json_create_id;
68
68
  ID oj_length_id;
69
69
  ID oj_new_id;
70
+ ID oj_pos_id;
70
71
  ID oj_read_id;
71
72
  ID oj_readpartial_id;
72
73
  ID oj_replace_id;
@@ -116,6 +117,7 @@ static VALUE mode_sym;
116
117
  static VALUE nilnil_sym;
117
118
  static VALUE null_sym;
118
119
  static VALUE object_sym;
120
+ static VALUE quirks_mode_sym;
119
121
  static VALUE ruby_sym;
120
122
  static VALUE sec_prec_sym;
121
123
  static VALUE strict_sym;
@@ -165,6 +167,7 @@ struct _Options oj_default_options = {
165
167
  10, // create_id_len
166
168
  9, // sec_prec
167
169
  Yes, // allow_gc
170
+ Yes, // quirks_mode
168
171
  0, // dump_opts
169
172
  };
170
173
 
@@ -188,6 +191,7 @@ static VALUE define_mimic_json(int argc, VALUE *argv, VALUE self);
188
191
  * - use_to_json: [true|false|nil] call to_json() methods on dump, default is false
189
192
  * - nilnil: [true|false|nil] if true a nil input to load will return nil and not raise an Exception
190
193
  * - allow_gc: [true|false|nil] allow or prohibit GC during parsing, default is true (allow)
194
+ * - quirks_mode: [true,|false|nil] Allow single JSON values instead of documents, default is true (allow)
191
195
  * @return [Hash] all current option settings.
192
196
  */
193
197
  static VALUE
@@ -204,6 +208,7 @@ get_def_opts(VALUE self) {
204
208
  rb_hash_aset(opts, use_to_json_sym, (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
205
209
  rb_hash_aset(opts, nilnil_sym, (Yes == oj_default_options.nilnil) ? Qtrue : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
206
210
  rb_hash_aset(opts, allow_gc_sym, (Yes == oj_default_options.allow_gc) ? Qtrue : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
211
+ rb_hash_aset(opts, quirks_mode_sym, (Yes == oj_default_options.quirks_mode) ? Qtrue : ((No == oj_default_options.quirks_mode) ? Qfalse : Qnil));
207
212
  switch (oj_default_options.mode) {
208
213
  case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
209
214
  case CompatMode: rb_hash_aset(opts, mode_sym, compat_sym); break;
@@ -265,6 +270,7 @@ get_def_opts(VALUE self) {
265
270
  * @param [true|false|nil] :use_to_json call to_json() methods on dump, default is false
266
271
  * @param [true|false|nil] :nilnil if true a nil input to load will return nil and not raise an Exception
267
272
  * @param [true|false|nil] :allow_gc allow or prohibit GC during parsing, default is true (allow)
273
+ * @param [true|false|nil] :quirks_mode allow single JSON values instead of documents, default is true (allow)
268
274
  * @return [nil]
269
275
  */
270
276
  static VALUE
@@ -278,6 +284,7 @@ set_def_opts(VALUE self, VALUE opts) {
278
284
  { use_to_json_sym, &oj_default_options.to_json },
279
285
  { nilnil_sym, &oj_default_options.nilnil },
280
286
  { allow_gc_sym, &oj_default_options.allow_gc },
287
+ { quirks_mode_sym, &oj_default_options.quirks_mode },
281
288
  { Qnil, 0 }
282
289
  };
283
290
  YesNoOpt o;
@@ -410,6 +417,7 @@ oj_parse_options(VALUE ropts, Options copts) {
410
417
  { use_to_json_sym, &copts->to_json },
411
418
  { nilnil_sym, &copts->nilnil },
412
419
  { allow_gc_sym, &copts->allow_gc },
420
+ { quirks_mode_sym, &copts->quirks_mode },
413
421
  { Qnil, 0 }
414
422
  };
415
423
  YesNoOpt o;
@@ -1225,9 +1233,10 @@ stream_writer_new(int argc, VALUE *argv, VALUE self) {
1225
1233
  }
1226
1234
  sw = ALLOC(struct _StreamWriter);
1227
1235
  str_writer_init(&sw->sw);
1228
- if (1 == argc) {
1229
- oj_parse_options(argv[0], &sw->sw.opts);
1236
+ if (2 == argc) {
1237
+ oj_parse_options(argv[1], &sw->sw.opts);
1230
1238
  }
1239
+ sw->sw.out.indent = sw->sw.opts.indent;
1231
1240
  sw->stream = stream;
1232
1241
  sw->type = type;
1233
1242
  sw->fd = fd;
@@ -1614,7 +1623,6 @@ static VALUE
1614
1623
  mimic_parse(int argc, VALUE *argv, VALUE self) {
1615
1624
  struct _ParseInfo pi;
1616
1625
  VALUE args[1];
1617
- VALUE result;
1618
1626
 
1619
1627
  if (argc < 1) {
1620
1628
  rb_raise(rb_eArgError, "Wrong number of arguments to parse.");
@@ -1622,6 +1630,8 @@ mimic_parse(int argc, VALUE *argv, VALUE self) {
1622
1630
  oj_set_compat_callbacks(&pi);
1623
1631
  pi.options = oj_default_options;
1624
1632
  pi.options.auto_define = No;
1633
+ pi.options.quirks_mode = No;
1634
+
1625
1635
  if (2 <= argc) {
1626
1636
  VALUE ropts = argv[1];
1627
1637
  VALUE v;
@@ -1632,6 +1642,11 @@ mimic_parse(int argc, VALUE *argv, VALUE self) {
1632
1642
  if (Qnil != (v = rb_hash_lookup(ropts, symbolize_names_sym))) {
1633
1643
  pi.options.sym_key = (Qtrue == v) ? Yes : No;
1634
1644
  }
1645
+
1646
+ if (Qnil != (v = rb_hash_lookup(ropts, quirks_mode_sym))) {
1647
+ pi.options.quirks_mode = (Qtrue == v) ? Yes : No;
1648
+ }
1649
+
1635
1650
  if (Qnil != (v = rb_hash_lookup(ropts, create_additions_sym))) {
1636
1651
  if (Qfalse == v) {
1637
1652
  oj_set_strict_callbacks(&pi);
@@ -1644,22 +1659,7 @@ mimic_parse(int argc, VALUE *argv, VALUE self) {
1644
1659
  }
1645
1660
  *args = *argv;
1646
1661
 
1647
- result = oj_pi_parse(1, args, &pi, 0, 0, 0);
1648
- switch (rb_type(result)) {
1649
- case T_NIL:
1650
- case T_TRUE:
1651
- case T_FALSE:
1652
- case T_FIXNUM:
1653
- case T_FLOAT:
1654
- case T_CLASS:
1655
- case T_SYMBOL:
1656
- rb_raise(oj_parse_error_class, "parse is only allowed to return data structure.");
1657
- break;
1658
- default:
1659
- // okay
1660
- break;
1661
- }
1662
- return result;
1662
+ return oj_pi_parse(1, args, &pi, 0, 0, 0);
1663
1663
  }
1664
1664
 
1665
1665
  static VALUE
@@ -1713,6 +1713,7 @@ static struct _Options mimic_object_to_json_options = {
1713
1713
  10, // create_id_len
1714
1714
  9, // sec_prec
1715
1715
  Yes, // allow_gc
1716
+ Yes, // quirks_mode
1716
1717
  0, // dump_opts
1717
1718
  };
1718
1719
 
@@ -1952,6 +1953,7 @@ void Init_oj() {
1952
1953
  oj_json_create_id = rb_intern("json_create");
1953
1954
  oj_length_id = rb_intern("length");
1954
1955
  oj_new_id = rb_intern("new");
1956
+ oj_pos_id = rb_intern("pos");
1955
1957
  oj_read_id = rb_intern("read");
1956
1958
  oj_readpartial_id = rb_intern("readpartial");
1957
1959
  oj_replace_id = rb_intern("replace");
@@ -2002,6 +2004,7 @@ void Init_oj() {
2002
2004
  mode_sym = ID2SYM(rb_intern("mode")); rb_gc_register_address(&mode_sym);
2003
2005
  null_sym = ID2SYM(rb_intern("null")); rb_gc_register_address(&null_sym);
2004
2006
  object_sym = ID2SYM(rb_intern("object")); rb_gc_register_address(&object_sym);
2007
+ quirks_mode_sym = ID2SYM(rb_intern("quirks_mode")); rb_gc_register_address(&quirks_mode_sym);
2005
2008
  ruby_sym = ID2SYM(rb_intern("ruby")); rb_gc_register_address(&ruby_sym);
2006
2009
  sec_prec_sym = ID2SYM(rb_intern("second_precision"));rb_gc_register_address(&sec_prec_sym);
2007
2010
  strict_sym = ID2SYM(rb_intern("strict")); rb_gc_register_address(&strict_sym);
@@ -141,6 +141,7 @@ typedef struct _Options {
141
141
  size_t create_id_len; // length of create_id
142
142
  int sec_prec; // second precision when dumping time
143
143
  char allow_gc; // allow GC during parse
144
+ char quirks_mode; // allow single JSON values instead of documents
144
145
  DumpOpts dump_opts;
145
146
  } *Options;
146
147
 
@@ -262,6 +263,7 @@ extern ID oj_instance_variables_id;
262
263
  extern ID oj_json_create_id;
263
264
  extern ID oj_length_id;
264
265
  extern ID oj_new_id;
266
+ extern ID oj_pos_id;
265
267
  extern ID oj_read_id;
266
268
  extern ID oj_readpartial_id;
267
269
  extern ID oj_replace_id;
@@ -873,5 +873,23 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
873
873
  if (err_has(&pi->err)) {
874
874
  oj_err_raise(&pi->err);
875
875
  }
876
+
877
+ if (pi->options.quirks_mode == No) {
878
+ switch (rb_type(result)) {
879
+ case T_NIL:
880
+ case T_TRUE:
881
+ case T_FALSE:
882
+ case T_FIXNUM:
883
+ case T_FLOAT:
884
+ case T_CLASS:
885
+ case T_SYMBOL:
886
+ rb_raise(oj_parse_error_class, "unexpected non-document value");
887
+ break;
888
+ default:
889
+ // okay
890
+ break;
891
+ }
892
+ }
893
+
876
894
  return result;
877
895
  }
@@ -86,7 +86,9 @@ oj_reader_init(Reader reader, VALUE io, int fd) {
86
86
  } else if (rb_respond_to(io, oj_readpartial_id)) {
87
87
  VALUE rfd;
88
88
 
89
- if (rb_respond_to(io, oj_fileno_id) && Qnil != (rfd = rb_funcall(io, oj_fileno_id, 0))) {
89
+ if (rb_respond_to(io, oj_fileno_id) && Qnil != (rfd = rb_funcall(io, oj_fileno_id, 0)) &&
90
+ rb_respond_to(io, oj_pos_id) && 0 == FIX2INT(rb_funcall(io, oj_pos_id, 0))) {
91
+
90
92
  reader->read_func = read_from_fd;
91
93
  reader->fd = FIX2INT(rfd);
92
94
  } else {
@@ -96,7 +98,9 @@ oj_reader_init(Reader reader, VALUE io, int fd) {
96
98
  } else if (rb_respond_to(io, oj_read_id)) {
97
99
  VALUE rfd;
98
100
 
99
- if (rb_respond_to(io, oj_fileno_id) && Qnil != (rfd = rb_funcall(io, oj_fileno_id, 0))) {
101
+ if (rb_respond_to(io, oj_fileno_id) && Qnil != (rfd = rb_funcall(io, oj_fileno_id, 0)) &&
102
+ rb_respond_to(io, oj_pos_id) && 0 == FIX2INT(rb_funcall(io, oj_pos_id, 0))) {
103
+
100
104
  reader->read_func = read_from_fd;
101
105
  reader->fd = FIX2INT(rfd);
102
106
  } else {
@@ -275,7 +275,8 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
275
275
  size_t len = lseek(fd, 0, SEEK_END);
276
276
 
277
277
  lseek(fd, 0, SEEK_SET);
278
- buf = ALLOC_N(char, len);
278
+ buf = ALLOC_N(char, len + 1);
279
+ buf[len] = '\0';
279
280
  pi.json = buf;
280
281
  pi.end = buf + len;
281
282
  if (0 >= (cnt = read(fd, (char*)pi.json, len)) || cnt != (ssize_t)len) {
@@ -6,22 +6,37 @@ module Oj
6
6
  # methods.
7
7
  #
8
8
  # @example
9
- #
9
+ #
10
10
  # require 'oj'
11
11
  #
12
12
  # class MyHandler < ::Oj::ScHandler
13
- # def initialize()
14
- # @hash_cnt = 0
13
+ # def hash_start
14
+ # {}
15
+ # end
16
+ #
17
+ # def hash_set(h,k,v)
18
+ # h[k] = v
19
+ # end
20
+ #
21
+ # def array_start
22
+ # []
23
+ # end
24
+ #
25
+ # def array_append(a,v)
26
+ # a << v
27
+ # end
28
+ #
29
+ # def add_value(v)
30
+ # p v
15
31
  # end
16
32
  #
17
- # def hash_start()
18
- # @hash_cnt += 1
33
+ # def error(message, line, column)
34
+ # p "ERROR: #{message}"
19
35
  # end
20
36
  # end
21
37
  #
22
- # cnt = MyHandler.new()
23
38
  # File.open('any.json', 'r') do |f|
24
- # Oj.sc_parse(cnt, f)
39
+ # Oj.sc_parse(MyHandler.new, f)
25
40
  # end
26
41
  #
27
42
  # To make the desired methods active while parsing the desired method should
@@ -45,37 +60,37 @@ module Oj
45
60
  # When a JSON object element starts the hash_start() callback is called if
46
61
  # public. It should return what ever Ruby Object is to be used as the element
47
62
  # that will later be included in the hash_set() callback.
48
- #
63
+ #
49
64
  # hash_end
50
- #
65
+ #
51
66
  # At the end of a JSON object element the hash_end() callback is called if public.
52
- #
67
+ #
53
68
  # hash_set
54
- #
69
+ #
55
70
  # When a key value pair is encountered during parsing the hash_set() callback
56
71
  # is called if public. The first element will be the object returned from the
57
72
  # enclosing hash_start() callback. The second argument is the key and the last
58
73
  # is the value.
59
- #
74
+ #
60
75
  # array_start
61
- #
76
+ #
62
77
  # When a JSON array element is started the array_start() callback is called if
63
78
  # public. It should return what ever Ruby Object is to be used as the element
64
79
  # that will later be included in the array_append() callback.
65
- #
80
+ #
66
81
  # array_end
67
- #
82
+ #
68
83
  # At the end of a JSON array element the array_end() callback is called if public.
69
- #
84
+ #
70
85
  # array_append
71
- #
86
+ #
72
87
  # When a element is encountered that is an element of an array the
73
88
  # array_append() callback is called if public. The first argument to the
74
89
  # callback is the Ruby object returned from the enclosing array_start()
75
90
  # callback.
76
- #
91
+ #
77
92
  # add_value
78
- #
93
+ #
79
94
  # The handler is expected to handle multiple JSON elements in one stream,
80
95
  # file, or string. When a top level JSON has been read completely the
81
96
  # add_value() callback is called. Even if only one element was ready this
@@ -99,7 +114,7 @@ module Oj
99
114
 
100
115
  def hash_set(h, key, value)
101
116
  end
102
-
117
+
103
118
  def array_start()
104
119
  end
105
120
 
@@ -108,7 +123,7 @@ module Oj
108
123
 
109
124
  def add_value(value)
110
125
  end
111
-
126
+
112
127
  def array_append(a, value)
113
128
  end
114
129
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.9.6'
4
+ VERSION = '2.9.7'
5
5
  end
@@ -7,10 +7,47 @@ $: << File.dirname(__FILE__)
7
7
 
8
8
  require 'helper'
9
9
 
10
- File.open('tst', 'r') do |file|
11
- puts file.gets
12
- puts file.read(1)
13
- Oj.load(file) do |val|
14
- puts "*** inside: #{val}"
10
+ class Handler
11
+ def initialize
12
+ @state = []
13
+ end
14
+
15
+ def hash_start
16
+ @state << {}
17
+ @state.last
15
18
  end
19
+
20
+ def hash_end
21
+ @state.pop
22
+ end
23
+
24
+ def hash_set(h,k,v)
25
+ h.store(k,v)
26
+ end
27
+
28
+ def array_start
29
+ @state << []
30
+ @state.last
31
+ end
32
+
33
+
34
+ def array_end
35
+ @state.pop
36
+ end
37
+
38
+ def array_append(a,v)
39
+ a << v
40
+ end
41
+
42
+ def add_value(v)
43
+ p v
44
+ end
45
+
46
+ def error(message, line, column); p "ERROR: #{message}" end
47
+ end
48
+
49
+ $handler = Handler.new
50
+
51
+ File.open('tst', 'r') do |file|
52
+ Oj.sc_parse($handler, file)
16
53
  end
@@ -98,6 +98,13 @@ class SharedMimicTest < Minitest::Test
98
98
  "children don't match")
99
99
  end
100
100
 
101
+ def test_parse_with_quirks_mode
102
+ json = %{null}
103
+ assert_equal(nil, JSON.parse(json, :quirks_mode => true))
104
+ assert_raises(JSON::ParserError) { JSON.parse(json, :quirks_mode => false) }
105
+ assert_raises(JSON::ParserError) { JSON.parse(json) }
106
+ end
107
+
101
108
  # []
102
109
  def test_bracket_load
103
110
  json = %{{"a":1,"b":[true,false]}}
@@ -1116,6 +1116,11 @@ class Juice < Minitest::Test
1116
1116
  assert_equal(nil, obj)
1117
1117
  end
1118
1118
 
1119
+ def test_quirks_mode
1120
+ assert_raises(Oj::ParseError) { Oj.load("null", :quirks_mode => false) }
1121
+ assert_equal nil, Oj.load("null", :quirks_mode => true)
1122
+ end
1123
+
1119
1124
  def dump_and_load(obj, trace=false)
1120
1125
  json = Oj.dump(obj, :indent => 2)
1121
1126
  puts json if trace
@@ -19,7 +19,7 @@ class OjWriter < Minitest::Test
19
19
  w = Oj::StringWriter.new(:indent => 0)
20
20
  w.push_array()
21
21
  w.pop()
22
- assert_equal('[]', w.to_s)
22
+ assert_equal("[]\n", w.to_s)
23
23
  end
24
24
 
25
25
  def test_string_writer_nested_array
@@ -34,14 +34,14 @@ class OjWriter < Minitest::Test
34
34
  w.push_array()
35
35
  w.pop()
36
36
  w.pop()
37
- assert_equal('[[],[[]],[]]', w.to_s)
37
+ assert_equal("[[],[[]],[]]\n", w.to_s)
38
38
  end
39
39
 
40
40
  def test_string_writer_empty_object
41
41
  w = Oj::StringWriter.new(:indent => 0)
42
42
  w.push_object()
43
43
  w.pop()
44
- assert_equal('{}', w.to_s)
44
+ assert_equal("{}\n", w.to_s)
45
45
  end
46
46
 
47
47
  def test_string_writer_nested_object
@@ -56,7 +56,7 @@ class OjWriter < Minitest::Test
56
56
  w.push_object("a3")
57
57
  w.pop()
58
58
  w.pop()
59
- assert_equal('{"a1":{},"a2":{"b":{}},"a3":{}}', w.to_s)
59
+ assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{}}\n|, w.to_s)
60
60
  end
61
61
 
62
62
  def test_string_writer_nested_key
@@ -76,7 +76,7 @@ class OjWriter < Minitest::Test
76
76
  w.push_value(37)
77
77
  w.pop()
78
78
  w.pop()
79
- assert_equal('{"a1":{},"a2":{"b":{}},"a3":{"a4":37}}', w.to_s)
79
+ assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{"a4":37}}\n|, w.to_s)
80
80
  end
81
81
 
82
82
  def test_string_writer_value_array
@@ -118,7 +118,7 @@ class OjWriter < Minitest::Test
118
118
  w.push_value(3)
119
119
  }
120
120
  }
121
- assert_equal('{"a1":{"a7":7},"a2":["x",3]}', w.to_s)
121
+ assert_equal(%|{"a1":{"a7":7},"a2":["x",3]}\n|, w.to_s)
122
122
  end
123
123
 
124
124
  def test_string_writer_json
@@ -131,7 +131,7 @@ class OjWriter < Minitest::Test
131
131
  w.push_json('{"a":65}', 'x')
132
132
  w.pop()
133
133
  w.pop()
134
- assert_equal('[7,true,"a string",{"x":{"a":65}}]', w.to_s)
134
+ assert_equal(%|[7,true,"a string",{"x":{"a":65}}]\n|, w.to_s)
135
135
  end
136
136
 
137
137
  def test_string_writer_pop_excess
@@ -206,7 +206,7 @@ class OjWriter < Minitest::Test
206
206
  w.push_value(3)
207
207
  w.push_array()
208
208
  w.pop_all()
209
- assert_equal('{"a1":{},"a2":[3,[]]}', w.to_s)
209
+ assert_equal(%|{"a1":{},"a2":[3,[]]}\n|, w.to_s)
210
210
  end
211
211
 
212
212
  def test_string_writer_reset
@@ -224,7 +224,7 @@ class OjWriter < Minitest::Test
224
224
  w = Oj::StreamWriter.new(output, :indent => 0)
225
225
  w.push_array()
226
226
  w.pop()
227
- assert_equal('[]', output.string())
227
+ assert_equal("[]\n", output.string())
228
228
  end
229
229
 
230
230
  def test_stream_writer_mixed_stringio
@@ -243,7 +243,7 @@ class OjWriter < Minitest::Test
243
243
  w.push_object("a3")
244
244
  w.pop()
245
245
  w.pop()
246
- assert_equal('{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}', output.string())
246
+ assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
247
247
  end
248
248
 
249
249
  def test_stream_writer_mixed_file
@@ -265,7 +265,7 @@ class OjWriter < Minitest::Test
265
265
  w.pop()
266
266
  end
267
267
  content = File.read(filename)
268
- assert_equal('{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}', content)
268
+ assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, content)
269
269
  end
270
270
 
271
271
  def test_stream_writer_nested_key_object
@@ -286,7 +286,7 @@ class OjWriter < Minitest::Test
286
286
  w.push_value(37)
287
287
  w.pop()
288
288
  w.pop()
289
- assert_equal('{"a1":{},"a2":{"b":{}},"a3":{"a4":37}}', output.string())
289
+ assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{"a4":37}}\n|, output.string())
290
290
  end
291
291
 
292
292
  end # OjWriter
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: 2.9.6
4
+ version: 2.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-15 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler