@@ -125,97 +125,92 @@ mod tests {
125125 use crate :: schema:: { DecodeContext , EncodeContext , JsonSchema } ;
126126
127127 #[ test]
128- fn text_into_data_raw ( ) {
128+ fn text_into_data_raw ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
129129 let mut engine = Engine :: new ( ) ;
130130 engine. register ( JsonCodec ) ;
131131 engine. register ( TextCodec ) ;
132132
133133 let input = "This is just a long long string" ;
134- let result = engine
135- . convert (
136- input. as_bytes ( ) ,
137- Format :: Text ,
138- Format :: Json ,
139- & DecodeContext :: default ( ) ,
140- & EncodeContext :: default ( ) ,
141- )
142- . unwrap ( ) ;
134+ let result = engine. convert (
135+ input. as_bytes ( ) ,
136+ Format :: Text ,
137+ Format :: Json ,
138+ & DecodeContext ,
139+ & EncodeContext :: default ( ) ,
140+ ) ?;
143141
144142 assert_eq ! ( result, br#""This is just a long long string""# ) ;
143+ Ok ( ( ) )
145144 }
146145
147146 #[ test]
148- fn normalizing_text_to_data_wraps_the_text_as_a_string ( ) {
147+ fn normalizing_text_to_data_wraps_the_text_as_a_string ( )
148+ -> Result < ( ) , Box < dyn std:: error:: Error > > {
149149 let engine = Engine :: new ( ) ;
150150
151151 assert_eq ! (
152- engine
153- . normalize_for_target(
154- Artifact :: Text ( "unstructured" . to_string( ) ) ,
155- ArtifactKind :: Data ,
156- )
157- . unwrap( ) ,
152+ engine. normalize_for_target(
153+ Artifact :: Text ( "unstructured" . to_string( ) ) ,
154+ ArtifactKind :: Data ,
155+ ) ?,
158156 Artifact :: Data ( Data :: String ( "unstructured" . to_string( ) ) )
159157 ) ;
158+ Ok ( ( ) )
160159 }
161160
162161 #[ test]
163- fn json_xml_json_round_trip_does_not_add_formatting_text ( ) {
162+ fn json_xml_json_round_trip_does_not_add_formatting_text ( )
163+ -> Result < ( ) , Box < dyn std:: error:: Error > > {
164164 let mut engine = Engine :: new ( ) ;
165165 engine. register ( JsonCodec ) ;
166166 engine. register ( XmlCodec ) ;
167- let decode_ctx = DecodeContext :: default ( ) ;
167+ let decode_ctx = DecodeContext ;
168168 let encode_ctx = EncodeContext :: default ( ) ;
169169 let json =
170170 br#"{"user":{"@id":"7","email":["ada@example.com","ada@work.example"],"name":"Ada"}}"# ;
171171
172- let xml = engine
173- . convert ( json, Format :: Json , Format :: Xml , & decode_ctx, & encode_ctx)
174- . unwrap ( ) ;
172+ let xml = engine. convert ( json, Format :: Json , Format :: Xml , & decode_ctx, & encode_ctx) ?;
175173 assert_eq ! (
176174 xml,
177175 br#"<user id="7"><email>ada@example.com</email><email>ada@work.example</email><name>Ada</name></user>"#
178176 ) ;
179177
180- let result = engine
181- . convert ( & xml, Format :: Xml , Format :: Json , & decode_ctx, & encode_ctx)
182- . unwrap ( ) ;
178+ let result = engine. convert ( & xml, Format :: Xml , Format :: Json , & decode_ctx, & encode_ctx) ?;
183179 assert_eq ! ( result, json) ;
180+ Ok ( ( ) )
184181 }
185182
186183 #[ test]
187- fn codecs_pretty_print_structured_output_when_requested ( ) {
184+ fn codecs_pretty_print_structured_output_when_requested ( )
185+ -> Result < ( ) , Box < dyn std:: error:: Error > > {
188186 let mut engine = Engine :: new ( ) ;
189187 engine. register ( JsonCodec ) ;
190188 engine. register ( XmlCodec ) ;
191- let decode_ctx = DecodeContext :: default ( ) ;
189+ let decode_ctx = DecodeContext ;
192190 let encode_ctx = EncodeContext { pretty : true } ;
193191
194- let xml = engine
195- . convert (
196- br#"{"user":{"name":"Ada","email":"ada@example.com"}}"# ,
197- Format :: Json ,
198- Format :: Xml ,
199- & decode_ctx,
200- & encode_ctx,
201- )
202- . unwrap ( ) ;
192+ let xml = engine. convert (
193+ br#"{"user":{"name":"Ada","email":"ada@example.com"}}"# ,
194+ Format :: Json ,
195+ Format :: Xml ,
196+ & decode_ctx,
197+ & encode_ctx,
198+ ) ?;
203199 assert_eq ! (
204200 xml,
205201 b"<user>\n <email>ada@example.com</email>\n <name>Ada</name>\n </user>"
206202 ) ;
207203
208- let json = engine
209- . convert ( & xml, Format :: Xml , Format :: Json , & decode_ctx, & encode_ctx)
210- . unwrap ( ) ;
204+ let json = engine. convert ( & xml, Format :: Xml , Format :: Json , & decode_ctx, & encode_ctx) ?;
211205 assert_eq ! (
212206 json,
213207 b"{\n \" user\" : {\n \" email\" : \" ada@example.com\" ,\n \" name\" : \" Ada\" \n }\n }"
214208 ) ;
209+ Ok ( ( ) )
215210 }
216211
217212 #[ test]
218- fn canonical_xml_array_converts_to_csv ( ) {
213+ fn canonical_xml_array_converts_to_csv ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
219214 let mut engine = Engine :: new ( ) ;
220215 engine. register ( XmlCodec ) ;
221216 engine. register ( CsvCodec ) ;
@@ -230,24 +225,24 @@ mod tests {
230225 </item>
231226</data>"# ;
232227
233- let csv = engine
234- . convert (
235- xml,
236- Format :: Xml ,
237- Format :: Csv ,
238- & DecodeContext :: default ( ) ,
239- & EncodeContext :: default ( ) ,
240- )
241- . unwrap ( ) ;
228+ let csv = engine. convert (
229+ xml,
230+ Format :: Xml ,
231+ Format :: Csv ,
232+ & DecodeContext ,
233+ & EncodeContext :: default ( ) ,
234+ ) ?;
242235
243236 assert_eq ! (
244237 csv,
245238 b"email,name\n ada@example.com,Ada Lovelace\n grace@example.com,Grace Hopper\n "
246239 ) ;
240+ Ok ( ( ) )
247241 }
248242
249243 #[ test]
250- fn validate_decodes_xml_before_applying_json_schema ( ) {
244+ fn validate_decodes_xml_before_applying_json_schema ( ) -> Result < ( ) , Box < dyn std:: error:: Error > >
245+ {
251246 let mut engine = Engine :: new ( ) ;
252247 engine. register ( XmlCodec ) ;
253248 let schema = JsonSchema {
@@ -268,13 +263,12 @@ mod tests {
268263 . to_string ( ) ,
269264 } ;
270265
271- engine
272- . validate (
273- b"<user><name>Ada</name></user>" ,
274- Format :: Xml ,
275- & schema,
276- & DecodeContext :: default ( ) ,
277- )
278- . unwrap ( ) ;
266+ engine. validate (
267+ b"<user><name>Ada</name></user>" ,
268+ Format :: Xml ,
269+ & schema,
270+ & DecodeContext ,
271+ ) ?;
272+ Ok ( ( ) )
279273 }
280274}
0 commit comments