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.
- checksums.yaml +5 -5
- data/LICENSE +21 -201
- data/README.md +105 -10
- data/bin/ffi-yajl-bench +11 -11
- data/ext/ffi_yajl/ext/dlopen/dlopen.c +40 -0
- data/ext/ffi_yajl/ext/dlopen/extconf.rb +16 -0
- data/ext/ffi_yajl/ext/dlopen/yajl.sym +18 -0
- data/ext/ffi_yajl/ext/encoder/encoder.c +270 -115
- data/ext/ffi_yajl/ext/encoder/extconf.rb +71 -14
- data/ext/ffi_yajl/ext/parser/extconf.rb +71 -14
- data/ext/ffi_yajl/ext/parser/parser.c +85 -44
- data/lib/ffi_yajl/benchmark/encode.rb +39 -92
- data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +23 -23
- data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +24 -30
- data/lib/ffi_yajl/benchmark/encode_profile.rb +15 -19
- data/lib/ffi_yajl/benchmark/http.rb +21 -25
- data/lib/ffi_yajl/benchmark/parse.rb +77 -117
- data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +27 -27
- data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +30 -30
- data/lib/ffi_yajl/benchmark/parse_profile.rb +14 -18
- data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +14 -19
- data/lib/ffi_yajl/benchmark/parse_stream.rb +28 -28
- data/lib/ffi_yajl/benchmark.rb +26 -6
- data/lib/ffi_yajl/encoder.rb +47 -6
- data/lib/ffi_yajl/ext.rb +37 -10
- data/lib/ffi_yajl/ffi/encoder.rb +150 -63
- data/lib/ffi_yajl/ffi/parser.rb +82 -64
- data/lib/ffi_yajl/ffi.rb +70 -46
- data/lib/ffi_yajl/map_library_name.rb +109 -0
- data/lib/ffi_yajl/parser.rb +69 -1
- data/lib/ffi_yajl/platform.rb +29 -0
- data/lib/ffi_yajl/version.rb +23 -1
- data/lib/ffi_yajl.rb +44 -8
- metadata +25 -238
- data/Rakefile +0 -62
- data/ext/libyajl2/extconf.rb +0 -65
- data/ext/libyajl2/vendored/.git +0 -1
- data/ext/libyajl2/vendored/.gitignore +0 -3
- data/ext/libyajl2/vendored/BUILDING +0 -23
- data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
- data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
- data/ext/libyajl2/vendored/COPYING +0 -13
- data/ext/libyajl2/vendored/ChangeLog +0 -175
- data/ext/libyajl2/vendored/README +0 -74
- data/ext/libyajl2/vendored/TODO +0 -9
- data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
- data/ext/libyajl2/vendored/configure +0 -79
- data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
- data/ext/libyajl2/vendored/example/README.md +0 -7
- data/ext/libyajl2/vendored/example/parse_config.c +0 -69
- data/ext/libyajl2/vendored/example/sample.config +0 -101
- data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
- data/ext/libyajl2/vendored/perf/documents.c +0 -1418
- data/ext/libyajl2/vendored/perf/documents.h +0 -28
- data/ext/libyajl2/vendored/perf/perftest.c +0 -134
- data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
- data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
- data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
- data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
- data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
- data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
- data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
- data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
- data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
- data/ext/libyajl2/vendored/src/yajl +0 -33
- data/ext/libyajl2/vendored/src/yajl.c +0 -175
- data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
- data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
- data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
- data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
- data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
- data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
- data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
- data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
- data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
- data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
- data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
- data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
- data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
- data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
- data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
- data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
- data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
- data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
- data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
- data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
- data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
- data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
- data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
- data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
- data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/array.json +0 -6
- data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
- data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
- data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
- data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
- data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
- data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
- data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
- data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
- data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
- data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
- data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
- data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
- data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
- data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
- data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
- data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
- data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
- data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/false.json +0 -1
- data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
- data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
- data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
- data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
- data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
- data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
- data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
- data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
- data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
- data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
- data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
- data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
- data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
- data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
- data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
- data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
- data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
- data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/null.json +0 -1
- data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
- data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
- data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
- data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
- data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
- data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
- data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
- data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
- data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
- data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
- data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
- data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
- data/ext/libyajl2/vendored/test/cases/true.json +0 -1
- data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
- data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
- data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
- data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
- data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
- data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
- data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
- data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
- data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
- data/lib/ffi_yajl/json_gem.rb +0 -121
- data/lib/libyajl.so +0 -0
- data/lib/libyajl.so.2 +0 -0
- data/lib/libyajl.so.2.0.5 +0 -0
- data/lib/libyajl_s.a +0 -0
- data/spec/ffi_yajl/encoder_spec.rb +0 -39
- data/spec/ffi_yajl/json_gem_spec.rb +0 -355
- data/spec/ffi_yajl/parser_spec.rb +0 -78
- 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
|