@@ -1342,3 +1342,152 @@ fn test_v1_prereqs() -> Result<(), Box<dyn Error>> {
1342
1342
1343
1343
Ok ( ( ) )
1344
1344
}
1345
+
1346
+ #[ test]
1347
+ fn test_v1_repository ( ) -> Result < ( ) , Box < dyn Error > > {
1348
+ // Load the schemas and compile the repository schema.
1349
+ let mut compiler = new_compiler ( "schema/v1" ) ?;
1350
+ let mut schemas = Schemas :: new ( ) ;
1351
+ let id = format ! ( "{SCHEMA_BASE}/repository.schema.json" ) ;
1352
+ let idx = compiler. compile ( & id, & mut schemas) ?;
1353
+
1354
+ for valid_repository in [
1355
+ ( "web" , json ! ( { "web" : "https://example.com" } ) ) ,
1356
+ (
1357
+ "type and url" ,
1358
+ json ! ( { "type" : "git" , "url" : "https://example.com" } ) ,
1359
+ ) ,
1360
+ (
1361
+ "x_ property" ,
1362
+ json ! ( { "web" : "https://example.com" , "x_y" : 0 } ) ,
1363
+ ) ,
1364
+ (
1365
+ "X_ property" ,
1366
+ json ! ( { "web" : "https://example.com" , "X_y" : 0 } ) ,
1367
+ ) ,
1368
+ ] {
1369
+ if let Err ( e) = schemas. validate ( & valid_repository. 1 , idx) {
1370
+ panic ! ( "extension {} failed: {e}" , valid_repository. 0 ) ;
1371
+ }
1372
+ }
1373
+
1374
+ for invalid_repository in [
1375
+ ( "empty array" , json ! ( [ ] ) ) ,
1376
+ ( "empty string" , json ! ( "" ) ) ,
1377
+ ( "empty string in array" , json ! ( [ "hi" , "" ] ) ) ,
1378
+ ( "true" , json ! ( true ) ) ,
1379
+ ( "false" , json ! ( false ) ) ,
1380
+ ( "null" , json ! ( null) ) ,
1381
+ ( "object" , json ! ( { } ) ) ,
1382
+ (
1383
+ "bare x_ property" ,
1384
+ json ! ( { "web" : "https://example.com" , "x_" : 0 } ) ,
1385
+ ) ,
1386
+ (
1387
+ "unknown property" ,
1388
+ json ! ( { "web" : "https://example.com" , "foo" : 0 } ) ,
1389
+ ) ,
1390
+ ( "url without type" , json ! ( { "url" : "x:y" } ) ) ,
1391
+ ( "type without url" , json ! ( { "type" : "cvs" } ) ) ,
1392
+ // web
1393
+ ( "bad web URL" , json ! ( { "web" : ":hello" } ) ) ,
1394
+ ( "web array" , json ! ( { "web" : [ "x:y" ] } ) ) ,
1395
+ ( "web object" , json ! ( { "web" : { } } ) ) ,
1396
+ ( "web bool" , json ! ( { "web" : true } ) ) ,
1397
+ ( "web number" , json ! ( { "web" : 42 } ) ) ,
1398
+ ( "web null" , json ! ( { "web" : null} ) ) ,
1399
+ // url
1400
+ ( "bad url" , json ! ( { "type" : "git" , "url" : ":hello" } ) ) ,
1401
+ ( "url array" , json ! ( { "type" : "git" , "url" : [ "x:y" ] } ) ) ,
1402
+ ( "url object" , json ! ( { "type" : "git" , "url" : { } } ) ) ,
1403
+ ( "url bool" , json ! ( { "type" : "git" , "url" : true } ) ) ,
1404
+ ( "url number" , json ! ( { "type" : "git" , "url" : 42 } ) ) ,
1405
+ ( "url null" , json ! ( { "type" : "git" , "url" : null} ) ) ,
1406
+ ] {
1407
+ if schemas. validate ( & invalid_repository. 1 , idx) . is_ok ( ) {
1408
+ panic ! ( "{} unexpectedly passed!" , invalid_repository. 0 )
1409
+ }
1410
+ }
1411
+
1412
+ Ok ( ( ) )
1413
+ }
1414
+
1415
+ #[ test]
1416
+ fn test_v1_resources ( ) -> Result < ( ) , Box < dyn Error > > {
1417
+ // Load the schemas and compile the resources schema.
1418
+ let mut compiler = new_compiler ( "schema/v1" ) ?;
1419
+ let mut schemas = Schemas :: new ( ) ;
1420
+ let id = format ! ( "{SCHEMA_BASE}/resources.schema.json" ) ;
1421
+ let idx = compiler. compile ( & id, & mut schemas) ?;
1422
+
1423
+ for valid_resources in [
1424
+ ( "homepage" , json ! ( { "homepage" : "https://example.com" } ) ) ,
1425
+ (
1426
+ "bugtracker web" ,
1427
+ json ! ( { "bugtracker" : { "web" : "https://foo.com" } } ) ,
1428
+ ) ,
1429
+ (
1430
+ "bugtracker mailto" ,
1431
+ json ! ( { "bugtracker" : { "mailto" : "[email protected] " } } ) ,
1432
+ ) ,
1433
+ (
1434
+ "repository web" ,
1435
+ json ! ( { "repository" : { "web" : "https://example.com" } } ) ,
1436
+ ) ,
1437
+ (
1438
+ "repository url and type" ,
1439
+ json ! ( { "repository" : { "type" : "git" , "url" : "https://example.com" } } ) ,
1440
+ ) ,
1441
+ ( "x_ property" , json ! ( { "homepage" : "x:y" , "x_y" : 0 } ) ) ,
1442
+ ( "X_ property" , json ! ( { "homepage" : "x:y" , "X_y" : 0 } ) ) ,
1443
+ ] {
1444
+ if let Err ( e) = schemas. validate ( & valid_resources. 1 , idx) {
1445
+ panic ! ( "extension {} failed: {e}" , valid_resources. 0 ) ;
1446
+ }
1447
+ }
1448
+
1449
+ for invalid_resources in [
1450
+ ( "empty array" , json ! ( [ ] ) ) ,
1451
+ ( "empty string" , json ! ( "" ) ) ,
1452
+ ( "empty string in array" , json ! ( [ "hi" , "" ] ) ) ,
1453
+ ( "true" , json ! ( true ) ) ,
1454
+ ( "false" , json ! ( false ) ) ,
1455
+ ( "null" , json ! ( null) ) ,
1456
+ ( "empty object" , json ! ( { } ) ) ,
1457
+ ( "bare x_ property" , json ! ( { "homepage" : "x:y" , "x_" : 0 } ) ) ,
1458
+ ( "unknown property" , json ! ( { "homepage" : "x:y" , "foo" : 0 } ) ) ,
1459
+ // homepage
1460
+ ( "bad homepage url" , json ! ( { "homepage" : ":hi" } ) ) ,
1461
+ ( "homepage array" , json ! ( { "homepage" : [ "x:y" ] } ) ) ,
1462
+ ( "homepage object" , json ! ( { "homepage" : { } } ) ) ,
1463
+ ( "homepage bool" , json ! ( { "homepage" : true } ) ) ,
1464
+ ( "homepage number" , json ! ( { "homepage" : 42 } ) ) ,
1465
+ ( "homepage null" , json ! ( { "homepage" : null} ) ) ,
1466
+ // bugtracker
1467
+ (
1468
+ "bad bugtracker url" ,
1469
+ json ! ( { "bugtracker" : { "web" : "3ttp://a.com" } } ) ,
1470
+ ) ,
1471
+ ( "bugtracker array" , json ! ( { "bugtracker" : [ "x:y" ] } ) ) ,
1472
+ ( "bugtracker empty object" , json ! ( { "bugtracker" : { } } ) ) ,
1473
+ ( "bugtracker bool" , json ! ( { "bugtracker" : true } ) ) ,
1474
+ ( "bugtracker number" , json ! ( { "bugtracker" : 42 } ) ) ,
1475
+ ( "bugtracker null" , json ! ( { "bugtracker" : null} ) ) ,
1476
+ // repository
1477
+ (
1478
+ "bad repository url" ,
1479
+ json ! ( { "repository" : { "web" : "3ttp://a.com" } } ) ,
1480
+ ) ,
1481
+ ( "repository array" , json ! ( { "repository" : [ "x:y" ] } ) ) ,
1482
+ ( "repository empty object" , json ! ( { "repository" : { } } ) ) ,
1483
+ ( "repository bool" , json ! ( { "repository" : true } ) ) ,
1484
+ ( "repository number" , json ! ( { "repository" : 42 } ) ) ,
1485
+ ( "repository null" , json ! ( { "repository" : null} ) ) ,
1486
+ ] {
1487
+ if schemas. validate ( & invalid_resources. 1 , idx) . is_ok ( ) {
1488
+ panic ! ( "{} unexpectedly passed!" , invalid_resources. 0 )
1489
+ }
1490
+ }
1491
+
1492
+ Ok ( ( ) )
1493
+ }
0 commit comments