Skip to content

Commit

Permalink
Widnows attempt #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Mar 21, 2024
1 parent d3a54f4 commit 463d67a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 101 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ insta = { version = "1.34.0", features = [
"json",
] }
itertools = "0.12.1"
path-slash = "0.2.1"
tempdir = "0.3.7"
txtar = "1.0.0"
217 changes: 116 additions & 101 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ mod tests {
use indexmap::IndexMap;
use indoc::indoc;
use itertools::Itertools;
use path_slash::*;
use serde::Serialize;
use tempdir::TempDir;

Expand All @@ -160,13 +161,27 @@ mod tests {
scan(path)
.map(|(dir_path, file_type)| {
(
dir_path.path().strip_prefix(path).unwrap().to_owned(),
dir_path
.path()
.strip_prefix(path)
.unwrap()
.to_slash_lossy()
.to_string(),
file_type,
)
})
.collect_vec()
}

fn showscan(input: &ThreeDirInput) -> impl Serialize {
let entries = input.scan().unwrap();
entries
.0
.into_iter()
.map(|(k, v)| (k.to_slash_lossy().to_string(), v))
.collect_vec()
}

fn left_right_edit_threedirinput(base: &Path) -> ThreeDirInput {
ThreeDirInput {
left: base.join("left").to_owned(),
Expand Down Expand Up @@ -211,43 +226,43 @@ mod tests {
"###);
// TODO: A different bug if edit/subdir/another_file is specified
let mut input = left_right_edit_threedirinput(tmp_dir.path());
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
subdir/txt:
- type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: "Changed text for editing\n"
- - subdir/txt
- - type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: "Changed text for editing\n"
"###);
let () = input
.save(IndexMap::from([string_pair("subdir/txt", "Edited text")]))
.unwrap();
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
subdir/txt:
- type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: Edited text
- - subdir/txt
- - type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: Edited text
"###);

// If the file exists on all sides, an empty save means an empty file.
let () = input
.save(IndexMap::from([string_pair("subdir/txt", "")]))
.unwrap();
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
subdir/txt:
- type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: ""
- - subdir/txt
- - type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: ""
"###);

// Test a validation error
Expand All @@ -263,15 +278,15 @@ mod tests {
)
"###);
// Should be the same as previous version
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
subdir/txt:
- type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: ""
- - subdir/txt
- - type: Text
value: "Some text\n"
- type: Text
value: "Changed text\n"
- type: Text
value: ""
"###);
}

Expand All @@ -293,40 +308,40 @@ mod tests {
value: "Some text for editing\n"
"###);
let mut input = left_right_edit_threedirinput(tmp_dir.path());
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
txt:
- type: Missing
- type: Text
value: "Some text\n"
- type: Text
value: "Some text for editing\n"
- - txt
- - type: Missing
- type: Text
value: "Some text\n"
- type: Text
value: "Some text for editing\n"
"###);
let () = input
.save(IndexMap::from([string_pair("txt", "somevalue")]))
.unwrap();
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
txt:
- type: Missing
- type: Text
value: "Some text\n"
- type: Text
value: somevalue
- - txt
- - type: Missing
- type: Text
value: "Some text\n"
- type: Text
value: somevalue
"###);
// TODO: If the file is missing on LHS, an empty save should mean that the file
// should be deleted.
let () = input
.save(IndexMap::from([string_pair("txt", "")]))
.unwrap();
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
txt:
- type: Missing
- type: Text
value: "Some text\n"
- type: Text
value: ""
- - txt
- - type: Missing
- type: Text
value: "Some text\n"
- type: Text
value: ""
"###);
}

Expand All @@ -343,13 +358,13 @@ mod tests {
value: "Some text\n"
"###);
let mut input = left_right_edit_threedirinput(tmp_dir.path());
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Missing
- - txt
- - type: Text
value: "Some text\n"
- type: Missing
- type: Missing
"###);
let result = input.save(IndexMap::from([string_pair("txt", "somevalue")]));
// BUG: We fail to create `right/txt` because `right/` does not exist
Expand All @@ -367,13 +382,13 @@ mod tests {
if path.ends_with("txt") &&
err.kind() == ErrorKind::NotFound
);
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Missing
- - txt
- - type: Text
value: "Some text\n"
- type: Missing
- type: Missing
"###);
}

Expand All @@ -395,54 +410,54 @@ mod tests {
value: "Doesn't matter what goes here\n"
"###);
let mut input = left_right_edit_threedirinput(tmp_dir.path());
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
randomfile:
- type: Missing
- type: Missing
- type: Text
value: "Doesn't matter what goes here\n"
txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Missing
- - randomfile
- - type: Missing
- type: Missing
- type: Text
value: "Doesn't matter what goes here\n"
- - txt
- - type: Text
value: "Some text\n"
- type: Missing
- type: Missing
"###);
let () = input
.save(IndexMap::from([string_pair("txt", "somevalue")]))
.unwrap();
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
randomfile:
- type: Missing
- type: Missing
- type: Text
value: "Doesn't matter what goes here\n"
txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Text
value: somevalue
- - randomfile
- - type: Missing
- type: Missing
- type: Text
value: "Doesn't matter what goes here\n"
- - txt
- - type: Text
value: "Some text\n"
- type: Missing
- type: Text
value: somevalue
"###);
// TODO: If the file is missing on RHS, an empty save should mean that the file
// should stay (or be) deleted.
let () = input
.save(IndexMap::from([string_pair("txt", "")]))
.unwrap();
insta::assert_yaml_snapshot!(input.scan().unwrap(), @r###"
insta::assert_yaml_snapshot!(showscan(&input), @r###"
---
randomfile:
- type: Missing
- type: Missing
- type: Text
value: "Doesn't matter what goes here\n"
txt:
- type: Text
value: "Some text\n"
- type: Missing
- type: Text
value: ""
- - randomfile
- - type: Missing
- type: Missing
- type: Text
value: "Doesn't matter what goes here\n"
- - txt
- - type: Text
value: "Some text\n"
- type: Missing
- type: Text
value: ""
"###);
}
}

0 comments on commit 463d67a

Please sign in to comment.