@@ -110,11 +110,7 @@ impl License {
110110impl Validate for License {
111111 fn validate_version ( & self , version : SpecVersion ) -> ValidationResult {
112112 ValidationContext :: new ( )
113- . add_field (
114- "license_identifier" ,
115- & self . license_identifier ,
116- validate_license_identifier,
117- )
113+ . add_struct ( "license_identifier" , & self . license_identifier , version)
118114 . add_struct_option ( "text" , self . text . as_ref ( ) , version)
119115 . add_field_option ( "url" , self . url . as_ref ( ) , validate_uri)
120116 . into ( )
@@ -154,14 +150,16 @@ impl Validate for LicenseIdentifier {
154150 . add_enum ( "Name" , name, validate_normalized_string)
155151 . into ( ) ,
156152 LicenseIdentifier :: SpdxId ( id) => ValidationContext :: new ( )
157- . add_field ( "SpdxId" , id, validate_spdx_identifier)
153+ . add_enum ( "SpdxId" , id, validate_spdx_identifier)
158154 . into ( ) ,
159155 }
160156 }
161157}
162158
163159#[ cfg( test) ]
164160mod test {
161+ use crate :: validation;
162+
165163 use super :: * ;
166164 use pretty_assertions:: assert_eq;
167165
@@ -186,30 +184,25 @@ mod test {
186184 } ) ] )
187185 . validate ( ) ;
188186
189- /*
190187 assert_eq ! (
191188 validation_result,
192- ValidationResult::Failed {
193- reasons: vec![FailureReason {
194- message: "NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
195- .to_string(),
196- context: ValidationContext(vec![
197- ValidationPathComponent::Array { index: 0 },
198- ValidationPathComponent::EnumVariant {
199- variant_name: "License".to_string()
200- },
201- ValidationPathComponent::Struct {
202- struct_name: "License".to_string(),
203- field_name: "license_identifier".to_string(),
204- },
205- ValidationPathComponent::EnumVariant {
206- variant_name: "Name".to_string()
207- },
208- ])
209- }]
210- }
189+ validation:: list(
190+ "inner" ,
191+ [ (
192+ 0 ,
193+ validation:: r#struct(
194+ "license" ,
195+ validation:: r#struct(
196+ "license_identifier" ,
197+ validation:: r#enum(
198+ "Name" ,
199+ "NormalizedString contains invalid characters \\ r \\ n \\ t or \\ r\\ n"
200+ )
201+ )
202+ )
203+ ) ]
204+ )
211205 ) ;
212- */
213206 }
214207
215208 #[ test]
@@ -221,29 +214,22 @@ mod test {
221214 } ) ] )
222215 . validate ( ) ;
223216
224- /*
225217 assert_eq ! (
226218 validation_result,
227- ValidationResult::Failed {
228- reasons: vec![FailureReason {
229- message: "SPDX identifier is not valid".to_string(),
230- context: ValidationContext(vec![
231- ValidationPathComponent::Array { index: 0 },
232- ValidationPathComponent::EnumVariant {
233- variant_name: "License".to_string()
234- },
235- ValidationPathComponent::Struct {
236- struct_name: "License".to_string(),
237- field_name: "license_identifier".to_string(),
238- },
239- ValidationPathComponent::EnumVariant {
240- variant_name: "SpdxId".to_string()
241- },
242- ])
243- }]
244- }
219+ validation:: list(
220+ "inner" ,
221+ [ (
222+ 0 ,
223+ validation:: r#struct(
224+ "license" ,
225+ validation:: r#struct(
226+ "license_identifier" ,
227+ validation:: r#enum( "SpdxId" , "SPDX identifier is not valid" )
228+ )
229+ )
230+ ) ]
231+ )
245232 ) ;
246- */
247233 }
248234
249235 #[ test]
@@ -253,22 +239,16 @@ mod test {
253239 ) ) ] )
254240 . validate ( ) ;
255241
256- /*
257242 assert_eq ! (
258243 validation_result,
259- ValidationResult::Failed {
260- reasons: vec![FailureReason {
261- message: "SPDX expression is not valid".to_string(),
262- context: ValidationContext(vec![
263- ValidationPathComponent::Array { index: 0 },
264- ValidationPathComponent::EnumVariant {
265- variant_name: "Expression".to_string()
266- }
267- ])
268- }]
269- }
244+ validation:: list(
245+ "inner" ,
246+ [ (
247+ 0 ,
248+ validation:: r#enum( "expression" , "SPDX expression is not valid" )
249+ ) ] ,
250+ )
270251 ) ;
271- */
272252 }
273253
274254 #[ test]
@@ -296,49 +276,34 @@ mod test {
296276 ] )
297277 . validate ( ) ;
298278
299- /*
300279 assert_eq ! (
301280 validation_result,
302- ValidationResult::Failed {
303- reasons: vec![
304- FailureReason {
305- message:
306- "NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
307- .to_string(),
308- context: ValidationContext(vec![
309- ValidationPathComponent::Array { index: 1 },
310- ValidationPathComponent::EnumVariant {
311- variant_name: "License".to_string()
312- },
313- ValidationPathComponent::Struct {
314- struct_name: "License".to_string(),
315- field_name: "license_identifier".to_string(),
316- },
317- ValidationPathComponent::EnumVariant {
318- variant_name: "Name".to_string()
319- },
320- ])
321- },
322- FailureReason {
323- message: "SPDX identifier is not valid".to_string(),
324- context: ValidationContext(vec![
325- ValidationPathComponent::Array { index: 2 },
326- ValidationPathComponent::EnumVariant {
327- variant_name: "License".to_string()
328- },
329- ValidationPathComponent::Struct {
330- struct_name: "License".to_string(),
331- field_name: "license_identifier".to_string(),
332- },
333- ValidationPathComponent::EnumVariant {
334- variant_name: "SpdxId".to_string()
335- },
336- ])
337- }
338- ]
339- }
281+ validation:: list(
282+ "inner" ,
283+ [ (
284+ 1 ,
285+ validation:: r#struct(
286+ "license" ,
287+ validation:: r#struct(
288+ "license_identifier" ,
289+ validation:: r#enum(
290+ "Name" ,
291+ "NormalizedString contains invalid characters \\ r \\ n \\ t or \\ r\\ n"
292+ )
293+ )
294+ )
295+ ) , (
296+ 2 ,
297+ validation:: r#struct(
298+ "license" ,
299+ validation:: r#struct(
300+ "license_identifier" ,
301+ validation:: r#enum( "SpdxId" , "SPDX identifier is not valid" )
302+ )
303+ )
304+ ) ]
305+ )
340306 ) ;
341- */
342307 }
343308
344309 #[ test]
@@ -350,32 +315,21 @@ mod test {
350315 ] )
351316 . validate ( ) ;
352317
353- /*
354318 assert_eq ! (
355319 validation_result,
356- ValidationResult::Failed {
357- reasons: vec![
358- FailureReason {
359- message: "SPDX expression is not valid".to_string(),
360- context: ValidationContext(vec![
361- ValidationPathComponent::Array { index: 1 },
362- ValidationPathComponent::EnumVariant {
363- variant_name: "Expression".to_string()
364- }
365- ])
366- },
367- FailureReason {
368- message: "SPDX expression is not valid".to_string(),
369- context: ValidationContext(vec![
370- ValidationPathComponent::Array { index: 2 },
371- ValidationPathComponent::EnumVariant {
372- variant_name: "Expression".to_string()
373- }
374- ])
375- }
320+ validation:: list(
321+ "inner" ,
322+ [
323+ (
324+ 1 ,
325+ validation:: r#enum( "expression" , "SPDX expression is not valid" ) ,
326+ ) ,
327+ (
328+ 2 ,
329+ validation:: r#enum( "expression" , "SPDX expression is not valid" ) ,
330+ )
376331 ]
377- }
332+ )
378333 ) ;
379- */
380334 }
381335}
0 commit comments