@@ -10,9 +10,11 @@ use serde_json::{json, Map, Value};
10
10
mod common;
11
11
use common:: * ;
12
12
13
+ const SCHEMA_VERSION : u8 = 1 ;
14
+
13
15
#[ test]
14
16
fn test_schema_v1 ( ) -> Result < ( ) , Box < dyn Error > > {
15
- test_schema_version ( 1 )
17
+ test_schema_version ( SCHEMA_VERSION )
16
18
}
17
19
18
20
#[ derive( Deserialize , Serialize ) ]
@@ -27,7 +29,7 @@ fn test_corpus_v1_valid() -> Result<(), Box<dyn Error>> {
27
29
// Load the schemas and compile the root schema.
28
30
let mut compiler = new_compiler ( "schema/v1" ) ?;
29
31
let mut schemas = Schemas :: new ( ) ;
30
- let id = id_for ( 1 , "distribution" ) ;
32
+ let id = id_for ( SCHEMA_VERSION , "distribution" ) ;
31
33
let index = compiler. compile ( & id, & mut schemas) ?;
32
34
33
35
// Test each meta JSON in the corpus.
@@ -50,7 +52,7 @@ fn test_corpus_v1_invalid() -> Result<(), Box<dyn Error>> {
50
52
// Load the schemas and compile the root schema.
51
53
let mut compiler = new_compiler ( "schema/v1" ) ?;
52
54
let mut schemas = Schemas :: new ( ) ;
53
- let id = id_for ( 1 , "distribution" ) ;
55
+ let id = id_for ( SCHEMA_VERSION , "distribution" ) ;
54
56
let index = compiler. compile ( & id, & mut schemas) ?;
55
57
56
58
// Test each meta JSON in the corpus.
@@ -75,22 +77,22 @@ fn test_corpus_v1_invalid() -> Result<(), Box<dyn Error>> {
75
77
fn test_v1_term ( ) -> Result < ( ) , Box < dyn Error > > {
76
78
// Load the schemas and compile the term schema.
77
79
let compiler = new_compiler ( "schema/v1" ) ?;
78
- test_term_schema ( compiler, 1 )
80
+ test_term_schema ( compiler, SCHEMA_VERSION )
79
81
}
80
82
81
83
#[ test]
82
84
fn test_v1_tags ( ) -> Result < ( ) , Box < dyn Error > > {
83
85
// Load the schemas and compile the tags schema.
84
86
let compiler = new_compiler ( "schema/v1" ) ?;
85
- test_tags_schema ( compiler, 1 )
87
+ test_tags_schema ( compiler, SCHEMA_VERSION )
86
88
}
87
89
88
90
#[ test]
89
91
fn test_v1_version ( ) -> Result < ( ) , Box < dyn Error > > {
90
92
// Load the schemas and compile the version schema.
91
93
let mut compiler = new_compiler ( "schema/v1" ) ?;
92
94
let mut schemas = Schemas :: new ( ) ;
93
- let id = id_for ( 1 , "version" ) ;
95
+ let id = id_for ( SCHEMA_VERSION , "version" ) ;
94
96
let idx = compiler. compile ( & id, & mut schemas) ?;
95
97
96
98
for valid_version in VALID_SEMVERS {
@@ -115,7 +117,7 @@ fn test_v1_version_range() -> Result<(), Box<dyn Error>> {
115
117
// Load the schemas and compile the version_range schema.
116
118
let mut compiler = new_compiler ( "schema/v1" ) ?;
117
119
let mut schemas = Schemas :: new ( ) ;
118
- let id = id_for ( 1 , "version_range" ) ;
120
+ let id = id_for ( SCHEMA_VERSION , "version_range" ) ;
119
121
let idx = compiler. compile ( & id, & mut schemas) ?;
120
122
121
123
for valid_version in VALID_SEMVERS {
@@ -186,7 +188,7 @@ fn test_v1_license() -> Result<(), Box<dyn Error>> {
186
188
// Load the schemas and compile the license schema.
187
189
let mut compiler = new_compiler ( "schema/v1" ) ?;
188
190
let mut schemas = Schemas :: new ( ) ;
189
- let id = id_for ( 1 , "license" ) ;
191
+ let id = id_for ( SCHEMA_VERSION , "license" ) ;
190
192
let idx = compiler. compile ( & id, & mut schemas) ?;
191
193
192
194
// Test valid license values.
@@ -254,7 +256,7 @@ fn test_v1_provides() -> Result<(), Box<dyn Error>> {
254
256
// Load the schemas and compile the provides schema.
255
257
let mut compiler = new_compiler ( "schema/v1" ) ?;
256
258
let mut schemas = Schemas :: new ( ) ;
257
- let id = id_for ( 1 , "provides" ) ;
259
+ let id = id_for ( SCHEMA_VERSION , "provides" ) ;
258
260
let idx = compiler. compile ( & id, & mut schemas) ?;
259
261
260
262
for valid_provides in [
@@ -353,7 +355,7 @@ fn test_v1_extension() -> Result<(), Box<dyn Error>> {
353
355
// Load the schemas and compile the extension schema.
354
356
let mut compiler = new_compiler ( "schema/v1" ) ?;
355
357
let mut schemas = Schemas :: new ( ) ;
356
- let id = id_for ( 1 , "extension" ) ;
358
+ let id = id_for ( SCHEMA_VERSION , "extension" ) ;
357
359
let idx = compiler. compile ( & id, & mut schemas) ?;
358
360
359
361
for valid_extension in [
@@ -529,7 +531,7 @@ fn test_v1_maintainer() -> Result<(), Box<dyn Error>> {
529
531
// Load the schemas and compile the maintainer schema.
530
532
let mut compiler = new_compiler ( "schema/v1" ) ?;
531
533
let mut schemas = Schemas :: new ( ) ;
532
- let id = id_for ( 1 , "maintainer" ) ;
534
+ let id = id_for ( SCHEMA_VERSION , "maintainer" ) ;
533
535
let idx = compiler. compile ( & id, & mut schemas) ?;
534
536
535
537
for valid_maintainer in [
@@ -578,7 +580,7 @@ fn test_v1_meta_spec() -> Result<(), Box<dyn Error>> {
578
580
// Load the schemas and compile the maintainer schema.
579
581
let mut compiler = new_compiler ( "schema/v1" ) ?;
580
582
let mut schemas = Schemas :: new ( ) ;
581
- let id = id_for ( 1 , "meta-spec" ) ;
583
+ let id = id_for ( SCHEMA_VERSION , "meta-spec" ) ;
582
584
let idx = compiler. compile ( & id, & mut schemas) ?;
583
585
584
586
for valid_meta_spec in [
@@ -632,7 +634,7 @@ fn test_v1_bugtracker() -> Result<(), Box<dyn Error>> {
632
634
// Load the schemas and compile the maintainer schema.
633
635
let mut compiler = new_compiler ( "schema/v1" ) ?;
634
636
let mut schemas = Schemas :: new ( ) ;
635
- let id = id_for ( 1 , "bugtracker" ) ;
637
+ let id = id_for ( SCHEMA_VERSION , "bugtracker" ) ;
636
638
let idx = compiler. compile ( & id, & mut schemas) ?;
637
639
638
640
for valid_bugtracker in [
@@ -686,7 +688,7 @@ fn test_v1_no_index() -> Result<(), Box<dyn Error>> {
686
688
// Load the schemas and compile the maintainer schema.
687
689
let mut compiler = new_compiler ( "schema/v1" ) ?;
688
690
let mut schemas = Schemas :: new ( ) ;
689
- let id = id_for ( 1 , "no_index" ) ;
691
+ let id = id_for ( SCHEMA_VERSION , "no_index" ) ;
690
692
let idx = compiler. compile ( & id, & mut schemas) ?;
691
693
692
694
for valid_no_index in [
@@ -751,7 +753,7 @@ fn test_v1_prereq_relationship() -> Result<(), Box<dyn Error>> {
751
753
// Load the schemas and compile the maintainer schema.
752
754
let mut compiler = new_compiler ( "schema/v1" ) ?;
753
755
let mut schemas = Schemas :: new ( ) ;
754
- let id = id_for ( 1 , "prereq_relationship" ) ;
756
+ let id = id_for ( SCHEMA_VERSION , "prereq_relationship" ) ;
755
757
let idx = compiler. compile ( & id, & mut schemas) ?;
756
758
757
759
for valid_prereq_relationship in [
@@ -804,7 +806,7 @@ fn test_v1_prereq_phase() -> Result<(), Box<dyn Error>> {
804
806
// Load the schemas and compile the maintainer schema.
805
807
let mut compiler = new_compiler ( "schema/v1" ) ?;
806
808
let mut schemas = Schemas :: new ( ) ;
807
- let id = id_for ( 1 , "prereq_phase" ) ;
809
+ let id = id_for ( SCHEMA_VERSION , "prereq_phase" ) ;
808
810
let idx = compiler. compile ( & id, & mut schemas) ?;
809
811
810
812
for valid_prereq_phase in [
@@ -916,7 +918,7 @@ fn test_v1_prereqs() -> Result<(), Box<dyn Error>> {
916
918
// Load the schemas and compile the maintainer schema.
917
919
let mut compiler = new_compiler ( "schema/v1" ) ?;
918
920
let mut schemas = Schemas :: new ( ) ;
919
- let id = id_for ( 1 , "prereqs" ) ;
921
+ let id = id_for ( SCHEMA_VERSION , "prereqs" ) ;
920
922
let idx = compiler. compile ( & id, & mut schemas) ?;
921
923
922
924
for valid_prereqs in [
@@ -1064,7 +1066,7 @@ fn test_v1_repository() -> Result<(), Box<dyn Error>> {
1064
1066
// Load the schemas and compile the repository schema.
1065
1067
let mut compiler = new_compiler ( "schema/v1" ) ?;
1066
1068
let mut schemas = Schemas :: new ( ) ;
1067
- let id = id_for ( 1 , "repository" ) ;
1069
+ let id = id_for ( SCHEMA_VERSION , "repository" ) ;
1068
1070
let idx = compiler. compile ( & id, & mut schemas) ?;
1069
1071
1070
1072
for valid_repository in [
@@ -1141,7 +1143,7 @@ fn test_v1_resources() -> Result<(), Box<dyn Error>> {
1141
1143
// Load the schemas and compile the resources schema.
1142
1144
let mut compiler = new_compiler ( "schema/v1" ) ?;
1143
1145
let mut schemas = Schemas :: new ( ) ;
1144
- let id = id_for ( 1 , "resources" ) ;
1146
+ let id = id_for ( SCHEMA_VERSION , "resources" ) ;
1145
1147
let idx = compiler. compile ( & id, & mut schemas) ?;
1146
1148
1147
1149
for valid_resources in [
@@ -1278,7 +1280,7 @@ fn test_v1_distribution() -> Result<(), Box<dyn Error>> {
1278
1280
// Load the schemas and compile the distribution schema.
1279
1281
let mut compiler = new_compiler ( "schema/v1" ) ?;
1280
1282
let mut schemas = Schemas :: new ( ) ;
1281
- let id = id_for ( 1 , "distribution" ) ;
1283
+ let id = id_for ( SCHEMA_VERSION , "distribution" ) ;
1282
1284
let idx = compiler. compile ( & id, & mut schemas) ?;
1283
1285
1284
1286
// Make sure the valid distribution is in fact valid.
0 commit comments