json-jruby 1.2.3-universal-java-1.6 → 1.2.4-universal-java-1.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/json/common.rb CHANGED
@@ -33,12 +33,16 @@ module JSON
33
33
  # level (absolute namespace path?). If there doesn't exist a constant at
34
34
  # the given path, an ArgumentError is raised.
35
35
  def deep_const_get(path) # :nodoc:
36
- path = path.to_s
37
- path.split(/::/).inject(Object) do |p, c|
36
+ path.to_s.split(/::/).inject(Object) do |p, c|
38
37
  case
39
38
  when c.empty? then p
40
39
  when p.const_defined?(c) then p.const_get(c)
41
- else raise ArgumentError, "can't find const #{path}"
40
+ else
41
+ begin
42
+ p.const_missing(c)
43
+ rescue NameError
44
+ raise ArgumentError, "can't find const #{path}"
45
+ end
42
46
  end
43
47
  end
44
48
  end
Binary file
Binary file
data/lib/json/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.2.3'
3
+ VERSION = '1.2.4'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 2
8
- - 3
9
- version: 1.2.3
8
+ - 4
9
+ version: 1.2.4
10
10
  platform: universal-java-1.6
11
11
  authors:
12
12
  - Daniel Luz
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-14 00:00:00 -03:00
17
+ date: 2010-04-08 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -28,58 +28,55 @@ extra_rdoc_files: []
28
28
 
29
29
  files:
30
30
  - lib/json.rb
31
- - lib/json/version.rb
31
+ - lib/json/common.rb
32
32
  - lib/json/ext.rb
33
33
  - lib/json/pure.rb
34
- - lib/json/common.rb
35
- - lib/json/version.rb.orig
36
- - lib/json/add/rails.rb
34
+ - lib/json/version.rb
37
35
  - lib/json/add/core.rb
36
+ - lib/json/add/rails.rb
38
37
  - lib/json/ext/generator.jar
39
38
  - lib/json/ext/parser.jar
40
- - lib/json/pure/generator.rb.orig
41
39
  - lib/json/pure/generator.rb
42
40
  - lib/json/pure/parser.rb
43
- - tests/test_json_generate.rb
44
- - tests/test_json_unicode.rb
45
41
  - tests/test_jjrb_offsets.rb
46
- - tests/test_json_generate.rb.orig
42
+ - tests/test_json.rb
47
43
  - tests/test_json_addition.rb
48
- - tests/test_json_fixtures.rb
49
44
  - tests/test_json_encoding.rb
45
+ - tests/test_json_fixtures.rb
46
+ - tests/test_json_generate.rb
50
47
  - tests/test_json_rails.rb
51
- - tests/test_json.rb
52
- - tests/fixtures/fail20.json
53
- - tests/fixtures/fail6.json
48
+ - tests/test_json_unicode.rb
54
49
  - tests/fixtures/fail1.json
55
- - tests/fixtures/fail14.json
56
- - tests/fixtures/fail9.json
57
- - tests/fixtures/pass26.json
58
- - tests/fixtures/fail27.json
59
- - tests/fixtures/fail19.json
60
- - tests/fixtures/fail5.json
61
50
  - tests/fixtures/fail10.json
51
+ - tests/fixtures/fail11.json
62
52
  - tests/fixtures/fail12.json
63
- - tests/fixtures/fail3.json
64
53
  - tests/fixtures/fail13.json
65
- - tests/fixtures/fail24.json
66
- - tests/fixtures/pass3.json
67
- - tests/fixtures/fail23.json
68
- - tests/fixtures/fail7.json
69
- - tests/fixtures/pass1.json
54
+ - tests/fixtures/fail14.json
70
55
  - tests/fixtures/fail18.json
71
- - tests/fixtures/pass17.json
72
- - tests/fixtures/fail11.json
56
+ - tests/fixtures/fail19.json
57
+ - tests/fixtures/fail2.json
58
+ - tests/fixtures/fail20.json
73
59
  - tests/fixtures/fail21.json
60
+ - tests/fixtures/fail22.json
61
+ - tests/fixtures/fail23.json
62
+ - tests/fixtures/fail24.json
74
63
  - tests/fixtures/fail25.json
64
+ - tests/fixtures/fail27.json
65
+ - tests/fixtures/fail28.json
66
+ - tests/fixtures/fail3.json
75
67
  - tests/fixtures/fail4.json
68
+ - tests/fixtures/fail5.json
69
+ - tests/fixtures/fail6.json
70
+ - tests/fixtures/fail7.json
76
71
  - tests/fixtures/fail8.json
77
- - tests/fixtures/fail2.json
72
+ - tests/fixtures/fail9.json
73
+ - tests/fixtures/pass1.json
78
74
  - tests/fixtures/pass15.json
79
- - tests/fixtures/fail22.json
80
- - tests/fixtures/fail28.json
81
- - tests/fixtures/pass2.json
82
75
  - tests/fixtures/pass16.json
76
+ - tests/fixtures/pass17.json
77
+ - tests/fixtures/pass2.json
78
+ - tests/fixtures/pass26.json
79
+ - tests/fixtures/pass3.json
83
80
  has_rdoc: true
84
81
  homepage: http://rubyforge.org/projects/json-jruby/
85
82
  licenses: []
@@ -1,456 +0,0 @@
1
- module JSON
2
- MAP = {
3
- "\x0" => '\u0000',
4
- "\x1" => '\u0001',
5
- "\x2" => '\u0002',
6
- "\x3" => '\u0003',
7
- "\x4" => '\u0004',
8
- "\x5" => '\u0005',
9
- "\x6" => '\u0006',
10
- "\x7" => '\u0007',
11
- "\b" => '\b',
12
- "\t" => '\t',
13
- "\n" => '\n',
14
- "\xb" => '\u000b',
15
- "\f" => '\f',
16
- "\r" => '\r',
17
- "\xe" => '\u000e',
18
- "\xf" => '\u000f',
19
- "\x10" => '\u0010',
20
- "\x11" => '\u0011',
21
- "\x12" => '\u0012',
22
- "\x13" => '\u0013',
23
- "\x14" => '\u0014',
24
- "\x15" => '\u0015',
25
- "\x16" => '\u0016',
26
- "\x17" => '\u0017',
27
- "\x18" => '\u0018',
28
- "\x19" => '\u0019',
29
- "\x1a" => '\u001a',
30
- "\x1b" => '\u001b',
31
- "\x1c" => '\u001c',
32
- "\x1d" => '\u001d',
33
- "\x1e" => '\u001e',
34
- "\x1f" => '\u001f',
35
- '"' => '\"',
36
- '\\' => '\\\\',
37
- } # :nodoc:
38
-
39
- # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
40
- # UTF16 big endian characters as \u????, and return it.
41
- if defined?(::Encoding)
42
- def utf8_to_json(string) # :nodoc:
43
- string = string.dup
44
- string << '' # XXX workaround: avoid buffer sharing
45
- string.force_encoding(::Encoding::ASCII_8BIT)
46
- string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
47
- string.force_encoding(::Encoding::UTF_8)
48
- string
49
- end
50
-
51
- def utf8_to_json_ascii(string) # :nodoc:
52
- string = string.dup
53
- string << '' # XXX workaround: avoid buffer sharing
54
- string.force_encoding(::Encoding::ASCII_8BIT)
55
- string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
56
- string.gsub!(/(
57
- (?:
58
- [\xc2-\xdf][\x80-\xbf] |
59
- [\xe0-\xef][\x80-\xbf]{2} |
60
- [\xf0-\xf4][\x80-\xbf]{3}
61
- )+ |
62
- [\x80-\xc1\xf5-\xff] # invalid
63
- )/nx) { |c|
64
- c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
65
- s = JSON::UTF8toUTF16.iconv(c).unpack('H*')[0]
66
- s.gsub!(/.{4}/n, '\\\\u\&')
67
- }
68
- string.force_encoding(::Encoding::UTF_8)
69
- string
70
- rescue Iconv::Failure => e
71
- raise GeneratorError, "Caught #{e.class}: #{e}"
72
- end
73
- else
74
- def utf8_to_json(string) # :nodoc:
75
- string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
76
- end
77
-
78
- def utf8_to_json_ascii(string) # :nodoc:
79
- string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
80
- string.gsub!(/(
81
- (?:
82
- [\xc2-\xdf][\x80-\xbf] |
83
- [\xe0-\xef][\x80-\xbf]{2} |
84
- [\xf0-\xf4][\x80-\xbf]{3}
85
- )+ |
86
- [\x80-\xc1\xf5-\xff] # invalid
87
- )/nx) { |c|
88
- c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
89
- s = JSON::UTF8toUTF16.iconv(c).unpack('H*')[0]
90
- s.gsub!(/.{4}/n, '\\\\u\&')
91
- }
92
- string
93
- rescue Iconv::Failure => e
94
- raise GeneratorError, "Caught #{e.class}: #{e}"
95
- end
96
- end
97
- module_function :utf8_to_json, :utf8_to_json_ascii
98
-
99
- module Pure
100
- module Generator
101
- # This class is used to create State instances, that are use to hold data
102
- # while generating a JSON text from a a Ruby data structure.
103
- class State
104
- # Creates a State object from _opts_, which ought to be Hash to create
105
- # a new State instance configured by _opts_, something else to create
106
- # an unconfigured instance. If _opts_ is a State object, it is just
107
- # returned.
108
- def self.from_state(opts)
109
- case opts
110
- when self
111
- opts
112
- when Hash
113
- new(opts)
114
- else
115
- SAFE_STATE_PROTOTYPE
116
- end
117
- end
118
-
119
- # Instantiates a new State object, configured by _opts_.
120
- #
121
- # _opts_ can have the following keys:
122
- #
123
- # * *indent*: a string used to indent levels (default: ''),
124
- # * *space*: a string that is put after, a : or , delimiter (default: ''),
125
- # * *space_before*: a string that is put before a : pair delimiter (default: ''),
126
- # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
127
- # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
128
- # * *check_circular*: is deprecated now, use the :max_nesting option instead,
129
- # * *max_nesting*: sets the maximum level of data structure nesting in
130
- # the generated JSON, max_nesting = 0 if no maximum should be checked.
131
- # * *allow_nan*: true if NaN, Infinity, and -Infinity should be
132
- # generated, otherwise an exception is thrown, if these values are
133
- # encountered. This options defaults to false.
134
- def initialize(opts = {})
135
- @indent = ''
136
- @space = ''
137
- @space_before = ''
138
- @object_nl = ''
139
- @array_nl = ''
140
- @allow_nan = false
141
- @ascii_only = false
142
- configure opts
143
- end
144
-
145
- # This string is used to indent levels in the JSON text.
146
- attr_accessor :indent
147
-
148
- # This string is used to insert a space between the tokens in a JSON
149
- # string.
150
- attr_accessor :space
151
-
152
- # This string is used to insert a space before the ':' in JSON objects.
153
- attr_accessor :space_before
154
-
155
- # This string is put at the end of a line that holds a JSON object (or
156
- # Hash).
157
- attr_accessor :object_nl
158
-
159
- # This string is put at the end of a line that holds a JSON array.
160
- attr_accessor :array_nl
161
-
162
- # This integer returns the maximum level of data structure nesting in
163
- # the generated JSON, max_nesting = 0 if no maximum is checked.
164
- attr_accessor :max_nesting
165
-
166
- def check_max_nesting(depth) # :nodoc:
167
- return if @max_nesting.zero?
168
- current_nesting = depth + 1
169
- current_nesting > @max_nesting and
170
- raise NestingError, "nesting of #{current_nesting} is too deep"
171
- end
172
-
173
- # Returns true, if circular data structures are checked,
174
- # otherwise returns false.
175
- def check_circular?
176
- !!@max_nesting.zero?
177
- end
178
-
179
- # Returns true if NaN, Infinity, and -Infinity should be considered as
180
- # valid JSON and output.
181
- def allow_nan?
182
- @allow_nan
183
- end
184
-
185
- def ascii_only?
186
- @ascii_only
187
- end
188
-
189
- # Configure this State instance with the Hash _opts_, and return
190
- # itself.
191
- def configure(opts)
192
- @indent = opts[:indent] if opts.key?(:indent)
193
- @space = opts[:space] if opts.key?(:space)
194
- @space_before = opts[:space_before] if opts.key?(:space_before)
195
- @object_nl = opts[:object_nl] if opts.key?(:object_nl)
196
- @array_nl = opts[:array_nl] if opts.key?(:array_nl)
197
- @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
198
- @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
199
- if !opts.key?(:max_nesting) # defaults to 19
200
- @max_nesting = 19
201
- elsif opts[:max_nesting]
202
- @max_nesting = opts[:max_nesting]
203
- else
204
- @max_nesting = 0
205
- end
206
- self
207
- end
208
-
209
- # Returns the configuration instance variables as a hash, that can be
210
- # passed to the configure method.
211
- def to_h
212
- result = {}
213
- for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting]
214
- result[iv.intern] = instance_variable_get("@#{iv}")
215
- end
216
- result
217
- end
218
- <<<<<<< HEAD:lib/json/pure/generator.rb
219
-
220
- # Generates a valid JSON document from object +obj+ and returns the
221
- # result. If no valid JSON document can be created this method raises a
222
- # GeneratorError exception.
223
- def generate(obj)
224
- result = obj.to_json(self)
225
- if result !~ /\A\s*(?:\[.*\]|\{.*\})\s*\Z/m
226
- raise GeneratorError, "only generation of JSON objects or arrays allowed"
227
- end
228
- result
229
- end
230
- |||||||
231
- =======
232
-
233
- # Return the value returned by method +name+.
234
- def [](name)
235
- __send__ name
236
- end
237
- >>>>>>> v1.2:lib/json/pure/generator.rb
238
- end
239
-
240
- module GeneratorMethods
241
- module Object
242
- # Converts this object to a string (calling #to_s), converts
243
- # it to a JSON string, and returns the result. This is a fallback, if no
244
- # special method #to_json was defined for some object.
245
- def to_json(*) to_s.to_json end
246
- end
247
-
248
- module Hash
249
- # Returns a JSON string containing a JSON object, that is unparsed from
250
- # this Hash instance.
251
- # _state_ is a JSON::State object, that can also be used to configure the
252
- # produced JSON string output further.
253
- # _depth_ is used to find out nesting depth, to indent accordingly.
254
- def to_json(state = nil, depth = 0, *)
255
- if state
256
- state = State.from_state(state)
257
- state.check_max_nesting(depth)
258
- end
259
- json_transform(state, depth)
260
- end
261
-
262
- private
263
-
264
- def json_shift(state, depth)
265
- state and not state.object_nl.empty? or return ''
266
- state.indent * depth
267
- end
268
-
269
- def json_transform(state, depth)
270
- delim = ','
271
- if state
272
- delim << state.object_nl
273
- result = '{'
274
- result << state.object_nl
275
- depth += 1
276
- first = true
277
- indent = state && !state.object_nl.empty?
278
- each { |key,value|
279
- result << delim unless first
280
- result << state.indent * depth if indent
281
- result << key.to_s.to_json(state, depth)
282
- result << state.space_before
283
- result << ':'
284
- result << state.space
285
- result << value.to_json(state, depth)
286
- first = false
287
- }
288
- depth -= 1
289
- result << state.object_nl
290
- result << state.indent * depth if indent if indent
291
- result << '}'
292
- else
293
- result = '{'
294
- result << map { |key,value|
295
- key.to_s.to_json << ':' << value.to_json
296
- }.join(delim)
297
- result << '}'
298
- end
299
- result
300
- end
301
- end
302
-
303
- module Array
304
- # Returns a JSON string containing a JSON array, that is unparsed from
305
- # this Array instance.
306
- # _state_ is a JSON::State object, that can also be used to configure the
307
- # produced JSON string output further.
308
- # _depth_ is used to find out nesting depth, to indent accordingly.
309
- def to_json(state = nil, depth = 0, *)
310
- if state
311
- state = State.from_state(state)
312
- state.check_max_nesting(depth)
313
- end
314
- json_transform(state, depth)
315
- end
316
-
317
- private
318
-
319
- def json_transform(state, depth)
320
- delim = ','
321
- if state
322
- delim << state.array_nl
323
- result = '['
324
- result << state.array_nl
325
- depth += 1
326
- first = true
327
- indent = state && !state.array_nl.empty?
328
- each { |value|
329
- result << delim unless first
330
- result << state.indent * depth if indent
331
- result << value.to_json(state, depth)
332
- first = false
333
- }
334
- depth -= 1
335
- result << state.array_nl
336
- result << state.indent * depth if indent
337
- result << ']'
338
- else
339
- '[' << map { |value| value.to_json }.join(delim) << ']'
340
- end
341
- end
342
- end
343
-
344
- module Integer
345
- # Returns a JSON string representation for this Integer number.
346
- def to_json(*) to_s end
347
- end
348
-
349
- module Float
350
- # Returns a JSON string representation for this Float number.
351
- def to_json(state = nil, *)
352
- case
353
- when infinite?
354
- if state && state.allow_nan?
355
- to_s
356
- else
357
- raise GeneratorError, "#{self} not allowed in JSON"
358
- end
359
- when nan?
360
- if state && state.allow_nan?
361
- to_s
362
- else
363
- raise GeneratorError, "#{self} not allowed in JSON"
364
- end
365
- else
366
- to_s
367
- end
368
- end
369
- end
370
-
371
- module String
372
- if defined?(::Encoding)
373
- # This string should be encoded with UTF-8 A call to this method
374
- # returns a JSON string encoded with UTF16 big endian characters as
375
- # \u????.
376
- def to_json(*args)
377
- state, = *args
378
- state ||= State.from_state(state)
379
- if encoding == ::Encoding::UTF_8
380
- string = self
381
- else
382
- string = encode(::Encoding::UTF_8)
383
- end
384
- if state.ascii_only?
385
- '"' << JSON.utf8_to_json_ascii(string) << '"'
386
- else
387
- '"' << JSON.utf8_to_json(string) << '"'
388
- end
389
- end
390
- else
391
- # This string should be encoded with UTF-8 A call to this method
392
- # returns a JSON string encoded with UTF16 big endian characters as
393
- # \u????.
394
- def to_json(*args)
395
- state, = *args
396
- state ||= State.from_state(state)
397
- if state.ascii_only?
398
- '"' << JSON.utf8_to_json_ascii(self) << '"'
399
- else
400
- '"' << JSON.utf8_to_json(self) << '"'
401
- end
402
- end
403
- end
404
-
405
- # Module that holds the extinding methods if, the String module is
406
- # included.
407
- module Extend
408
- # Raw Strings are JSON Objects (the raw bytes are stored in an
409
- # array for the key "raw"). The Ruby String can be created by this
410
- # module method.
411
- def json_create(o)
412
- o['raw'].pack('C*')
413
- end
414
- end
415
-
416
- # Extends _modul_ with the String::Extend module.
417
- def self.included(modul)
418
- modul.extend Extend
419
- end
420
-
421
- # This method creates a raw object hash, that can be nested into
422
- # other data structures and will be unparsed as a raw string. This
423
- # method should be used, if you want to convert raw strings to JSON
424
- # instead of UTF-8 strings, e. g. binary data.
425
- def to_json_raw_object
426
- {
427
- JSON.create_id => self.class.name,
428
- 'raw' => self.unpack('C*'),
429
- }
430
- end
431
-
432
- # This method creates a JSON text from the result of
433
- # a call to to_json_raw_object of this String.
434
- def to_json_raw(*args)
435
- to_json_raw_object.to_json(*args)
436
- end
437
- end
438
-
439
- module TrueClass
440
- # Returns a JSON string for true: 'true'.
441
- def to_json(*) 'true' end
442
- end
443
-
444
- module FalseClass
445
- # Returns a JSON string for false: 'false'.
446
- def to_json(*) 'false' end
447
- end
448
-
449
- module NilClass
450
- # Returns a JSON string for nil: 'null'.
451
- def to_json(*) 'null' end
452
- end
453
- end
454
- end
455
- end
456
- end
@@ -1,14 +0,0 @@
1
- module JSON
2
- # JSON version
3
- <<<<<<< HEAD:lib/json/version.rb
4
- VERSION = '2.0.0'
5
- |||||||
6
- VERSION = '1.2.2'
7
- =======
8
- VERSION = '1.2.3'
9
- >>>>>>> v1.2:lib/json/version.rb
10
- VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
11
- VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
12
- VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
13
- VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
14
- end
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
-
4
- require 'test/unit'
5
- case ENV['JSON']
6
- when 'pure' then require 'json/pure'
7
- when 'ext' then require 'json/ext'
8
- else require 'json'
9
- end
10
-
11
- class TC_JSONGenerate < Test::Unit::TestCase
12
- include JSON
13
-
14
- def setup
15
- @hash = {
16
- 'a' => 2,
17
- 'b' => 3.141,
18
- 'c' => 'c',
19
- 'd' => [ 1, "b", 3.14 ],
20
- 'e' => { 'foo' => 'bar' },
21
- 'g' => "\"\0\037",
22
- 'h' => 1000.0,
23
- 'i' => 0.001
24
- }
25
- @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
26
- '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
27
- @json3 = <<'EOT'.chomp
28
- {
29
- "a": 2,
30
- "b": 3.141,
31
- "c": "c",
32
- "d": [
33
- 1,
34
- "b",
35
- 3.14
36
- ],
37
- "e": {
38
- "foo": "bar"
39
- },
40
- "g": "\"\u0000\u001f",
41
- "h": 1000.0,
42
- "i": 0.001
43
- }
44
- EOT
45
- end
46
-
47
- def test_generate
48
- json = generate(@hash)
49
- assert_equal(JSON.parse(@json2), JSON.parse(json))
50
- parsed_json = parse(json)
51
- assert_equal(@hash, parsed_json)
52
- json = generate({1=>2})
53
- assert_equal('{"1":2}', json)
54
- parsed_json = parse(json)
55
- assert_equal({"1"=>2}, parsed_json)
56
- assert_raise(GeneratorError) { generate(666) }
57
- end
58
-
59
- def test_generate_pretty
60
- json = pretty_generate(@hash)
61
- assert_equal(JSON.parse(@json3), JSON.parse(json))
62
- parsed_json = parse(json)
63
- assert_equal(@hash, parsed_json)
64
- json = pretty_generate({1=>2})
65
- assert_equal(<<'EOT'.chomp, json)
66
- {
67
- "1": 2
68
- }
69
- EOT
70
- parsed_json = parse(json)
71
- assert_equal({"1"=>2}, parsed_json)
72
- assert_raise(GeneratorError) { pretty_generate(666) }
73
- end
74
-
75
- def test_fast_generate
76
- json = fast_generate(@hash)
77
- assert_equal(JSON.parse(@json2), JSON.parse(json))
78
- parsed_json = parse(json)
79
- assert_equal(@hash, parsed_json)
80
- json = fast_generate({1=>2})
81
- assert_equal('{"1":2}', json)
82
- parsed_json = parse(json)
83
- assert_equal({"1"=>2}, parsed_json)
84
- assert_raise(GeneratorError) { fast_generate(666) }
85
- end
86
-
87
- def test_states
88
- json = generate({1=>2}, nil)
89
- assert_equal('{"1":2}', json)
90
- <<<<<<< HEAD:tests/test_json_generate.rb
91
- s = JSON.state.new
92
- |||||||
93
- s = JSON.state.new(:check_circular => true)
94
- #assert s.check_circular
95
- =======
96
- s = JSON.state.new(:check_circular => true)
97
- assert s.check_circular?
98
- assert s[:check_circular?]
99
- >>>>>>> v1.2:tests/test_json_generate.rb
100
- h = { 1=>2 }
101
- h[3] = h
102
- <<<<<<< HEAD:tests/test_json_generate.rb
103
- assert_raises(JSON::NestingError) { generate(h) }
104
- assert_raises(JSON::NestingError) { generate(h, s) }
105
- s = JSON.state.new
106
- |||||||
107
- assert_raises(JSON::CircularDatastructure) { generate(h) }
108
- assert_raises(JSON::CircularDatastructure) { generate(h, s) }
109
- s = JSON.state.new(:check_circular => true)
110
- #assert s.check_circular
111
- =======
112
- assert_raises(JSON::CircularDatastructure) { generate(h) }
113
- assert_raises(JSON::CircularDatastructure) { generate(h, s) }
114
- s = JSON.state.new(:check_circular => true)
115
- assert s.check_circular?
116
- assert s[:check_circular?]
117
- >>>>>>> v1.2:tests/test_json_generate.rb
118
- a = [ 1, 2 ]
119
- a << a
120
- assert_raises(JSON::NestingError) { generate(a, s) }
121
- end
122
-
123
- def test_allow_nan
124
- assert_raises(GeneratorError) { generate([JSON::NaN]) }
125
- assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
126
- assert_raises(GeneratorError) { fast_generate([JSON::NaN]) }
127
- assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) }
128
- assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
129
- assert_raises(GeneratorError) { generate([JSON::Infinity]) }
130
- assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
131
- assert_raises(GeneratorError) { fast_generate([JSON::Infinity]) }
132
- assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) }
133
- assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
134
- assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) }
135
- assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
136
- assert_raises(GeneratorError) { fast_generate([JSON::MinusInfinity]) }
137
- assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
138
- assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
139
- end
140
- end