ffi-yajl 0.0.1-universal-java → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +21 -201
  3. data/README.md +105 -10
  4. data/bin/ffi-yajl-bench +11 -11
  5. data/ext/ffi_yajl/ext/dlopen/dlopen.c +40 -0
  6. data/ext/ffi_yajl/ext/dlopen/extconf.rb +16 -0
  7. data/ext/ffi_yajl/ext/dlopen/yajl.sym +18 -0
  8. data/ext/ffi_yajl/ext/encoder/encoder.c +270 -115
  9. data/ext/ffi_yajl/ext/encoder/extconf.rb +71 -14
  10. data/ext/ffi_yajl/ext/parser/extconf.rb +71 -14
  11. data/ext/ffi_yajl/ext/parser/parser.c +85 -44
  12. data/lib/ffi_yajl/benchmark/encode.rb +39 -92
  13. data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +23 -23
  14. data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +24 -30
  15. data/lib/ffi_yajl/benchmark/encode_profile.rb +15 -19
  16. data/lib/ffi_yajl/benchmark/http.rb +21 -25
  17. data/lib/ffi_yajl/benchmark/parse.rb +77 -117
  18. data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +27 -27
  19. data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +30 -30
  20. data/lib/ffi_yajl/benchmark/parse_profile.rb +14 -18
  21. data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +14 -19
  22. data/lib/ffi_yajl/benchmark/parse_stream.rb +28 -28
  23. data/lib/ffi_yajl/benchmark.rb +26 -6
  24. data/lib/ffi_yajl/encoder.rb +47 -6
  25. data/lib/ffi_yajl/ext.rb +37 -10
  26. data/lib/ffi_yajl/ffi/encoder.rb +150 -63
  27. data/lib/ffi_yajl/ffi/parser.rb +82 -64
  28. data/lib/ffi_yajl/ffi.rb +70 -46
  29. data/lib/ffi_yajl/map_library_name.rb +109 -0
  30. data/lib/ffi_yajl/parser.rb +69 -1
  31. data/lib/ffi_yajl/platform.rb +29 -0
  32. data/lib/ffi_yajl/version.rb +23 -1
  33. data/lib/ffi_yajl.rb +44 -8
  34. metadata +25 -238
  35. data/Rakefile +0 -62
  36. data/ext/libyajl2/extconf.rb +0 -65
  37. data/ext/libyajl2/vendored/.git +0 -1
  38. data/ext/libyajl2/vendored/.gitignore +0 -3
  39. data/ext/libyajl2/vendored/BUILDING +0 -23
  40. data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
  41. data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
  42. data/ext/libyajl2/vendored/COPYING +0 -13
  43. data/ext/libyajl2/vendored/ChangeLog +0 -175
  44. data/ext/libyajl2/vendored/README +0 -74
  45. data/ext/libyajl2/vendored/TODO +0 -9
  46. data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
  47. data/ext/libyajl2/vendored/configure +0 -79
  48. data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
  49. data/ext/libyajl2/vendored/example/README.md +0 -7
  50. data/ext/libyajl2/vendored/example/parse_config.c +0 -69
  51. data/ext/libyajl2/vendored/example/sample.config +0 -101
  52. data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
  53. data/ext/libyajl2/vendored/perf/documents.c +0 -1418
  54. data/ext/libyajl2/vendored/perf/documents.h +0 -28
  55. data/ext/libyajl2/vendored/perf/perftest.c +0 -134
  56. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
  57. data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
  58. data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
  59. data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
  60. data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
  61. data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
  62. data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
  63. data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
  64. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
  65. data/ext/libyajl2/vendored/src/yajl +0 -33
  66. data/ext/libyajl2/vendored/src/yajl.c +0 -175
  67. data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
  68. data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
  69. data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
  70. data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
  71. data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
  72. data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
  73. data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
  74. data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
  75. data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
  76. data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
  77. data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
  78. data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
  79. data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
  80. data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
  81. data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
  82. data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
  83. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
  84. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
  85. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
  86. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
  87. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
  88. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
  89. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
  90. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
  91. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
  92. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
  93. data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
  94. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
  95. data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
  96. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
  97. data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
  98. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
  99. data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
  100. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
  101. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
  102. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
  103. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
  104. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
  105. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
  106. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
  107. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
  108. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
  109. data/ext/libyajl2/vendored/test/cases/array.json +0 -6
  110. data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
  111. data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
  112. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
  113. data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
  114. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
  115. data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
  116. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
  117. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
  118. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
  119. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
  120. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
  121. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
  122. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
  123. data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
  124. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
  125. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
  126. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
  127. data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
  128. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
  129. data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
  130. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
  131. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
  132. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
  133. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
  134. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
  135. data/ext/libyajl2/vendored/test/cases/false.json +0 -1
  136. data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
  137. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
  138. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
  139. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
  140. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
  141. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
  142. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
  143. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
  144. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
  145. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
  146. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
  147. data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
  148. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
  149. data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
  150. data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
  151. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
  152. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
  153. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
  154. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
  155. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
  156. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
  157. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
  158. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
  159. data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
  160. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
  161. data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
  162. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
  163. data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
  164. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
  165. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
  166. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
  167. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
  168. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
  169. data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
  170. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
  171. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
  172. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
  173. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
  174. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
  175. data/ext/libyajl2/vendored/test/cases/null.json +0 -1
  176. data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
  177. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
  178. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
  179. data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
  180. data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
  181. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
  182. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
  183. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
  184. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
  185. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
  186. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
  187. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
  188. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
  189. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
  190. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
  191. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
  192. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
  193. data/ext/libyajl2/vendored/test/cases/true.json +0 -1
  194. data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
  195. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
  196. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
  197. data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
  198. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  199. data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
  200. data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
  201. data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
  202. data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
  203. data/lib/ffi_yajl/json_gem.rb +0 -121
  204. data/lib/libyajl.so +0 -0
  205. data/lib/libyajl.so.2 +0 -0
  206. data/lib/libyajl.so.2.0.5 +0 -0
  207. data/lib/libyajl_s.a +0 -0
  208. data/spec/ffi_yajl/encoder_spec.rb +0 -39
  209. data/spec/ffi_yajl/json_gem_spec.rb +0 -355
  210. data/spec/ffi_yajl/parser_spec.rb +0 -78
  211. data/spec/spec_helper.rb +0 -14
@@ -1,355 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # This started life as yajl-ruby's json_gem_compatibility/compatibility_spec.rb file.
4
- # Kinda looks like they stole it from the JSON gem. I updated the syntax a lot.
5
-
6
- require 'spec_helper'
7
-
8
- class Dummy; end
9
-
10
- describe "JSON Gem Compat API" do
11
-
12
- # Magic to make the before loading tests actually run before loading
13
- RSpec.configure do |config|
14
- config.order_groups_and_examples do |list|
15
- list.sort_by { |item| item.description }
16
- end
17
- end
18
-
19
- context "A: before loading the compat library" do
20
- it "should not mixin #to_json on random objects" do
21
- d = Dummy.new
22
- expect(d.respond_to?(:to_json)).to be_false
23
- end
24
-
25
- it "should not mixin #to_json to a string" do
26
- expect("".respond_to?(:to_json)).to be_false
27
- end
28
-
29
- it "should not mixin #to_json to a fixnum" do
30
- expect(1.respond_to?(:to_json)).to be_false
31
- end
32
-
33
- it "should not mixin #to_json on a float" do
34
- expect("1.5".to_f.respond_to?(:to_json)).to be_false
35
- end
36
-
37
- it "should not mixin #to_json on an array" do
38
- expect([].respond_to?(:to_json)).to be_false
39
- end
40
-
41
- it "should not mixin #to_json on a hash" do
42
- expect({:foo => "bar"}.respond_to?(:to_json)).to be_false
43
- end
44
-
45
- it "should not mixin #to_json on a trueclass" do
46
- expect(true.respond_to?(:to_json)).to be_false
47
- end
48
-
49
- it "should not mixin #to_json on a falseclass" do
50
- expect(false.respond_to?(:to_json)).to be_false
51
- end
52
-
53
- it "should not mixin #to_json on a nilclass" do
54
- expect(nil.respond_to?(:to_json)).to be_false
55
- end
56
- end
57
-
58
- context "B: when in compat mode" do
59
-
60
- before(:all) do
61
- require 'ffi_yajl/json_gem'
62
- end
63
-
64
- it "should define JSON class" do
65
- expect(defined?(JSON)).to be_true
66
- end
67
-
68
- it "should implement JSON#parse" do
69
- expect(JSON.respond_to?(:parse)).to be_true
70
- end
71
-
72
- it "should implement JSON#generate" do
73
- expect(JSON.respond_to?(:generate)).to be_true
74
- end
75
-
76
- it "should implement JSON#pretty_generate" do
77
- expect(JSON.respond_to?(:pretty_generate)).to be_true
78
- end
79
-
80
- it "should implement JSON#load" do
81
- expect(JSON.respond_to?(:load)).to be_true
82
- end
83
-
84
- it "should implement JSON#dump" do
85
- expect(JSON.respond_to?(:dump)).to be_true
86
- end
87
-
88
- context "when setting symbolize_keys via JSON.default_options" do
89
- before(:all) { @saved_default = JSON.default_options[:symbolize_keys] }
90
- after(:all) { JSON.default_options[:symbolize_keys] = @saved_default }
91
-
92
- it "the default behavior should be to not symbolize keys" do
93
- expect(JSON.parse('{"foo": 1234}')).to eq({"foo" => 1234})
94
- end
95
-
96
- it "changing the default_options should change the behavior to true" do
97
- pending("implement symbolize keys")
98
- JSON.default_options[:symbolize_keys] = true
99
- expect(JSON.parse('{"foo": 1234}')).to eq({:foo => 1234})
100
- end
101
- end
102
-
103
- context "when setting symbolize_names via JSON.default_options" do
104
- before(:all) { @saved_default = JSON.default_options[:symbolize_names] }
105
- after(:all) { JSON.default_options[:symbolize_names] = @saved_default }
106
-
107
- it "the default behavior should be to not symbolize keys" do
108
- expect(JSON.parse('{"foo": 1234}')).to eq({"foo" => 1234})
109
- end
110
-
111
- it "changing the default_options should change the behavior to true" do
112
- pending("implement symbolize keys")
113
- JSON.default_options[:symbolize_names] = true
114
- expect(JSON.parse('{"foo": 1234}')).to eq({:foo => 1234})
115
- end
116
- end
117
-
118
- it "should support passing symbolize_names to JSON.parse" do
119
- pending("implement symbolize keys")
120
- expect(JSON.parse('{"foo": 1234}', :symbolize_names => true)).to eq({:foo => 1234})
121
- end
122
-
123
- it "should support passing symbolize_keys to JSON.parse" do
124
- pending("implement symbolize keys")
125
- expect(JSON.parse('{"foo": 1234}', :symbolize_keys => true)).to eq({:foo => 1234})
126
- end
127
-
128
- context "when encode arbitrary classes via their default to_json method" do
129
- it "encodes random classes correctly" do
130
- d = Dummy.new
131
- expect(d.to_json).to eq( %Q{"#{d.to_s}"} )
132
- end
133
-
134
- it "encodes Time values correctly" do
135
- t = Time.new
136
- expect(t.to_json).to eq( %Q{"#{t.to_s}"} )
137
- end
138
-
139
- it "encodes Date values correctly" do
140
- da = Date.new
141
- expect(da.to_json).to eq( %Q{"#{da.to_s}"} )
142
- end
143
-
144
- it "encodes DateTime values correctly" do
145
- dt = DateTime.new
146
- expect(dt.to_json).to eq( %Q{"#{dt.to_s}"} )
147
- end
148
- end
149
-
150
- context "JSON exception classes" do
151
- it "should define JSON::JSONError as a StandardError" do
152
- expect(JSON::JSONError.new.is_a?(StandardError)).to be_true
153
- end
154
- it "should define JSON::ParserError as a JSON::JSONError" do
155
- expect(JSON::ParserError.new.is_a?(JSON::JSONError)).to be_true
156
- end
157
- it "should define JSON::GeneratorError as a JSON::JSONError" do
158
- expect(JSON::GeneratorError.new.is_a?(JSON::JSONError)).to be_true
159
- end
160
- it "should raise JSON::ParserError on a bad parse" do
161
- expect{ JSON.parse("blah") }.to raise_error(JSON::ParserError)
162
- end
163
- it "should raise JSON::GeneratorError on encoding NaN" do
164
- expect{ JSON.generate(0.0/0.0) }.to raise_error(JSON::GeneratorError)
165
- end
166
- it "should raise JSON::GeneratorError on encoding -Infinity" do
167
- expect{ JSON.generate(-1.0/0.0) }.to raise_error(JSON::GeneratorError)
168
- end
169
- it "should raise JSON::GeneratorError on encoding Infinity" do
170
- expect{ JSON.generate(1.0/0.0) }.to raise_error(JSON::GeneratorError)
171
- end
172
- it "should raise JSON::GeneratorError on encoding a partial UTF-8 character" do
173
- expect{ JSON.generate(["\xea"]) }.to raise_error(JSON::GeneratorError)
174
- end
175
- end
176
-
177
- shared_examples_for "handles encoding and parsing correctly" do
178
- it "should encode the content correctly" do
179
- expect(ruby.to_json).to eq(json)
180
- end
181
- it "should parse the content correctly" do
182
- expect(JSON.parse(json)).to eq(ruby)
183
- end
184
- end
185
-
186
- context "when encoding strings" do
187
- it "should render empty string correctly" do
188
- expect(''.to_json).to eq( %q{""} )
189
- end
190
- it "should encode backspace character" do
191
- expect("\b".to_json).to eq( %q{"\\b"} )
192
- end
193
- it "should encode \u0001 correctly" do
194
- expect(0x1.chr.to_json).to eq( %q{"\u0001"} )
195
- end
196
-
197
- it "should encode \u001f correctly" do
198
- expect(0x1f.chr.to_json).to eq( %q{"\u001F"} )
199
- end
200
-
201
- it "should encode a string with a space correctly" do
202
- expect(' '.to_json).to eq( %q{" "} )
203
- end
204
-
205
- it "should encode 0x75 correctly" do
206
- expect(0x7f.chr.to_json).to eq( %Q{"#{0x7f.chr}"} )
207
- end
208
-
209
- context "when dealing with bignums" do
210
- let(:ruby) { [ 12345678901234567890 ] }
211
- let(:json) { "[12345678901234567890]" }
212
-
213
- it_behaves_like "handles encoding and parsing correctly"
214
- end
215
-
216
-
217
- context "when dealing with common UTF-8 symbols" do
218
- let(:ruby) { [ "© ≠ €! \01" ] }
219
- let(:json) { "[\"© ≠ €! \\u0001\"]" }
220
-
221
- it_behaves_like "handles encoding and parsing correctly"
222
- end
223
-
224
- context "when dealing with Hiragana UTF-8 characters" do
225
- let(:ruby) { ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"] }
226
- let(:json) { "[\"あいうえお\"]" }
227
-
228
- it_behaves_like "handles encoding and parsing correctly"
229
- end
230
-
231
- context "whatever this is" do
232
- let(:ruby) { ['საქართველო'] }
233
- let(:json) { "[\"საქართველო\"]" }
234
-
235
- it_behaves_like "handles encoding and parsing correctly"
236
- end
237
-
238
- context "accents" do
239
- let(:ruby) { ["Ã"] }
240
- let(:json) { '["Ã"]' }
241
-
242
- it_behaves_like "handles encoding and parsing correctly"
243
- end
244
-
245
- context "euro symbol" do
246
- let(:ruby) { ["€"] }
247
- let(:json) { '["\u20ac"]' }
248
- it "should parse the content correctly" do
249
- expect(JSON.parse(json)).to eq(ruby)
250
- end
251
- end
252
-
253
- context "and whatever this is" do
254
-
255
- utf8_str = "\xf0\xa0\x80\x81"
256
- let(:ruby) { [utf8_str] }
257
- let(:json) { "[\"#{utf8_str}\"]" }
258
-
259
- it_behaves_like "handles encoding and parsing correctly"
260
- end
261
- end
262
-
263
-
264
- context "when encoding basic types with #to_json" do
265
- it "Array#to_json should work" do
266
- expect([ "a", "b", "c" ].to_json).to eq(%Q{["a","b","c"]})
267
- end
268
-
269
- it "Hash#to_json should work" do
270
- expect({"a"=>"b"}.to_json).to eq(%Q{{"a":"b"}})
271
- end
272
-
273
- it "Fixnum#to_json should work" do
274
- expect(1.to_json).to eq("1")
275
- end
276
-
277
- it "Float#to_json should work" do
278
- expect(1.1.to_json).to eq("1.1")
279
- end
280
-
281
- it "String#to_json should work" do
282
- expect("foo".to_json).to eq(%Q{"foo"})
283
- end
284
-
285
- it "TrueClass#to_json should work" do
286
- expect(true.to_json).to eq("true")
287
- end
288
-
289
- it "FalseClass#to_json should work" do
290
- expect(false.to_json).to eq("false")
291
- end
292
-
293
- it "NilClass#to_json should work" do
294
- expect(nil.to_json).to eq("null")
295
- end
296
- end
297
-
298
- context "ported tests for generation" do
299
- before(:all) do
300
- @hash = {
301
- 'a' => 2,
302
- 'b' => 3.141,
303
- 'c' => 'c',
304
- 'd' => [ 1, "b", 3.14 ],
305
- 'e' => { 'foo' => 'bar' },
306
- 'g' => "blah",
307
- 'h' => 1000.0,
308
- 'i' => 0.001
309
- }
310
-
311
- @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},"g":"blah","h":1000.0,"i":0.001}'
312
-
313
- @json3 = %{
314
- {
315
- "a": 2,
316
- "b": 3.141,
317
- "c": "c",
318
- "d": [1, "b", 3.14],
319
- "e": {"foo": "bar"},
320
- "g": "blah",
321
- "h": 1000.0,
322
- "i": 0.001
323
- }
324
- }.chomp
325
- end
326
-
327
- it "should be able to unparse" do
328
- json = JSON.generate(@hash)
329
- expect(JSON.parse(@json2)).to eq(JSON.parse(json))
330
- parsed_json = JSON.parse(json)
331
- expect(@hash).to eq(parsed_json)
332
- json = JSON.generate({1=>2})
333
- expect('{"1":2}').to eql(json)
334
- parsed_json = JSON.parse(json)
335
- expect({"1"=>2}).to eq(parsed_json)
336
- end
337
-
338
- it "should be able to unparse pretty" do
339
- json = JSON.pretty_generate(@hash)
340
- expect(JSON.parse(@json3)).to eq(JSON.parse(json))
341
- parsed_json = JSON.parse(json)
342
- expect(@hash).to eq(parsed_json)
343
- json = JSON.pretty_generate({1=>2})
344
- test = "{\n \"1\": 2\n}".chomp
345
- expect(test).to eq(json)
346
- parsed_json = JSON.parse(json)
347
- expect({"1"=>2}).to eq(parsed_json)
348
- end
349
-
350
- it "JSON.generate should handle nil second argument" do
351
- expect(JSON.generate(["foo"], nil)).to eql(%q{["foo"]})
352
- end
353
- end
354
- end
355
- end
@@ -1,78 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe "FFI_Yajl::Parser" do
6
-
7
- let(:parser) { FFI_Yajl::Parser.new }
8
-
9
- it "throws an exception when trailing braces are missing" do
10
- json = '{{"foo": 1234}'
11
- expect { parser.parse(json) }.to raise_error(FFI_Yajl::ParseError)
12
- end
13
-
14
- it "throws an exception when trailing brackets are missing" do
15
- json = '[["foo", "bar"]'
16
- expect { parser.parse(json) }.to raise_error(FFI_Yajl::ParseError)
17
- end
18
-
19
- it "throws an exception when it has an extra brace" do
20
- json = '{{"foo": 1234}}}'
21
- expect { parser.parse(json) }.to raise_error(FFI_Yajl::ParseError)
22
- end
23
-
24
- it "throws an exception when it has an extra bracket" do
25
- json = '[["foo", "bar"]]]'
26
- expect { parser.parse(json) }.to raise_error(FFI_Yajl::ParseError)
27
- end
28
-
29
- context "when parsing floats" do
30
- it "parses simple floating point values" do
31
- json = '{"foo": 3.14159265358979}'
32
- expect(parser.parse(json)).to eql({"foo" => 3.14159265358979})
33
- end
34
-
35
- it "parses simple negative floating point values" do
36
- json = '{"foo":-2.00231930436153}'
37
- expect(parser.parse(json)).to eql({"foo" => -2.00231930436153})
38
- end
39
-
40
- it "parses floats with negative exponents and a large E" do
41
- json = '{"foo": 1.602176565E-19}'
42
- expect(parser.parse(json)).to eql({"foo" => 1.602176565e-19})
43
- end
44
-
45
- it "parses floats with negative exponents and a small e" do
46
- json = '{"foo": 6.6260689633e-34 }'
47
- expect(parser.parse(json)).to eql({"foo" => 6.6260689633e-34 })
48
- end
49
-
50
- it "parses floats with positive exponents and a large E" do
51
- json = '{"foo": 6.0221413E+23}'
52
- expect(parser.parse(json)).to eql({"foo" => 6.0221413e+23})
53
- end
54
-
55
- it "parses floats with positive exponents and a small e" do
56
- json = '{"foo": 8.9875517873681764e+9 }'
57
- expect(parser.parse(json)).to eql({"foo" => 8.9875517873681764e+9 })
58
- end
59
-
60
- it "parses floats with an exponent without a sign and a large E" do
61
- json = '{"foo": 2.99792458E8 }'
62
- expect(parser.parse(json)).to eql({"foo" => 2.99792458e+8 })
63
- end
64
-
65
- it "parses floats with an exponent without a sign and a small e" do
66
- json = '{"foo": 1.0973731568539e7 }'
67
- expect(parser.parse(json)).to eql({"foo" => 1.0973731568539e+7 })
68
- end
69
- end
70
-
71
- context "when parsing unicode in hash keys" do
72
- it "handles heavy metal umlauts in keys" do
73
- json = '{"München": "Bayern"}'
74
- expect(parser.parse(json)).to eql({"München" => "Bayern"})
75
- end
76
- end
77
- end
78
-
data/spec/spec_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- $: << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
2
-
3
- require 'ffi_yajl'
4
-
5
- RSpec.configure do |c|
6
- c.filter_run_excluding :ruby_gte_19 => true unless RUBY_VERSION.to_f >= 1.9
7
-
8
- c.order = 'random'
9
-
10
- c.expect_with :rspec do |c|
11
- c.syntax = :expect
12
- end
13
-
14
- end