Skip to content

Commit

Permalink
testing infra
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Mar 21, 2024
1 parent 95405f5 commit 985016f
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
103 changes: 103 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ tracing-subscriber = "0.3.18"
walkdir = "2.4.0"

[dev-dependencies]
indoc = "2.0.4"
insta = { version = "1.34.0", features = [
"redactions",
"serde",
"yaml",
"json",
] }
itertools = "0.12.1"
tempdir = "0.3.7"
txtar = "1.0.0"
90 changes: 90 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,93 @@ fn scan_several(roots: [&PathBuf; 3]) -> Result<EntriesToCompare, DataReadError>
}
Ok(result)
}

#[cfg(test)]
mod tests {
use indexmap::indexmap;
use indoc::indoc;
use itertools::Itertools;
use tempdir::TempDir;

use super::*;

fn left_right_edit_threedirinput(base: &Path) -> ThreeDirInput {
ThreeDirInput {
left: base.join("left").to_owned(),
right: base.join("right").to_owned(),
edit: base.join("edit").to_owned(),
}
}

#[test]
fn it_works() {
let tmp_dir = TempDir::new("de3test").unwrap();
txtar::from_str(indoc! {"
-- left/subdir/txt --
Some text
"})
.materialize(tmp_dir.path())
.unwrap();
let result = scan(tmp_dir.path())
.map(|(dir_path, file_type)| {
(
dir_path
.path()
.strip_prefix(tmp_dir.path())
.unwrap()
.to_owned(),
file_type,
)
})
.collect_vec();
insta::assert_yaml_snapshot!(result, @r###"
---
- - left/subdir/txt
- type: Text
value: "Some text\n"
"###);
let mut input = left_right_edit_threedirinput(tmp_dir.path());
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
---
subdir/txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Missing
"###);
let result = input.save(indexmap! {
"subdir/txt".to_string() => "".to_string()
});
insta::assert_debug_snapshot!(result, @r###"
Err(
IOError(
"/var/folders/lj/rv4h95_d0mxb9ryztzpz4qph0000gn/T/de3test.hg2lQoslcgCd/edit/subdir/txt",
Os {
code: 2,
kind: NotFound,
message: "No such file or directory",
},
),
)
"###);
let result = input.save(indexmap! {
"another_txt".to_string() => "".to_string(),
"subdir/txt".to_string() => "".to_string()
});
insta::assert_debug_snapshot!(result, @r###"
Err(
ValidationFailError(
"another_txt",
),
)
"###);
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
---
subdir/txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Missing
"###);
}
}

0 comments on commit 985016f

Please sign in to comment.