Skip to content

Commit 8dd7128

Browse files
committed
split testsuite into files
1 parent 1c6b1cb commit 8dd7128

12 files changed

+71
-48
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ thiserror = "1.0.40"
3030
build-binary = ["clap", "anyhow"]
3131

3232
[dev-dependencies]
33-
insta = "1.29.0"
33+
insta = { version = "1.29.0", features = ["glob"] }

src/lib.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,53 +40,6 @@ mod tests {
4040

4141
use insta::assert_debug_snapshot;
4242

43-
#[test]
44-
fn nothing() {
45-
let lhs = json! {{ "type": "string" }};
46-
let rhs = json! {{ "type": "string" }};
47-
48-
let diff = diff(lhs, rhs).unwrap();
49-
50-
assert_debug_snapshot!(
51-
diff,
52-
@"[]"
53-
);
54-
}
55-
56-
#[test]
57-
fn basic() {
58-
let lhs = json! {{ "type": "string" }};
59-
let rhs = json! {{ "type": "number" }};
60-
61-
let diff = diff(lhs, rhs).unwrap();
62-
63-
assert_debug_snapshot!(
64-
diff,
65-
@r###"
66-
[
67-
Change {
68-
path: "",
69-
change: TypeRemove {
70-
removed: String,
71-
},
72-
},
73-
Change {
74-
path: "",
75-
change: TypeAdd {
76-
added: Number,
77-
},
78-
},
79-
Change {
80-
path: "",
81-
change: TypeAdd {
82-
added: Integer,
83-
},
84-
},
85-
]
86-
"###
87-
);
88-
}
89-
9043
#[test]
9144
fn extend_type() {
9245
let lhs = json! {{ "type": "string" }};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"anyOf": [{"type": "string"}]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "string"
3+
}

tests/fixtures/basic/basic.lhs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "type": "string" }

tests/fixtures/basic/basic.rhs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "type": "number" }

tests/fixtures/basic/nothing.lhs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "type": "string" }

tests/fixtures/basic/nothing.rhs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "type": "string" }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: tests/test.rs
3+
expression: diff
4+
input_file: tests/fixtures/any_of/to_equivalent_type.lhs.json
5+
---
6+
[]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
source: tests/test.rs
3+
expression: diff
4+
input_file: tests/fixtures/basic/basic.lhs.json
5+
---
6+
[
7+
Change {
8+
path: "",
9+
change: TypeRemove {
10+
removed: String,
11+
},
12+
},
13+
Change {
14+
path: "",
15+
change: TypeAdd {
16+
added: Number,
17+
},
18+
},
19+
Change {
20+
path: "",
21+
change: TypeAdd {
22+
added: Integer,
23+
},
24+
},
25+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: tests/test.rs
3+
expression: diff
4+
input_file: tests/fixtures/basic/nothing.lhs.json
5+
---
6+
[]

tests/test.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use insta::{assert_debug_snapshot, glob};
2+
use json_schema_diff::diff;
3+
use serde_json::Value;
4+
5+
#[test]
6+
fn test_from_fixtures() {
7+
let test = |path_for_lhs: &std::path::Path| {
8+
let contents = std::fs::read_to_string(path_for_lhs).unwrap();
9+
let lhs: Value = serde_json::from_str(&contents).unwrap();
10+
let rhs_filename = path_for_lhs
11+
.file_name()
12+
.unwrap()
13+
.to_str()
14+
.unwrap()
15+
.replace(".lhs.json", ".rhs.json");
16+
let contents =
17+
std::fs::read_to_string(path_for_lhs.parent().unwrap().join(rhs_filename)).unwrap();
18+
let rhs: Value = serde_json::from_str(&contents).unwrap();
19+
let diff = diff(lhs, rhs).unwrap();
20+
assert_debug_snapshot!(diff);
21+
};
22+
glob!("../tests/fixtures", "**/*.lhs.json", test);
23+
}

0 commit comments

Comments
 (0)