Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 27, 2024
1 parent 7715a01 commit 2de74de
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/schematic/tests/__fixtures__/pkl/five.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vector = List("x", "y", "z")
2 changes: 2 additions & 0 deletions crates/schematic/tests/__fixtures__/pkl/four.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boolean = false
number = 123
1 change: 1 addition & 0 deletions crates/schematic/tests/__fixtures__/pkl/one.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
string = "foo"
2 changes: 2 additions & 0 deletions crates/schematic/tests/__fixtures__/pkl/three.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boolean = true
string = "bar"
1 change: 1 addition & 0 deletions crates/schematic/tests/__fixtures__/pkl/two.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vector = List("a", "b", "c")
41 changes: 41 additions & 0 deletions crates/schematic/tests/file_sources_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,47 @@ fn loads_json_file_optional() {
assert_eq!(result.config.number, 0);
}

#[cfg(feature = "pkl")]
#[test]
fn loads_pkl_files() {
let root = get_fixture_path("pkl");

let result = ConfigLoader::<Config>::new()
.file(root.join("one.pkl"))
.unwrap()
.file(root.join("two.pkl"))
.unwrap()
.file(root.join("three.pkl"))
.unwrap()
.file(root.join("four.pkl"))
.unwrap()
.file(root.join("five.pkl"))
.unwrap()
.load()
.unwrap();

assert!(!result.config.boolean);
assert_eq!(result.config.string, "bar");
assert_eq!(result.config.number, 123);
assert_eq!(result.config.vector, vec!["x", "y", "z"]);
}

#[cfg(feature = "pkl")]
#[test]
fn loads_pkl_file_optional() {
let root = get_fixture_path("pkl");

let result = ConfigLoader::<Config>::new()
.file_optional(root.join("missing.pkl"))
.unwrap()
.load()
.unwrap();

assert!(!result.config.boolean);
assert_eq!(result.config.string, "");
assert_eq!(result.config.number, 0);
}

#[cfg(feature = "toml")]
#[test]
fn loads_toml_files() {
Expand Down

0 comments on commit 2de74de

Please sign in to comment.