1 # Copyright 2010 Google Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 require 'google/api_client/parsers/json_parser'
20 describe Google::APIClient::JSONParser, 'generates json from hash' do
22 @parser = Google::APIClient::JSONParser
25 it 'should translate simple hash to JSON string' do
26 @parser.serialize('test' => 23).should == '{"test":23}'
29 it 'should translate simple nested into to nested JSON string' do
31 'test' => 23, 'test2' => {'foo' => 'baz', 12 => 3.14 }
33 '{"test2":{"12":3.14,"foo":"baz"},"test":23}'
37 describe Google::APIClient::JSONParser, 'parses json string into hash' do
39 @parser = Google::APIClient::JSONParser
42 it 'should parse simple json string into hash' do
43 @parser.parse('{"test":23}').should == {'test' => 23}
46 it 'should parse nested json object into hash' do
47 @parser.parse('{"test":23, "test2":{"bar":"baz", "foo":3.14}}').should == {
48 'test' => 23, 'test2' => {'bar' => 'baz', 'foo' => 3.14}