33require_relative '../spec_helper'
44
55module Smithy
6- module CBOR
6+ module Cbor
77 describe Codec do
88 let ( :structure_shape ) { SchemaHelper . sample_schema . const_get ( :Structure ) }
99
10- it 'serialize returns nil when given a unit shape' do
11- expect ( subject . serialize ( Schema ::Shapes ::Prelude ::Unit , '' ) ) . to be_nil
10+ it 'build returns nil when given a unit shape' do
11+ expect ( subject . build ( Schema ::Shapes ::Prelude ::Unit , '' ) ) . to be_nil
1212 end
1313
14- it 'deserializes returns an empty hash when given bytes are empty' do
15- expect ( subject . deserialize ( Schema ::Shapes ::Prelude ::String , '' ) ) . to be_empty
14+ it 'parses returns an empty hash when given bytes are empty' do
15+ expect ( subject . parse ( Schema ::Shapes ::Prelude ::String , '' ) ) . to be_empty
1616 end
1717
18- it 'deserializes returns an empty hash when given a unit shape' do
19- expect ( subject . deserialize ( Schema ::Shapes ::Prelude ::Unit , '' ) ) . to be_empty
18+ it 'parses returns an empty hash when given a unit shape' do
19+ expect ( subject . parse ( Schema ::Shapes ::Prelude ::Unit , '' ) ) . to be_empty
2020 end
2121
22- it 'serializes and deserializes data' do
22+ it 'builds and parses data' do
2323 time = Time . now
2424 allow ( Time ) . to receive ( :at ) . and_return ( time )
2525 data = {
@@ -45,95 +45,95 @@ module CBOR
4545 union : { string : 'string' }
4646 }
4747 data = data . merge ( structure : data )
48- bytes = subject . serialize ( structure_shape , data )
49- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
48+ bytes = subject . build ( structure_shape , data )
49+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
5050 end
5151
5252 context 'structures' do
53- it 'serializes and deserializes structures as a type' do
53+ it 'builds and parses structures as a type' do
5454 type = structure_shape . type . new ( string : 'string' )
55- bytes = subject . serialize ( structure_shape , type )
56- expect ( subject . deserialize ( structure_shape , bytes ) . string ) . to eq ( 'string' )
55+ bytes = subject . build ( structure_shape , type )
56+ expect ( subject . parse ( structure_shape , bytes ) . string ) . to eq ( 'string' )
5757 end
5858
59- it 'serializes and deserializes structures as a hash' do
59+ it 'builds and parses structures as a hash' do
6060 data = { string : 'string' }
61- bytes = subject . serialize ( structure_shape , data )
62- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
61+ bytes = subject . build ( structure_shape , data )
62+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
6363 end
6464 end
6565
6666 context 'unions' do
67- it 'serializes and deserializes union as a type' do
67+ it 'builds and parses union as a type' do
6868 union = structure_shape . member ( :union ) . shape . member_type ( :string ) . new ( string : 'string' )
6969 type = structure_shape . type . new ( union : union )
70- bytes = subject . serialize ( structure_shape , type )
71- expect ( subject . deserialize ( structure_shape , bytes ) . union ) . to eq ( union )
70+ bytes = subject . build ( structure_shape , type )
71+ expect ( subject . parse ( structure_shape , bytes ) . union ) . to eq ( union )
7272 end
7373
74- it 'serializes and deserializes union as a hash' do
74+ it 'builds and parses union as a hash' do
7575 data = { union : { string : 'string' } }
76- bytes = subject . serialize ( structure_shape , data )
77- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
76+ bytes = subject . build ( structure_shape , data )
77+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
7878 end
7979
80- it 'serializes and deserializes unit members as a type' do
80+ it 'builds and parses unit members as a type' do
8181 union = structure_shape . member ( :union ) . shape . member_type ( :unit ) . new ( unit : Schema ::EmptyStructure . new )
8282 type = structure_shape . type . new ( union : union )
83- bytes = subject . serialize ( structure_shape , type )
84- expect ( subject . deserialize ( structure_shape , bytes ) . union ) . to eq ( union )
83+ bytes = subject . build ( structure_shape , type )
84+ expect ( subject . parse ( structure_shape , bytes ) . union ) . to eq ( union )
8585 end
8686
87- it 'serializes and deserializes unit members as a hash' do
87+ it 'builds and parses unit members as a hash' do
8888 data = { union : { unit : { } } }
89- bytes = subject . serialize ( structure_shape , data )
90- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
89+ bytes = subject . build ( structure_shape , data )
90+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
9191 end
9292
93- it 'serializes a nil union' do
93+ it 'builds a nil union' do
9494 data = { union : nil }
95- bytes = subject . serialize ( structure_shape , data )
96- expect ( subject . deserialize ( structure_shape , bytes ) . union ) . to eq ( nil )
95+ bytes = subject . build ( structure_shape , data )
96+ expect ( subject . parse ( structure_shape , bytes ) . union ) . to eq ( nil )
9797 end
9898
99- it 'deserializes unknown union members' do
99+ it 'parses unknown union members' do
100100 unknown_union_type = structure_shape . member ( :union ) . shape . member_type ( :unknown )
101101 data = { union : { 'someThing' => 'someValue' } }
102- deserialized = subject . deserialize ( structure_shape , CBOR . encode ( data ) )
103- expect ( deserialized . union ) . to be_a ( unknown_union_type )
104- expect ( deserialized . union . to_h ) . to eq ( unknown : { 'someThing' => 'someValue' } )
102+ parsed = subject . parse ( structure_shape , Cbor . encode ( data ) )
103+ expect ( parsed . union ) . to be_a ( unknown_union_type )
104+ expect ( parsed . union . to_h ) . to eq ( unknown : { 'someThing' => 'someValue' } )
105105 end
106106 end
107107
108108 context 'lists' do
109- it 'serializes and deserializes lists' do
109+ it 'builds and parses lists' do
110110 data = { list : [ 'string' ] }
111- bytes = subject . serialize ( structure_shape , data )
112- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
111+ bytes = subject . build ( structure_shape , data )
112+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
113113 end
114114
115115 it 'can handle sparse lists' do
116116 list_shape = structure_shape . member ( :list ) . shape
117117 list_shape . traits . merge! ( 'smithy.api#sparse' => { } )
118118 data = { list : [ nil ] }
119- bytes = subject . serialize ( structure_shape , data )
120- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
119+ bytes = subject . build ( structure_shape , data )
120+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
121121 end
122122 end
123123
124124 context 'maps' do
125- it 'serializes and deserializes maps' do
125+ it 'builds and parses maps' do
126126 data = { map : { 'key' => 'value' } }
127- bytes = subject . serialize ( structure_shape , data )
128- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
127+ bytes = subject . build ( structure_shape , data )
128+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
129129 end
130130
131131 it 'can handle sparse maps' do
132132 map_shape = structure_shape . member ( :map ) . shape
133133 map_shape . traits . merge! ( 'smithy.api#sparse' => { } )
134134 data = { map : { 'key' => nil } }
135- bytes = subject . serialize ( structure_shape , data )
136- expect ( subject . deserialize ( structure_shape , bytes ) . to_h ) . to eq ( data )
135+ bytes = subject . build ( structure_shape , data )
136+ expect ( subject . parse ( structure_shape , bytes ) . to_h ) . to eq ( data )
137137 end
138138 end
139139 end
0 commit comments