json 2.0.3 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +66 -0
  3. data/Gemfile +1 -3
  4. data/LICENSE +56 -0
  5. data/README.md +54 -21
  6. data/VERSION +1 -1
  7. data/ext/json/ext/fbuffer/fbuffer.h +0 -3
  8. data/ext/json/ext/generator/generator.c +229 -54
  9. data/ext/json/ext/generator/generator.h +5 -3
  10. data/ext/json/ext/parser/extconf.rb +25 -0
  11. data/ext/json/ext/parser/parser.c +180 -85
  12. data/ext/json/ext/parser/parser.h +2 -0
  13. data/ext/json/ext/parser/parser.rl +104 -9
  14. data/ext/json/extconf.rb +1 -0
  15. data/json.gemspec +0 -0
  16. data/lib/json/add/bigdecimal.rb +2 -2
  17. data/lib/json/add/complex.rb +2 -3
  18. data/lib/json/add/ostruct.rb +1 -1
  19. data/lib/json/add/rational.rb +2 -3
  20. data/lib/json/add/regexp.rb +2 -2
  21. data/lib/json/add/set.rb +29 -0
  22. data/lib/json/common.rb +372 -125
  23. data/lib/json/pure/generator.rb +31 -10
  24. data/lib/json/pure/parser.rb +35 -5
  25. data/lib/json/version.rb +1 -1
  26. data/lib/json.rb +549 -29
  27. data/tests/fixtures/fail29.json +1 -0
  28. data/tests/fixtures/fail30.json +1 -0
  29. data/tests/fixtures/fail31.json +1 -0
  30. data/tests/fixtures/fail32.json +1 -0
  31. data/tests/json_addition_test.rb +6 -0
  32. data/tests/json_common_interface_test.rb +47 -4
  33. data/tests/json_encoding_test.rb +2 -0
  34. data/tests/json_fixtures_test.rb +9 -1
  35. data/tests/json_generator_test.rb +30 -8
  36. data/tests/json_parser_test.rb +43 -12
  37. data/tests/lib/core_assertions.rb +763 -0
  38. data/tests/lib/envutil.rb +365 -0
  39. data/tests/lib/find_executable.rb +22 -0
  40. data/tests/lib/helper.rb +4 -0
  41. data/tests/ractor_test.rb +30 -0
  42. data/tests/test_helper.rb +3 -7
  43. metadata +31 -44
  44. data/.gitignore +0 -17
  45. data/.travis.yml +0 -19
  46. data/README-json-jruby.md +0 -33
  47. data/Rakefile +0 -408
  48. data/data/example.json +0 -1
  49. data/data/index.html +0 -38
  50. data/data/prototype.js +0 -4184
  51. data/diagrams/.keep +0 -0
  52. data/install.rb +0 -23
  53. data/java/src/json/ext/ByteListTranscoder.java +0 -166
  54. data/java/src/json/ext/Generator.java +0 -443
  55. data/java/src/json/ext/GeneratorMethods.java +0 -231
  56. data/java/src/json/ext/GeneratorService.java +0 -42
  57. data/java/src/json/ext/GeneratorState.java +0 -490
  58. data/java/src/json/ext/OptionsReader.java +0 -113
  59. data/java/src/json/ext/Parser.java +0 -2347
  60. data/java/src/json/ext/Parser.rl +0 -878
  61. data/java/src/json/ext/ParserService.java +0 -34
  62. data/java/src/json/ext/RuntimeInfo.java +0 -116
  63. data/java/src/json/ext/StringDecoder.java +0 -166
  64. data/java/src/json/ext/StringEncoder.java +0 -111
  65. data/java/src/json/ext/Utils.java +0 -88
  66. data/json-java.gemspec +0 -38
  67. data/json_pure.gemspec +0 -38
  68. data/references/rfc7159.txt +0 -899
  69. data/tools/diff.sh +0 -18
  70. data/tools/fuzz.rb +0 -131
  71. data/tools/server.rb +0 -62
data/tools/diff.sh DELETED
@@ -1,18 +0,0 @@
1
- #!/bin/sh
2
-
3
- files=`find ext -name '*.[ch]' -o -name parser.rl`
4
-
5
- for f in $files
6
- do
7
- b=`basename $f`
8
- g=`find ../ruby/ext/json -name $b`
9
- d=`diff -u $f $g`
10
- test -z "$d" && continue
11
- echo "$d"
12
- read -p "Edit diff of $b? " a
13
- case $a in
14
- [yY]*)
15
- vimdiff $f $g
16
- ;;
17
- esac
18
- done
data/tools/fuzz.rb DELETED
@@ -1,131 +0,0 @@
1
- require 'json'
2
-
3
- class Fuzzer
4
- def initialize(n, freqs = {})
5
- sum = freqs.inject(0.0) { |s, x| s + x.last }
6
- freqs.each_key { |x| freqs[x] /= sum }
7
- s = 0.0
8
- freqs.each_key do |x|
9
- freqs[x] = s .. (s + t = freqs[x])
10
- s += t
11
- end
12
- @freqs = freqs
13
- @n = n
14
- @alpha = (0..0xff).to_a
15
- end
16
-
17
- def random_string
18
- s = ''
19
- 30.times { s << @alpha[rand(@alpha.size)] }
20
- s
21
- end
22
-
23
- def pick
24
- r = rand
25
- found = @freqs.find { |k, f| f.include? rand }
26
- found && found.first
27
- end
28
-
29
- def make_pick
30
- k = pick
31
- case
32
- when k == Hash, k == Array
33
- k.new
34
- when k == true, k == false, k == nil
35
- k
36
- when k == String
37
- random_string
38
- when k == Fixnum
39
- rand(2 ** 30) - 2 ** 29
40
- when k == Bignum
41
- rand(2 ** 70) - 2 ** 69
42
- end
43
- end
44
-
45
- def fuzz(current = nil)
46
- if @n > 0
47
- case current
48
- when nil
49
- @n -= 1
50
- current = fuzz [ Hash, Array ][rand(2)].new
51
- when Array
52
- while @n > 0
53
- @n -= 1
54
- current << case p = make_pick
55
- when Array, Hash
56
- fuzz(p)
57
- else
58
- p
59
- end
60
- end
61
- when Hash
62
- while @n > 0
63
- @n -= 1
64
- current[random_string] = case p = make_pick
65
- when Array, Hash
66
- fuzz(p)
67
- else
68
- p
69
- end
70
- end
71
- end
72
- end
73
- current
74
- end
75
- end
76
-
77
- class MyState < JSON.state
78
- WS = " \r\t\n"
79
-
80
- def initialize
81
- super(
82
- :indent => make_spaces,
83
- :space => make_spaces,
84
- :space_before => make_spaces,
85
- :object_nl => make_spaces,
86
- :array_nl => make_spaces,
87
- :max_nesting => false
88
- )
89
- end
90
-
91
- def make_spaces
92
- s = ''
93
- rand(1).times { s << WS[rand(WS.size)] }
94
- s
95
- end
96
- end
97
-
98
- n = (ARGV.shift || 500).to_i
99
- loop do
100
- fuzzer = Fuzzer.new(n,
101
- Hash => 25,
102
- Array => 25,
103
- String => 10,
104
- Fixnum => 10,
105
- Bignum => 10,
106
- nil => 5,
107
- true => 5,
108
- false => 5
109
- )
110
- o1 = fuzzer.fuzz
111
- json = JSON.generate o1, MyState.new
112
- if $DEBUG
113
- puts "-" * 80
114
- puts json, json.size
115
- else
116
- puts json.size
117
- end
118
- begin
119
- o2 = JSON.parse(json, :max_nesting => false)
120
- rescue JSON::ParserError => e
121
- puts "Caught #{e.class}: #{e.message}\n#{e.backtrace * "\n"}"
122
- puts "o1 = #{o1.inspect}", "json = #{json}", "json_str = #{json.inspect}"
123
- puts "locals = #{local_variables.inspect}"
124
- exit
125
- end
126
- if o1 != o2
127
- puts "mismatch", "o1 = #{o1.inspect}", "o2 = #{o2.inspect}",
128
- "json = #{json}", "json_str = #{json.inspect}"
129
- puts "locals = #{local_variables.inspect}"
130
- end
131
- end
data/tools/server.rb DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'webrick'
5
- include WEBrick
6
- $:.unshift 'ext'
7
- $:.unshift 'lib'
8
- require 'json'
9
-
10
- class JSONServlet < HTTPServlet::AbstractServlet
11
- @@count = 1
12
-
13
- def do_GET(req, res)
14
- obj = {
15
- "TIME" => Time.now.strftime("%FT%T"),
16
- "foo" => "Bär",
17
- "bar" => "© ≠ €!",
18
- 'a' => 2,
19
- 'b' => 3.141,
20
- 'COUNT' => @@count += 1,
21
- 'c' => 'c',
22
- 'd' => [ 1, "b", 3.14 ],
23
- 'e' => { 'foo' => 'bar' },
24
- 'g' => "松本行弘",
25
- 'h' => 1000.0,
26
- 'i' => 0.001,
27
- 'j' => "\xf0\xa0\x80\x81",
28
- }
29
- res.body = JSON.generate obj
30
- res['Content-Type'] = "application/json"
31
- end
32
- end
33
-
34
- def create_server(err, dir, port)
35
- dir = File.expand_path(dir)
36
- err.puts "Surf to:", "http://#{Socket.gethostname}:#{port}"
37
-
38
- s = HTTPServer.new(
39
- :Port => port,
40
- :DocumentRoot => dir,
41
- :Logger => WEBrick::Log.new(err),
42
- :AccessLog => [
43
- [ err, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
44
- [ err, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
45
- [ err, WEBrick::AccessLog::AGENT_LOG_FORMAT ]
46
- ]
47
- )
48
- s.mount("/json", JSONServlet)
49
- s
50
- end
51
-
52
- default_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
53
- dir = ARGV.shift || default_dir
54
- port = (ARGV.shift || 6666).to_i
55
- s = create_server(STDERR, dir, 6666)
56
- t = Thread.new { s.start }
57
- trap(:INT) do
58
- s.shutdown
59
- t.join
60
- exit
61
- end
62
- sleep