json-jruby 1.1.2-universal-java-1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/lib/json.rb +235 -0
  2. data/lib/json/add/core.rb +127 -0
  3. data/lib/json/add/rails.rb +58 -0
  4. data/lib/json/common.rb +354 -0
  5. data/lib/json/ext.rb +13 -0
  6. data/lib/json/ext/generator.jar +0 -0
  7. data/lib/json/ext/parser.jar +0 -0
  8. data/lib/json/pure.rb +75 -0
  9. data/lib/json/pure/generator.rb +394 -0
  10. data/lib/json/pure/parser.rb +259 -0
  11. data/lib/json/version.rb +9 -0
  12. data/tests/fixtures/fail1.json +1 -0
  13. data/tests/fixtures/fail10.json +1 -0
  14. data/tests/fixtures/fail11.json +1 -0
  15. data/tests/fixtures/fail12.json +1 -0
  16. data/tests/fixtures/fail13.json +1 -0
  17. data/tests/fixtures/fail14.json +1 -0
  18. data/tests/fixtures/fail18.json +1 -0
  19. data/tests/fixtures/fail19.json +1 -0
  20. data/tests/fixtures/fail2.json +1 -0
  21. data/tests/fixtures/fail20.json +1 -0
  22. data/tests/fixtures/fail21.json +1 -0
  23. data/tests/fixtures/fail22.json +1 -0
  24. data/tests/fixtures/fail23.json +1 -0
  25. data/tests/fixtures/fail24.json +1 -0
  26. data/tests/fixtures/fail25.json +1 -0
  27. data/tests/fixtures/fail27.json +2 -0
  28. data/tests/fixtures/fail28.json +2 -0
  29. data/tests/fixtures/fail3.json +1 -0
  30. data/tests/fixtures/fail4.json +1 -0
  31. data/tests/fixtures/fail5.json +1 -0
  32. data/tests/fixtures/fail6.json +1 -0
  33. data/tests/fixtures/fail7.json +1 -0
  34. data/tests/fixtures/fail8.json +1 -0
  35. data/tests/fixtures/fail9.json +1 -0
  36. data/tests/fixtures/pass1.json +56 -0
  37. data/tests/fixtures/pass15.json +1 -0
  38. data/tests/fixtures/pass16.json +1 -0
  39. data/tests/fixtures/pass17.json +1 -0
  40. data/tests/fixtures/pass2.json +1 -0
  41. data/tests/fixtures/pass26.json +1 -0
  42. data/tests/fixtures/pass3.json +6 -0
  43. data/tests/runner.rb +26 -0
  44. data/tests/test_json.rb +294 -0
  45. data/tests/test_json_addition.rb +144 -0
  46. data/tests/test_json_fixtures.rb +30 -0
  47. data/tests/test_json_generate.rb +100 -0
  48. data/tests/test_json_rails.rb +114 -0
  49. data/tests/test_json_unicode.rb +61 -0
  50. metadata +99 -0
@@ -0,0 +1,100 @@
1
+ require 'test/unit'
2
+ require 'json'
3
+
4
+ class TC_JSONGenerate < Test::Unit::TestCase
5
+ include JSON
6
+
7
+ def setup
8
+ $KCODE = 'UTF8'
9
+ @hash = {
10
+ 'a' => 2,
11
+ 'b' => 3.141,
12
+ 'c' => 'c',
13
+ 'd' => [ 1, "b", 3.14 ],
14
+ 'e' => { 'foo' => 'bar' },
15
+ 'g' => "\"\0\037",
16
+ 'h' => 1000.0,
17
+ 'i' => 0.001
18
+ }
19
+ @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
20
+ '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
21
+ @json3 = <<'EOT'.chomp
22
+ {
23
+ "a": 2,
24
+ "b": 3.141,
25
+ "c": "c",
26
+ "d": [
27
+ 1,
28
+ "b",
29
+ 3.14
30
+ ],
31
+ "e": {
32
+ "foo": "bar"
33
+ },
34
+ "g": "\"\u0000\u001f",
35
+ "h": 1000.0,
36
+ "i": 0.001
37
+ }
38
+ EOT
39
+ end
40
+
41
+ def test_unparse
42
+ json = unparse(@hash)
43
+ assert_equal(JSON.parse(@json2), JSON.parse(json))
44
+ parsed_json = parse(json)
45
+ assert_equal(@hash, parsed_json)
46
+ json = generate({1=>2})
47
+ assert_equal('{"1":2}', json)
48
+ parsed_json = parse(json)
49
+ assert_equal({"1"=>2}, parsed_json)
50
+ end
51
+
52
+ def test_unparse_pretty
53
+ json = pretty_unparse(@hash)
54
+ assert_equal(JSON.parse(@json3), JSON.parse(json))
55
+ parsed_json = parse(json)
56
+ assert_equal(@hash, parsed_json)
57
+ json = pretty_generate({1=>2})
58
+ assert_equal(<<'EOT'.chomp, json)
59
+ {
60
+ "1": 2
61
+ }
62
+ EOT
63
+ parsed_json = parse(json)
64
+ assert_equal({"1"=>2}, parsed_json)
65
+ end
66
+
67
+ def test_states
68
+ json = generate({1=>2}, nil)
69
+ assert_equal('{"1":2}', json)
70
+ s = JSON.state.new(:check_circular => true)
71
+ #assert s.check_circular
72
+ h = { 1=>2 }
73
+ h[3] = h
74
+ assert_raises(JSON::CircularDatastructure) { generate(h) }
75
+ assert_raises(JSON::CircularDatastructure) { generate(h, s) }
76
+ s = JSON.state.new(:check_circular => true)
77
+ #assert s.check_circular
78
+ a = [ 1, 2 ]
79
+ a << a
80
+ assert_raises(JSON::CircularDatastructure) { generate(a, s) }
81
+ end
82
+
83
+ def test_allow_nan
84
+ assert_raises(GeneratorError) { generate([JSON::NaN]) }
85
+ assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
86
+ assert_equal '[NaN]', fast_generate([JSON::NaN])
87
+ assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) }
88
+ assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
89
+ assert_raises(GeneratorError) { generate([JSON::Infinity]) }
90
+ assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
91
+ assert_equal '[Infinity]', fast_generate([JSON::Infinity])
92
+ assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) }
93
+ assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
94
+ assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) }
95
+ assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
96
+ assert_equal '[-Infinity]', fast_generate([JSON::MinusInfinity])
97
+ assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
98
+ assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
99
+ end
100
+ end
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'json/add/rails'
5
+ require 'date'
6
+
7
+ class TC_JSONRails < Test::Unit::TestCase
8
+ include JSON
9
+
10
+ class A
11
+ def initialize(a)
12
+ @a = a
13
+ end
14
+
15
+ attr_reader :a
16
+
17
+ def ==(other)
18
+ a == other.a
19
+ end
20
+
21
+ def self.json_create(object)
22
+ new(*object['args'])
23
+ end
24
+
25
+ def to_json(*args)
26
+ {
27
+ 'json_class' => self.class.name,
28
+ 'args' => [ @a ],
29
+ }.to_json(*args)
30
+ end
31
+ end
32
+
33
+ class B
34
+ def to_json(*args)
35
+ {
36
+ 'json_class' => self.class.name,
37
+ }.to_json(*args)
38
+ end
39
+ end
40
+
41
+ class C
42
+ def to_json(*args)
43
+ {
44
+ 'json_class' => 'TC_JSONRails::Nix',
45
+ }.to_json(*args)
46
+ end
47
+ end
48
+
49
+ def setup
50
+ $KCODE = 'UTF8'
51
+ end
52
+
53
+ def test_extended_json
54
+ a = A.new(666)
55
+ assert A.json_creatable?
56
+ json = generate(a)
57
+ a_again = JSON.parse(json)
58
+ assert_kind_of a.class, a_again
59
+ assert_equal a, a_again
60
+ end
61
+
62
+ def test_extended_json_disabled
63
+ a = A.new(666)
64
+ assert A.json_creatable?
65
+ json = generate(a)
66
+ a_again = JSON.parse(json, :create_additions => true)
67
+ assert_kind_of a.class, a_again
68
+ assert_equal a, a_again
69
+ a_hash = JSON.parse(json, :create_additions => false)
70
+ assert_kind_of Hash, a_hash
71
+ assert_equal(
72
+ {"args"=>[666], "json_class"=>"TC_JSONRails::A"}.sort_by { |k,| k },
73
+ a_hash.sort_by { |k,| k }
74
+ )
75
+ end
76
+
77
+ def test_extended_json_fail
78
+ b = B.new
79
+ assert !B.json_creatable?
80
+ json = generate(b)
81
+ assert_equal({ 'json_class' => B.name }, JSON.parse(json))
82
+ end
83
+
84
+ def test_extended_json_fail
85
+ c = C.new # with rails addition all objects are theoretically creatable
86
+ assert C.json_creatable?
87
+ json = generate(c)
88
+ assert_raises(ArgumentError) { JSON.parse(json) }
89
+ end
90
+
91
+ def test_raw_strings
92
+ raw = ''
93
+ raw_array = []
94
+ for i in 0..255
95
+ raw << i
96
+ raw_array << i
97
+ end
98
+ json = raw.to_json_raw
99
+ json_raw_object = raw.to_json_raw_object
100
+ hash = { 'json_class' => 'String', 'raw'=> raw_array }
101
+ assert_equal hash, json_raw_object
102
+ json_raw = <<EOT.chomp
103
+ {\"json_class\":\"String\",\"raw\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,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,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255]}
104
+ EOT
105
+ # "
106
+ assert_equal json_raw, json
107
+ raw_again = JSON.parse(json)
108
+ assert_equal raw, raw_again
109
+ end
110
+
111
+ def test_symbol
112
+ assert_equal '"foo"', JSON(:foo) # we don't want an object here
113
+ end
114
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'json'
5
+
6
+ class TC_JSONUnicode < Test::Unit::TestCase
7
+ include JSON
8
+
9
+ def setup
10
+ $KCODE = 'UTF8'
11
+ end
12
+
13
+ def test_unicode
14
+ assert_equal '""', ''.to_json
15
+ assert_equal '"\\b"', "\b".to_json
16
+ assert_equal '"\u0001"', 0x1.chr.to_json
17
+ assert_equal '"\u001f"', 0x1f.chr.to_json
18
+ assert_equal '" "', ' '.to_json
19
+ assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
20
+ utf8 = [ "© ≠ €! \01" ]
21
+ json = '["\u00a9 \u2260 \u20ac! \u0001"]'
22
+ assert_equal json, utf8.to_json
23
+ assert_equal utf8, parse(json)
24
+ utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
25
+ json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
26
+ assert_equal json, utf8.to_json
27
+ assert_equal utf8, parse(json)
28
+ utf8 = ['საქართველო']
29
+ json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
30
+ assert_equal json, utf8.to_json
31
+ assert_equal utf8, parse(json)
32
+ assert_equal '["\\u00c3"]', JSON.generate(["Ã"])
33
+ assert_equal ["€"], JSON.parse('["\u20ac"]')
34
+ utf8 = ["\xf0\xa0\x80\x81"]
35
+ json = '["\ud840\udc01"]'
36
+ assert_equal json, JSON.generate(utf8)
37
+ assert_equal utf8, JSON.parse(json)
38
+ end
39
+
40
+ def test_chars
41
+ (0..0x7f).each do |i|
42
+ json = '["\u%04x"]' % i
43
+ if RUBY_VERSION >= "1.9."
44
+ i = i.chr
45
+ end
46
+ assert_equal i, JSON.parse(json).first[0]
47
+ if i == ?\b
48
+ generated = JSON.generate(["" << i])
49
+ assert '["\b"]' == generated || '["\10"]' == generated
50
+ elsif [?\n, ?\r, ?\t, ?\f].include?(i)
51
+ assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i])
52
+ elsif i.chr < 0x20.chr
53
+ assert_equal json, JSON.generate(["" << i])
54
+ end
55
+ end
56
+ assert_raises(JSON::GeneratorError) do
57
+ JSON.generate(["" << 0x80])
58
+ end
59
+ assert_equal "\302\200", JSON.parse('["\u0080"]').first
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ extensions: []
3
+ homepage: http://rubyforge.org/projects/json-jruby/
4
+ executables: []
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.1.2
7
+ post_install_message:
8
+ date: 2008-04-06 03:00:00 +00:00
9
+ files:
10
+ - lib/json.rb
11
+ - lib/json
12
+ - lib/json/version.rb
13
+ - lib/json/add
14
+ - lib/json/ext
15
+ - lib/json/ext.rb
16
+ - lib/json/pure.rb
17
+ - lib/json/common.rb
18
+ - lib/json/pure
19
+ - lib/json/add/rails.rb
20
+ - lib/json/add/core.rb
21
+ - lib/json/ext/generator.jar
22
+ - lib/json/ext/parser.jar
23
+ - lib/json/pure/generator.rb
24
+ - lib/json/pure/parser.rb
25
+ - tests/test_json_generate.rb
26
+ - tests/test_json_unicode.rb
27
+ - tests/fixtures
28
+ - tests/test_json_addition.rb
29
+ - tests/test_json_fixtures.rb
30
+ - tests/test_json_rails.rb
31
+ - tests/test_json.rb
32
+ - tests/runner.rb
33
+ - tests/fixtures/fail20.json
34
+ - tests/fixtures/fail6.json
35
+ - tests/fixtures/fail1.json
36
+ - tests/fixtures/fail14.json
37
+ - tests/fixtures/fail9.json
38
+ - tests/fixtures/pass26.json
39
+ - tests/fixtures/fail27.json
40
+ - tests/fixtures/fail19.json
41
+ - tests/fixtures/fail5.json
42
+ - tests/fixtures/fail10.json
43
+ - tests/fixtures/fail12.json
44
+ - tests/fixtures/fail3.json
45
+ - tests/fixtures/fail13.json
46
+ - tests/fixtures/fail24.json
47
+ - tests/fixtures/pass3.json
48
+ - tests/fixtures/fail23.json
49
+ - tests/fixtures/fail7.json
50
+ - tests/fixtures/pass1.json
51
+ - tests/fixtures/fail18.json
52
+ - tests/fixtures/pass17.json
53
+ - tests/fixtures/fail11.json
54
+ - tests/fixtures/fail21.json
55
+ - tests/fixtures/fail25.json
56
+ - tests/fixtures/fail4.json
57
+ - tests/fixtures/fail8.json
58
+ - tests/fixtures/fail2.json
59
+ - tests/fixtures/pass15.json
60
+ - tests/fixtures/fail22.json
61
+ - tests/fixtures/fail28.json
62
+ - tests/fixtures/pass2.json
63
+ - tests/fixtures/pass16.json
64
+ rubygems_version: 1.0.1
65
+ rdoc_options: []
66
+ signing_key:
67
+ cert_chain: []
68
+ name: json-jruby
69
+ has_rdoc: false
70
+ platform: universal-java-1.5
71
+ summary: A JSON implementation as a JRuby extension
72
+ default_executable:
73
+ bindir: bin
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ version:
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: !str 0
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ version:
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: !str 0
86
+ require_paths:
87
+ - lib
88
+ specification_version: 2
89
+ test_files:
90
+ - tests/runner.rb
91
+ dependencies: []
92
+ description:
93
+ email: mernen@gmail.com
94
+ authors:
95
+ - Daniel Luz
96
+ extra_rdoc_files: []
97
+ requirements: []
98
+ rubyforge_project: json-jruby
99
+ autorequire: