Skip to content

Commit 11845c8

Browse files
committed
Use constant
1 parent 007a834 commit 11845c8

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

tests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn test_tags_schema(mut compiler: Compiler, version: u8) -> Result<(), Box<d
207207
Ok(())
208208
}
209209

210-
pub fn test_schema_version(version: i8) -> Result<(), Box<dyn Error>> {
210+
pub fn test_schema_version(version: u8) -> Result<(), Box<dyn Error>> {
211211
let mut compiler = Compiler::new();
212212
compiler.enable_format_assertions();
213213
let mut loaded: HashMap<String, Vec<Value>> = HashMap::new();

tests/v1_schema_test.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ use serde_json::{json, Map, Value};
1010
mod common;
1111
use common::*;
1212

13+
const SCHEMA_VERSION: u8 = 1;
14+
1315
#[test]
1416
fn test_schema_v1() -> Result<(), Box<dyn Error>> {
15-
test_schema_version(1)
17+
test_schema_version(SCHEMA_VERSION)
1618
}
1719

1820
#[derive(Deserialize, Serialize)]
@@ -27,7 +29,7 @@ fn test_corpus_v1_valid() -> Result<(), Box<dyn Error>> {
2729
// Load the schemas and compile the root schema.
2830
let mut compiler = new_compiler("schema/v1")?;
2931
let mut schemas = Schemas::new();
30-
let id = id_for(1, "distribution");
32+
let id = id_for(SCHEMA_VERSION, "distribution");
3133
let index = compiler.compile(&id, &mut schemas)?;
3234

3335
// Test each meta JSON in the corpus.
@@ -50,7 +52,7 @@ fn test_corpus_v1_invalid() -> Result<(), Box<dyn Error>> {
5052
// Load the schemas and compile the root schema.
5153
let mut compiler = new_compiler("schema/v1")?;
5254
let mut schemas = Schemas::new();
53-
let id = id_for(1, "distribution");
55+
let id = id_for(SCHEMA_VERSION, "distribution");
5456
let index = compiler.compile(&id, &mut schemas)?;
5557

5658
// Test each meta JSON in the corpus.
@@ -75,22 +77,22 @@ fn test_corpus_v1_invalid() -> Result<(), Box<dyn Error>> {
7577
fn test_v1_term() -> Result<(), Box<dyn Error>> {
7678
// Load the schemas and compile the term schema.
7779
let compiler = new_compiler("schema/v1")?;
78-
test_term_schema(compiler, 1)
80+
test_term_schema(compiler, SCHEMA_VERSION)
7981
}
8082

8183
#[test]
8284
fn test_v1_tags() -> Result<(), Box<dyn Error>> {
8385
// Load the schemas and compile the tags schema.
8486
let compiler = new_compiler("schema/v1")?;
85-
test_tags_schema(compiler, 1)
87+
test_tags_schema(compiler, SCHEMA_VERSION)
8688
}
8789

8890
#[test]
8991
fn test_v1_version() -> Result<(), Box<dyn Error>> {
9092
// Load the schemas and compile the version schema.
9193
let mut compiler = new_compiler("schema/v1")?;
9294
let mut schemas = Schemas::new();
93-
let id = id_for(1, "version");
95+
let id = id_for(SCHEMA_VERSION, "version");
9496
let idx = compiler.compile(&id, &mut schemas)?;
9597

9698
for valid_version in VALID_SEMVERS {
@@ -115,7 +117,7 @@ fn test_v1_version_range() -> Result<(), Box<dyn Error>> {
115117
// Load the schemas and compile the version_range schema.
116118
let mut compiler = new_compiler("schema/v1")?;
117119
let mut schemas = Schemas::new();
118-
let id = id_for(1, "version_range");
120+
let id = id_for(SCHEMA_VERSION, "version_range");
119121
let idx = compiler.compile(&id, &mut schemas)?;
120122

121123
for valid_version in VALID_SEMVERS {
@@ -186,7 +188,7 @@ fn test_v1_license() -> Result<(), Box<dyn Error>> {
186188
// Load the schemas and compile the license schema.
187189
let mut compiler = new_compiler("schema/v1")?;
188190
let mut schemas = Schemas::new();
189-
let id = id_for(1, "license");
191+
let id = id_for(SCHEMA_VERSION, "license");
190192
let idx = compiler.compile(&id, &mut schemas)?;
191193

192194
// Test valid license values.
@@ -254,7 +256,7 @@ fn test_v1_provides() -> Result<(), Box<dyn Error>> {
254256
// Load the schemas and compile the provides schema.
255257
let mut compiler = new_compiler("schema/v1")?;
256258
let mut schemas = Schemas::new();
257-
let id = id_for(1, "provides");
259+
let id = id_for(SCHEMA_VERSION, "provides");
258260
let idx = compiler.compile(&id, &mut schemas)?;
259261

260262
for valid_provides in [
@@ -353,7 +355,7 @@ fn test_v1_extension() -> Result<(), Box<dyn Error>> {
353355
// Load the schemas and compile the extension schema.
354356
let mut compiler = new_compiler("schema/v1")?;
355357
let mut schemas = Schemas::new();
356-
let id = id_for(1, "extension");
358+
let id = id_for(SCHEMA_VERSION, "extension");
357359
let idx = compiler.compile(&id, &mut schemas)?;
358360

359361
for valid_extension in [
@@ -529,7 +531,7 @@ fn test_v1_maintainer() -> Result<(), Box<dyn Error>> {
529531
// Load the schemas and compile the maintainer schema.
530532
let mut compiler = new_compiler("schema/v1")?;
531533
let mut schemas = Schemas::new();
532-
let id = id_for(1, "maintainer");
534+
let id = id_for(SCHEMA_VERSION, "maintainer");
533535
let idx = compiler.compile(&id, &mut schemas)?;
534536

535537
for valid_maintainer in [
@@ -578,7 +580,7 @@ fn test_v1_meta_spec() -> Result<(), Box<dyn Error>> {
578580
// Load the schemas and compile the maintainer schema.
579581
let mut compiler = new_compiler("schema/v1")?;
580582
let mut schemas = Schemas::new();
581-
let id = id_for(1, "meta-spec");
583+
let id = id_for(SCHEMA_VERSION, "meta-spec");
582584
let idx = compiler.compile(&id, &mut schemas)?;
583585

584586
for valid_meta_spec in [
@@ -632,7 +634,7 @@ fn test_v1_bugtracker() -> Result<(), Box<dyn Error>> {
632634
// Load the schemas and compile the maintainer schema.
633635
let mut compiler = new_compiler("schema/v1")?;
634636
let mut schemas = Schemas::new();
635-
let id = id_for(1, "bugtracker");
637+
let id = id_for(SCHEMA_VERSION, "bugtracker");
636638
let idx = compiler.compile(&id, &mut schemas)?;
637639

638640
for valid_bugtracker in [
@@ -686,7 +688,7 @@ fn test_v1_no_index() -> Result<(), Box<dyn Error>> {
686688
// Load the schemas and compile the maintainer schema.
687689
let mut compiler = new_compiler("schema/v1")?;
688690
let mut schemas = Schemas::new();
689-
let id = id_for(1, "no_index");
691+
let id = id_for(SCHEMA_VERSION, "no_index");
690692
let idx = compiler.compile(&id, &mut schemas)?;
691693

692694
for valid_no_index in [
@@ -751,7 +753,7 @@ fn test_v1_prereq_relationship() -> Result<(), Box<dyn Error>> {
751753
// Load the schemas and compile the maintainer schema.
752754
let mut compiler = new_compiler("schema/v1")?;
753755
let mut schemas = Schemas::new();
754-
let id = id_for(1, "prereq_relationship");
756+
let id = id_for(SCHEMA_VERSION, "prereq_relationship");
755757
let idx = compiler.compile(&id, &mut schemas)?;
756758

757759
for valid_prereq_relationship in [
@@ -804,7 +806,7 @@ fn test_v1_prereq_phase() -> Result<(), Box<dyn Error>> {
804806
// Load the schemas and compile the maintainer schema.
805807
let mut compiler = new_compiler("schema/v1")?;
806808
let mut schemas = Schemas::new();
807-
let id = id_for(1, "prereq_phase");
809+
let id = id_for(SCHEMA_VERSION, "prereq_phase");
808810
let idx = compiler.compile(&id, &mut schemas)?;
809811

810812
for valid_prereq_phase in [
@@ -916,7 +918,7 @@ fn test_v1_prereqs() -> Result<(), Box<dyn Error>> {
916918
// Load the schemas and compile the maintainer schema.
917919
let mut compiler = new_compiler("schema/v1")?;
918920
let mut schemas = Schemas::new();
919-
let id = id_for(1, "prereqs");
921+
let id = id_for(SCHEMA_VERSION, "prereqs");
920922
let idx = compiler.compile(&id, &mut schemas)?;
921923

922924
for valid_prereqs in [
@@ -1064,7 +1066,7 @@ fn test_v1_repository() -> Result<(), Box<dyn Error>> {
10641066
// Load the schemas and compile the repository schema.
10651067
let mut compiler = new_compiler("schema/v1")?;
10661068
let mut schemas = Schemas::new();
1067-
let id = id_for(1, "repository");
1069+
let id = id_for(SCHEMA_VERSION, "repository");
10681070
let idx = compiler.compile(&id, &mut schemas)?;
10691071

10701072
for valid_repository in [
@@ -1141,7 +1143,7 @@ fn test_v1_resources() -> Result<(), Box<dyn Error>> {
11411143
// Load the schemas and compile the resources schema.
11421144
let mut compiler = new_compiler("schema/v1")?;
11431145
let mut schemas = Schemas::new();
1144-
let id = id_for(1, "resources");
1146+
let id = id_for(SCHEMA_VERSION, "resources");
11451147
let idx = compiler.compile(&id, &mut schemas)?;
11461148

11471149
for valid_resources in [
@@ -1278,7 +1280,7 @@ fn test_v1_distribution() -> Result<(), Box<dyn Error>> {
12781280
// Load the schemas and compile the distribution schema.
12791281
let mut compiler = new_compiler("schema/v1")?;
12801282
let mut schemas = Schemas::new();
1281-
let id = id_for(1, "distribution");
1283+
let id = id_for(SCHEMA_VERSION, "distribution");
12821284
let idx = compiler.compile(&id, &mut schemas)?;
12831285

12841286
// Make sure the valid distribution is in fact valid.

tests/v2_schema_test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,33 @@ use serde_json::json;
77
mod common;
88
use common::*;
99

10+
const SCHEMA_VERSION: u8 = 2;
11+
1012
#[test]
1113
fn test_schema_v1() -> Result<(), Box<dyn Error>> {
12-
test_schema_version(2)
14+
test_schema_version(SCHEMA_VERSION)
1315
}
1416

1517
#[test]
1618
fn test_v2_term() -> Result<(), Box<dyn Error>> {
1719
// Load the schemas and compile the term schema.
1820
let compiler = new_compiler("schema/v2")?;
19-
test_term_schema(compiler, 2)
21+
test_term_schema(compiler, SCHEMA_VERSION)
2022
}
2123

2224
#[test]
2325
fn test_v2_tags() -> Result<(), Box<dyn Error>> {
2426
// Load the schemas and compile the tags schema.
2527
let compiler = new_compiler("schema/v2")?;
26-
test_tags_schema(compiler, 2)
28+
test_tags_schema(compiler, SCHEMA_VERSION)
2729
}
2830

2931
#[test]
3032
fn test_v2_semver() -> Result<(), Box<dyn Error>> {
3133
// Load the schemas and compile the semver schema.
3234
let mut compiler = new_compiler("schema/v2")?;
3335
let mut schemas = Schemas::new();
34-
let id = id_for(2, "semver");
36+
let id = id_for(SCHEMA_VERSION, "semver");
3537
let idx = compiler.compile(&id, &mut schemas)?;
3638

3739
for valid_version in VALID_SEMVERS {

0 commit comments

Comments
 (0)