yajl-ruby 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- data/CHANGELOG.md +8 -1
- data/MIT-LICENSE +3 -3
- data/README.rdoc +8 -8
- data/VERSION.yml +1 -1
- data/benchmark/subjects/ohai.yml +171 -171
- data/ext/api/yajl_common.h +9 -9
- data/ext/api/yajl_gen.h +10 -10
- data/ext/api/yajl_parse.h +15 -15
- data/ext/yajl.c +8 -8
- data/ext/yajl_alloc.c +6 -6
- data/ext/yajl_alloc.h +6 -6
- data/ext/yajl_buf.c +7 -7
- data/ext/yajl_buf.h +7 -7
- data/ext/yajl_bytestack.h +10 -10
- data/ext/yajl_encode.c +12 -12
- data/ext/yajl_encode.h +6 -6
- data/ext/yajl_ext.c +67 -80
- data/ext/yajl_ext.h +4 -4
- data/ext/yajl_gen.c +16 -16
- data/ext/yajl_lex.c +79 -76
- data/ext/yajl_lex.h +14 -14
- data/ext/yajl_parser.c +34 -34
- data/ext/yajl_parser.h +7 -7
- data/lib/yajl.rb +7 -7
- data/lib/yajl/bzip2/stream_reader.rb +1 -11
- data/lib/yajl/bzip2/stream_writer.rb +1 -1
- data/lib/yajl/deflate/stream_reader.rb +6 -7
- data/lib/yajl/deflate/stream_writer.rb +2 -2
- data/lib/yajl/gzip/stream_reader.rb +0 -10
- data/lib/yajl/http_stream.rb +12 -12
- data/lib/yajl/json_gem/encoding.rb +4 -4
- data/lib/yajl/json_gem/parsing.rb +3 -3
- data/spec/encoding/encoding_spec.rb +23 -23
- data/spec/global/global_spec.rb +8 -8
- data/spec/http/http_delete_spec.rb +13 -13
- data/spec/http/http_error_spec.rb +2 -2
- data/spec/http/http_get_spec.rb +15 -15
- data/spec/http/http_post_spec.rb +12 -12
- data/spec/http/http_put_spec.rb +14 -14
- data/spec/json_gem_compatibility/compatibility_spec.rb +21 -21
- data/spec/parsing/active_support_spec.rb +6 -6
- data/spec/parsing/chunked_spec.rb +12 -12
- data/spec/parsing/fixtures_spec.rb +4 -4
- data/spec/parsing/one_off_spec.rb +9 -9
- data/yajl-ruby.gemspec +3 -3
- metadata +12 -5
@@ -15,7 +15,7 @@ describe "Yajl HTTP error" do
|
|
15
15
|
@uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.error.dump")
|
16
16
|
TCPSocket.should_receive(:new).and_return(@request)
|
17
17
|
@request.should_receive(:write)
|
18
|
-
|
18
|
+
|
19
19
|
begin
|
20
20
|
Yajl::HttpStream.get(@uri)
|
21
21
|
rescue Yajl::HttpStream::HttpError => e
|
@@ -26,7 +26,7 @@ describe "Yajl HTTP error" do
|
|
26
26
|
it "should contain the error code in the message" do
|
27
27
|
@error.message.should match(/404/)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should provide the HTTP response headers" do
|
31
31
|
@error.headers.keys.should include('ETag', 'Content-Length', 'Server')
|
32
32
|
end
|
data/spec/http/http_get_spec.rb
CHANGED
@@ -22,37 +22,37 @@ describe "Yajl HTTP GET request" do
|
|
22
22
|
raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
|
23
23
|
parse_off_headers(raw)
|
24
24
|
@template_hash = Yajl::Parser.parse(raw)
|
25
|
-
|
25
|
+
|
26
26
|
raw.rewind
|
27
27
|
parse_off_headers(raw)
|
28
28
|
@template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
|
29
|
-
|
29
|
+
|
30
30
|
@deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
|
31
31
|
@gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
|
32
32
|
@chunked_body = {"item"=>{"price"=>1.99, "updated_by_id"=>nil, "cached_tag_list"=>"", "name"=>"generated", "created_at"=>"2009-03-24T05:25:09Z", "cost"=>0.597, "delta"=>false, "created_by_id"=>nil, "updated_at"=>"2009-03-24T05:25:09Z", "import_tag"=>nil, "account_id"=>16, "id"=>1, "taxable"=>true, "unit"=>nil, "sku"=>"06317-0306", "company_id"=>0, "description"=>nil, "active"=>true}}
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
after(:each) do
|
36
36
|
@file_path = nil
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def prepare_mock_request_dump(format=:raw)
|
40
40
|
@request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
|
41
41
|
@uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
|
42
42
|
TCPSocket.should_receive(:new).and_return(@request)
|
43
43
|
@request.should_receive(:write)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should parse a raw response" do
|
47
47
|
prepare_mock_request_dump :raw
|
48
48
|
@template_hash.should == Yajl::HttpStream.get(@uri)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should parse a raw response and symbolize keys" do
|
52
52
|
prepare_mock_request_dump :raw
|
53
53
|
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should parse a raw response using instance method" do
|
57
57
|
prepare_mock_request_dump :raw
|
58
58
|
@uri.should_receive(:host)
|
@@ -60,7 +60,7 @@ describe "Yajl HTTP GET request" do
|
|
60
60
|
stream = Yajl::HttpStream.new
|
61
61
|
@template_hash.should == stream.get(@uri)
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it "should parse a chunked response using instance method" do
|
65
65
|
prepare_mock_request_dump :chunked
|
66
66
|
@uri.should_receive(:host)
|
@@ -70,39 +70,39 @@ describe "Yajl HTTP GET request" do
|
|
70
70
|
obj.should eql(@chunked_body)
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
if defined?(Yajl::Bzip2::StreamReader)
|
75
75
|
it "should parse a bzip2 compressed response" do
|
76
76
|
prepare_mock_request_dump :bzip2
|
77
77
|
@template_hash.should == Yajl::HttpStream.get(@uri)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it "should parse a bzip2 compressed response and symbolize keys" do
|
81
81
|
prepare_mock_request_dump :bzip2
|
82
82
|
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "should parse a deflate compressed response" do
|
87
87
|
prepare_mock_request_dump :deflate
|
88
88
|
@template_hash.should == Yajl::HttpStream.get(@uri)
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
it "should parse a deflate compressed response and symbolize keys" do
|
92
92
|
prepare_mock_request_dump :deflate
|
93
93
|
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
it "should parse a gzip compressed response" do
|
97
97
|
prepare_mock_request_dump :gzip
|
98
98
|
@template_hash.should == Yajl::HttpStream.get(@uri)
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "should parse a gzip compressed response and symbolize keys" do
|
102
102
|
prepare_mock_request_dump :gzip
|
103
103
|
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it "should raise when an HTTP code that isn't 200 is returned" do
|
107
107
|
prepare_mock_request_dump :error
|
108
108
|
lambda { Yajl::HttpStream.get(@uri) }.should raise_exception(Yajl::HttpStream::HttpError)
|
data/spec/http/http_post_spec.rb
CHANGED
@@ -22,22 +22,22 @@ describe "Yajl HTTP POST request" do
|
|
22
22
|
raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
|
23
23
|
parse_off_headers(raw)
|
24
24
|
@template_hash = Yajl::Parser.parse(raw)
|
25
|
-
|
25
|
+
|
26
26
|
raw.rewind
|
27
27
|
parse_off_headers(raw)
|
28
28
|
@template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
|
29
|
-
|
29
|
+
|
30
30
|
@deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
|
31
31
|
@gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
|
32
32
|
@body = "blah=foo&bar=baz"
|
33
33
|
@hashed_body = {:blah => 'foo', 'bar' => 'baz'}
|
34
34
|
@chunked_body = {"item"=>{"price"=>1.99, "updated_by_id"=>nil, "cached_tag_list"=>"", "name"=>"generated", "created_at"=>"2009-03-24T05:25:09Z", "cost"=>0.597, "delta"=>false, "created_by_id"=>nil, "updated_at"=>"2009-03-24T05:25:09Z", "import_tag"=>nil, "account_id"=>16, "id"=>1, "taxable"=>true, "unit"=>nil, "sku"=>"06317-0306", "company_id"=>0, "description"=>nil, "active"=>true}}
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
after(:each) do
|
38
38
|
@file_path = nil
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def prepare_mock_request_dump(format=:raw)
|
42
42
|
@request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
|
43
43
|
@uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
|
@@ -62,39 +62,39 @@ describe "Yajl HTTP POST request" do
|
|
62
62
|
prepare_mock_request_dump :raw
|
63
63
|
@template_hash.should == Yajl::HttpStream.post(@uri, @hashed_body)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
it "should parse a raw response and symbolize keys" do
|
67
67
|
prepare_mock_request_dump :raw
|
68
68
|
@template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
if defined?(Yajl::Bzip2::StreamReader)
|
72
72
|
it "should parse a bzip2 compressed response" do
|
73
73
|
prepare_mock_request_dump :bzip2
|
74
74
|
@template_hash.should == Yajl::HttpStream.post(@uri, @body)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "should parse a bzip2 compressed response and symbolize keys" do
|
78
78
|
prepare_mock_request_dump :bzip2
|
79
79
|
@template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "should parse a deflate compressed response" do
|
84
84
|
prepare_mock_request_dump :deflate
|
85
85
|
@template_hash.should == Yajl::HttpStream.post(@uri, @body)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it "should parse a deflate compressed response and symbolize keys" do
|
89
89
|
prepare_mock_request_dump :deflate
|
90
90
|
@template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should parse a gzip compressed response" do
|
94
94
|
prepare_mock_request_dump :gzip
|
95
95
|
@template_hash.should == Yajl::HttpStream.post(@uri, @body)
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "should parse a gzip compressed response and symbolize keys" do
|
99
99
|
prepare_mock_request_dump :gzip
|
100
100
|
@template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
|
@@ -116,7 +116,7 @@ describe "Yajl HTTP POST request" do
|
|
116
116
|
prepare_mock_request_dump :html
|
117
117
|
lambda {Yajl::HttpStream.post(@uri, @body)}.should raise_error(Yajl::HttpStream::InvalidContentType)
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
it "should raise when an HTTP code that isn't 200 is returned" do
|
121
121
|
prepare_mock_request_dump :error
|
122
122
|
lambda { Yajl::HttpStream.post(@uri, @body) }.should raise_exception(Yajl::HttpStream::HttpError)
|
data/spec/http/http_put_spec.rb
CHANGED
@@ -22,28 +22,28 @@ describe "Yajl HTTP PUT request" do
|
|
22
22
|
raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
|
23
23
|
parse_off_headers(raw)
|
24
24
|
@template_hash = Yajl::Parser.parse(raw)
|
25
|
-
|
25
|
+
|
26
26
|
raw.rewind
|
27
27
|
parse_off_headers(raw)
|
28
28
|
@template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
|
29
|
-
|
29
|
+
|
30
30
|
@deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
|
31
31
|
@gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
|
32
32
|
@body = "blah=foo&bar=baz"
|
33
33
|
@hashed_body = {:blah => 'foo', 'bar' => 'baz'}
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
after(:each) do
|
37
37
|
@file_path = nil
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def prepare_mock_request_dump(format=:raw)
|
41
41
|
@request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
|
42
42
|
@uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
|
43
43
|
TCPSocket.should_receive(:new).and_return(@request)
|
44
44
|
@request.should_receive(:write)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "should parse a raw response" do
|
48
48
|
prepare_mock_request_dump :raw
|
49
49
|
@template_hash.should == Yajl::HttpStream.put(@uri, @body)
|
@@ -56,49 +56,49 @@ describe "Yajl HTTP PUT request" do
|
|
56
56
|
stream = Yajl::HttpStream.new
|
57
57
|
@template_hash.should == stream.put(@uri, @body)
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "should parse a raw response with hashed body" do
|
61
61
|
prepare_mock_request_dump :raw
|
62
62
|
@template_hash.should == Yajl::HttpStream.post(@uri, @hashed_body)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "should parse a raw response and symbolize keys" do
|
66
66
|
prepare_mock_request_dump :raw
|
67
67
|
@template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
if defined?(Yajl::Bzip2::StreamReader)
|
71
71
|
it "should parse a bzip2 compressed response" do
|
72
72
|
prepare_mock_request_dump :bzip2
|
73
73
|
@template_hash.should == Yajl::HttpStream.put(@uri, @body)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
it "should parse a bzip2 compressed response and symbolize keys" do
|
77
77
|
prepare_mock_request_dump :bzip2
|
78
78
|
@template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should parse a deflate compressed response" do
|
83
83
|
prepare_mock_request_dump :deflate
|
84
84
|
@template_hash.should == Yajl::HttpStream.put(@uri, @body)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it "should parse a deflate compressed response and symbolize keys" do
|
88
88
|
prepare_mock_request_dump :deflate
|
89
89
|
@template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
it "should parse a gzip compressed response" do
|
93
93
|
prepare_mock_request_dump :gzip
|
94
94
|
@template_hash.should == Yajl::HttpStream.put(@uri, @body)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
it "should parse a gzip compressed response and symbolize keys" do
|
98
98
|
prepare_mock_request_dump :gzip
|
99
99
|
@template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it "should raise when an HTTP code that isn't 200 is returned" do
|
103
103
|
prepare_mock_request_dump :error
|
104
104
|
lambda { Yajl::HttpStream.put(@uri, @body) }.should raise_exception(Yajl::HttpStream::HttpError)
|
@@ -6,7 +6,7 @@ class Dummy; end
|
|
6
6
|
describe "JSON Gem compatability API" do
|
7
7
|
it "shoud not mixin #to_json on base objects until compatability has been enabled" do
|
8
8
|
d = Dummy.new
|
9
|
-
|
9
|
+
|
10
10
|
d.respond_to?(:to_json).should_not be_true
|
11
11
|
"".respond_to?(:to_json).should_not be_true
|
12
12
|
1.respond_to?(:to_json).should_not be_true
|
@@ -17,11 +17,11 @@ describe "JSON Gem compatability API" do
|
|
17
17
|
false.respond_to?(:to_json).should_not be_true
|
18
18
|
nil.respond_to?(:to_json).should_not be_true
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should mixin #to_json on base objects after compatability has been enabled" do
|
22
22
|
require 'yajl/json_gem'
|
23
23
|
d = Dummy.new
|
24
|
-
|
24
|
+
|
25
25
|
d.respond_to?(:to_json).should be_true
|
26
26
|
"".respond_to?(:to_json).should be_true
|
27
27
|
1.respond_to?(:to_json).should be_true
|
@@ -32,17 +32,17 @@ describe "JSON Gem compatability API" do
|
|
32
32
|
false.respond_to?(:to_json).should be_true
|
33
33
|
nil.respond_to?(:to_json).should be_true
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should require yajl/json_gem to enable the compatability API" do
|
37
37
|
defined?(JSON).should be_true
|
38
|
-
|
38
|
+
|
39
39
|
JSON.respond_to?(:parse).should be_true
|
40
40
|
JSON.respond_to?(:generate).should be_true
|
41
41
|
JSON.respond_to?(:pretty_generate).should be_true
|
42
42
|
JSON.respond_to?(:load).should be_true
|
43
43
|
JSON.respond_to?(:dump).should be_true
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should allow default parsing options be set with JSON.default_options" do
|
47
47
|
default = JSON.default_options[:symbolize_keys]
|
48
48
|
JSON.parse('{"foo": 1234}').should === {"foo" => 1234}
|
@@ -50,35 +50,35 @@ describe "JSON Gem compatability API" do
|
|
50
50
|
JSON.parse('{"foo": 1234}').should === {:foo => 1234}
|
51
51
|
JSON.default_options[:symbolize_keys] = default # ensure the rest of the test cases expect the default
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "should encode arbitrary classes via their default to_json method" do
|
55
55
|
d = Dummy.new
|
56
56
|
d.to_json.should == "\"#{d.to_s}\""
|
57
|
-
|
57
|
+
|
58
58
|
t = Time.now
|
59
59
|
t.to_json.should == "\"#{t.to_s}\""
|
60
|
-
|
60
|
+
|
61
61
|
da = Date.today
|
62
62
|
da.to_json.should == "\"#{da.to_s}\""
|
63
|
-
|
63
|
+
|
64
64
|
dt = DateTime.new
|
65
65
|
dt.to_json.should == "\"#{dt.to_s}\""
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should have the standard parsing and encoding exceptions mapped" do
|
69
69
|
JSON::JSONError.new.is_a?(StandardError).should be_true
|
70
70
|
JSON::ParserError.new.is_a?(JSON::JSONError).should be_true
|
71
71
|
JSON::GeneratorError.new.is_a?(JSON::JSONError).should be_true
|
72
|
-
|
72
|
+
|
73
73
|
lambda {
|
74
74
|
JSON.parse("blah")
|
75
75
|
}.should raise_error(JSON::ParserError)
|
76
|
-
|
76
|
+
|
77
77
|
lambda {
|
78
78
|
JSON.generate(0.0/0.0)
|
79
79
|
}.should raise_error(JSON::GeneratorError)
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
context "ported tests for Unicode" do
|
83
83
|
it "should be able to encode and parse unicode" do
|
84
84
|
'""'.should eql(''.to_json)
|
@@ -108,7 +108,7 @@ describe "JSON Gem compatability API" do
|
|
108
108
|
utf8.should eql(JSON.parse(json))
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
context "ported tests for generation" do
|
113
113
|
before(:all) do
|
114
114
|
@hash = {
|
@@ -121,9 +121,9 @@ describe "JSON Gem compatability API" do
|
|
121
121
|
'h' => 1000.0,
|
122
122
|
'i' => 0.001
|
123
123
|
}
|
124
|
-
|
124
|
+
|
125
125
|
@json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},"g":"blah","h":1000.0,"i":0.001}'
|
126
|
-
|
126
|
+
|
127
127
|
@json3 = %{
|
128
128
|
{
|
129
129
|
"a": 2,
|
@@ -137,7 +137,7 @@ describe "JSON Gem compatability API" do
|
|
137
137
|
}
|
138
138
|
}.chomp
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
it "should be able to unparse" do
|
142
142
|
json = JSON.generate(@hash)
|
143
143
|
JSON.parse(@json2).should == JSON.parse(json)
|
@@ -148,7 +148,7 @@ describe "JSON Gem compatability API" do
|
|
148
148
|
parsed_json = JSON.parse(json)
|
149
149
|
{"1"=>2}.should == parsed_json
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it "should be able to unparse pretty" do
|
153
153
|
json = JSON.pretty_generate(@hash)
|
154
154
|
JSON.parse(@json3).should == JSON.parse(json)
|
@@ -161,13 +161,13 @@ describe "JSON Gem compatability API" do
|
|
161
161
|
{"1"=>2}.should == parsed_json
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
context "ported fixture tests" do
|
166
166
|
fixtures = File.join(File.dirname(__FILE__), '../parsing/fixtures/*.json')
|
167
167
|
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
168
168
|
JSON_PASSED = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
169
169
|
JSON_FAILED = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
170
|
-
|
170
|
+
|
171
171
|
JSON_FAILED.each do |name, source|
|
172
172
|
it "should not be able to parse #{File.basename(name)} as an IO" do
|
173
173
|
lambda {
|
@@ -12,10 +12,10 @@ describe "ActiveSupport test cases" do
|
|
12
12
|
%({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
|
13
13
|
# multibyte
|
14
14
|
%({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
|
15
|
-
%({"a": "2007-01-01"}) => {'a' => "2007-01-01"},
|
16
|
-
%({"a": "2007-01-01 01:12:34 Z"}) => {'a' => "2007-01-01 01:12:34 Z"},
|
15
|
+
%({"a": "2007-01-01"}) => {'a' => "2007-01-01"},
|
16
|
+
%({"a": "2007-01-01 01:12:34 Z"}) => {'a' => "2007-01-01 01:12:34 Z"},
|
17
17
|
# no time zone
|
18
|
-
%({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
|
18
|
+
%({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
|
19
19
|
# needs to be *exact*
|
20
20
|
%({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
|
21
21
|
%({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"},
|
@@ -33,7 +33,7 @@ describe "ActiveSupport test cases" do
|
|
33
33
|
%q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"},
|
34
34
|
%q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}
|
35
35
|
}
|
36
|
-
|
36
|
+
|
37
37
|
TESTS.each do |json, expected|
|
38
38
|
it "should be able to parse #{json} as an IO" do
|
39
39
|
lambda {
|
@@ -41,7 +41,7 @@ describe "ActiveSupport test cases" do
|
|
41
41
|
}.should_not raise_error(Yajl::ParseError)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
TESTS.each do |json, expected|
|
46
46
|
it "should be able to parse #{json} as a string" do
|
47
47
|
lambda {
|
@@ -55,7 +55,7 @@ describe "ActiveSupport test cases" do
|
|
55
55
|
Yajl::Parser.parse(StringIO.new("{: 1}"))
|
56
56
|
}.should raise_error(Yajl::ParseError)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it "should fail parsing {: 1} as a string" do
|
60
60
|
lambda {
|
61
61
|
Yajl::Parser.parse("{: 1}")
|