json_pure 1.8.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +5 -3
  4. data/CHANGES +5 -5
  5. data/Gemfile +3 -1
  6. data/README.md +131 -84
  7. data/Rakefile +17 -10
  8. data/VERSION +1 -1
  9. data/ext/json/ext/generator/generator.c +1 -52
  10. data/ext/json/ext/generator/generator.h +0 -5
  11. data/ext/json/ext/parser/extconf.rb +3 -0
  12. data/ext/json/ext/parser/parser.c +304 -458
  13. data/ext/json/ext/parser/parser.h +0 -1
  14. data/ext/json/ext/parser/parser.rl +35 -152
  15. data/ext/json/extconf.rb +0 -1
  16. data/java/src/json/ext/Generator.java +2 -5
  17. data/java/src/json/ext/GeneratorState.java +2 -54
  18. data/java/src/json/ext/OptionsReader.java +1 -1
  19. data/java/src/json/ext/Parser.java +109 -409
  20. data/java/src/json/ext/Parser.rl +24 -117
  21. data/java/src/json/ext/RuntimeInfo.java +0 -4
  22. data/json.gemspec +0 -0
  23. data/json_pure.gemspec +7 -7
  24. data/lib/json.rb +1 -0
  25. data/lib/json/add/bigdecimal.rb +1 -0
  26. data/lib/json/add/complex.rb +2 -1
  27. data/lib/json/add/core.rb +1 -0
  28. data/lib/json/add/date.rb +1 -1
  29. data/lib/json/add/date_time.rb +1 -1
  30. data/lib/json/add/exception.rb +1 -1
  31. data/lib/json/add/ostruct.rb +1 -1
  32. data/lib/json/add/range.rb +1 -1
  33. data/lib/json/add/rational.rb +1 -0
  34. data/lib/json/add/regexp.rb +1 -1
  35. data/lib/json/add/struct.rb +1 -1
  36. data/lib/json/add/symbol.rb +1 -1
  37. data/lib/json/add/time.rb +1 -1
  38. data/lib/json/common.rb +24 -52
  39. data/lib/json/ext.rb +0 -6
  40. data/lib/json/generic_object.rb +5 -4
  41. data/lib/json/pure.rb +2 -8
  42. data/lib/json/pure/generator.rb +51 -123
  43. data/lib/json/pure/parser.rb +28 -80
  44. data/lib/json/version.rb +2 -1
  45. data/references/rfc7159.txt +899 -0
  46. data/tests/fixtures/obsolete_fail1.json +1 -0
  47. data/tests/{test_json_addition.rb → json_addition_test.rb} +22 -25
  48. data/tests/json_common_interface_test.rb +126 -0
  49. data/tests/json_encoding_test.rb +105 -0
  50. data/tests/json_ext_parser_test.rb +15 -0
  51. data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
  52. data/tests/{test_json_generate.rb → json_generator_test.rb} +65 -37
  53. data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
  54. data/tests/json_parser_test.rb +448 -0
  55. data/tests/json_string_matching_test.rb +38 -0
  56. data/tests/test_helper.rb +23 -0
  57. data/tools/fuzz.rb +1 -9
  58. metadata +18 -31
  59. data/TODO +0 -1
  60. data/tests/fixtures/fail1.json +0 -1
  61. data/tests/setup_variant.rb +0 -11
  62. data/tests/test_json.rb +0 -519
  63. data/tests/test_json_encoding.rb +0 -65
  64. data/tests/test_json_string_matching.rb +0 -39
  65. data/tests/test_json_unicode.rb +0 -72
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
-
7
- class TestJSONEncoding < Test::Unit::TestCase
8
- include JSON
9
-
10
- def setup
11
- @utf_8 = '["© ≠ €!"]'
12
- @parsed = [ "© ≠ €!" ]
13
- @generated = '["\u00a9 \u2260 \u20ac!"]'
14
- if String.method_defined?(:encode)
15
- @utf_16_data = [@parsed.first.encode('utf-16be', 'utf-8')]
16
- @utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
17
- @utf_16be = @utf_8.encode('utf-16be', 'utf-8')
18
- @utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
19
- @utf_16le = @utf_8.encode('utf-16le', 'utf-8')
20
- @utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
21
- @utf_32be = @utf_8.encode('utf-32be', 'utf-8')
22
- @utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
23
- @utf_32le = @utf_8.encode('utf-32le', 'utf-8')
24
- @utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
25
- else
26
- require 'iconv'
27
- @utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
28
- @utf_8_ascii_8bit = @utf_8.dup
29
- @utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
30
- @utf_16be_ascii_8bit = @utf_16be.dup
31
- @utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
32
- @utf_16le_ascii_8bit = @utf_16le.dup
33
- @utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
34
- @utf_32be_ascii_8bit = @utf_32be.dup
35
- @utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
36
- @utf_32le_ascii_8bit = @utf_32le.dup
37
- end
38
- end
39
-
40
- def test_parse
41
- assert_equal @parsed, JSON.parse(@utf_8)
42
- assert_equal @parsed, JSON.parse(@utf_16be)
43
- assert_equal @parsed, JSON.parse(@utf_16le)
44
- assert_equal @parsed, JSON.parse(@utf_32be)
45
- assert_equal @parsed, JSON.parse(@utf_32le)
46
- end
47
-
48
- def test_parse_ascii_8bit
49
- assert_equal @parsed, JSON.parse(@utf_8_ascii_8bit)
50
- assert_equal @parsed, JSON.parse(@utf_16be_ascii_8bit)
51
- assert_equal @parsed, JSON.parse(@utf_16le_ascii_8bit)
52
- assert_equal @parsed, JSON.parse(@utf_32be_ascii_8bit)
53
- assert_equal @parsed, JSON.parse(@utf_32le_ascii_8bit)
54
- end
55
-
56
- def test_generate
57
- assert_equal @generated, JSON.generate(@parsed, :ascii_only => true)
58
- if defined?(::Encoding)
59
- assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
60
- else
61
- # XXX checking of correct utf8 data is not as strict (yet?) without :ascii_only
62
- assert_raises(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) }
63
- end
64
- end
65
- end
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
- require 'stringio'
7
- require 'time'
8
-
9
- class TestJSONStringMatching < Test::Unit::TestCase
10
- include JSON
11
-
12
- class TestTime < ::Time
13
- def self.json_create(string)
14
- Time.parse(string)
15
- end
16
-
17
- def to_json(*)
18
- %{"#{strftime('%FT%T%z')}"}
19
- end
20
-
21
- def ==(other)
22
- to_i == other.to_i
23
- end
24
- end
25
-
26
- def test_match_date
27
- t = TestTime.new
28
- t_json = [ t ].to_json
29
- assert_equal [ t ],
30
- JSON.parse(t_json, :create_additions => true,
31
- :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
32
- assert_equal [ t.strftime('%FT%T%z') ],
33
- JSON.parse(t_json, :create_additions => true,
34
- :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
35
- assert_equal [ t.strftime('%FT%T%z') ],
36
- JSON.parse(t_json,
37
- :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
38
- end
39
- end
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
-
7
- class TestJSONUnicode < Test::Unit::TestCase
8
- include JSON
9
-
10
- def test_unicode
11
- assert_equal '""', ''.to_json
12
- assert_equal '"\\b"', "\b".to_json
13
- assert_equal '"\u0001"', 0x1.chr.to_json
14
- assert_equal '"\u001f"', 0x1f.chr.to_json
15
- assert_equal '" "', ' '.to_json
16
- assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
17
- utf8 = [ "© ≠ €! \01" ]
18
- json = '["© ≠ €! \u0001"]'
19
- assert_equal json, utf8.to_json(:ascii_only => false)
20
- assert_equal utf8, parse(json)
21
- json = '["\u00a9 \u2260 \u20ac! \u0001"]'
22
- assert_equal json, utf8.to_json(:ascii_only => true)
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 = "[\"\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212\"]"
26
- assert_equal utf8, parse(json)
27
- assert_equal json, utf8.to_json(:ascii_only => false)
28
- utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
29
- assert_equal utf8, parse(json)
30
- json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
31
- assert_equal json, utf8.to_json(:ascii_only => true)
32
- assert_equal utf8, parse(json)
33
- utf8 = ['საქართველო']
34
- json = '["საქართველო"]'
35
- assert_equal json, utf8.to_json(:ascii_only => false)
36
- json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
37
- assert_equal json, utf8.to_json(:ascii_only => true)
38
- assert_equal utf8, parse(json)
39
- assert_equal '["Ã"]', JSON.generate(["Ã"], :ascii_only => false)
40
- assert_equal '["\\u00c3"]', JSON.generate(["Ã"], :ascii_only => true)
41
- assert_equal ["€"], JSON.parse('["\u20ac"]')
42
- utf8 = ["\xf0\xa0\x80\x81"]
43
- json = "[\"\xf0\xa0\x80\x81\"]"
44
- assert_equal json, JSON.generate(utf8, :ascii_only => false)
45
- assert_equal utf8, JSON.parse(json)
46
- json = '["\ud840\udc01"]'
47
- assert_equal json, JSON.generate(utf8, :ascii_only => true)
48
- assert_equal utf8, JSON.parse(json)
49
- end
50
-
51
- def test_chars
52
- (0..0x7f).each do |i|
53
- json = '["\u%04x"]' % i
54
- if RUBY_VERSION >= "1.9."
55
- i = i.chr
56
- end
57
- assert_equal i, JSON.parse(json).first[0]
58
- if i == ?\b
59
- generated = JSON.generate(["" << i])
60
- assert '["\b"]' == generated || '["\10"]' == generated
61
- elsif [?\n, ?\r, ?\t, ?\f].include?(i)
62
- assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i])
63
- elsif i.chr < 0x20.chr
64
- assert_equal json, JSON.generate(["" << i])
65
- end
66
- end
67
- assert_raise(JSON::GeneratorError) do
68
- JSON.generate(["\x80"], :ascii_only => true)
69
- end
70
- assert_equal "\302\200", JSON.parse('["\u0080"]').first
71
- end
72
- end