Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b86012b

Browse files
committed
loose fixtures are usable more easily now
1 parent 2da5a62 commit b86012b

3 files changed

Lines changed: 28 additions & 20 deletions

File tree

git-index/tests/index/file/read.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::path::{Path, PathBuf};
22

3+
use crate::loose_file_path;
34
use bstr::ByteSlice;
45
use git_index::{entry, Version};
56
use git_testtools::hex_to_id;
@@ -13,10 +14,6 @@ fn verify(index: git_index::File) -> git_index::File {
1314
index
1415
}
1516

16-
pub(crate) fn loose_file_path(name: &str) -> PathBuf {
17-
git_testtools::fixture_path(Path::new("loose_index").join(name).with_extension("git-index"))
18-
}
19-
2017
pub(crate) fn loose_file(name: &str) -> git_index::File {
2118
let path = loose_file_path(name);
2219
let file = git_index::File::at(path, git_index::decode::Options::default()).unwrap();

git-index/tests/index/file/write.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1+
use crate::index::Fixture::*;
12
use filetime::FileTime;
23
use git_index::{decode, entry, extension, verify::extensions::no_find, write, write::Options, State, Version};
34

4-
use crate::{fixture_index_path, index::file::read::loose_file_path};
5+
use crate::{fixture_index_path, loose_file_path};
56

67
/// Round-trips should eventually be possible for all files we have, as we write them back exactly as they were read.
78
#[test]
89
fn roundtrips() -> crate::Result {
9-
enum Kind {
10-
Generated(&'static str),
11-
Loose(&'static str),
12-
}
13-
use Kind::*;
1410
let input = [
1511
(Loose("extended-flags"), all_ext_but_eoie()),
1612
(Loose("conflicting-file"), all_ext_but_eoie()),
@@ -54,12 +50,6 @@ fn state_comparisons_with_various_extension_configurations() {
5450
}
5551
}
5652

57-
enum Kind {
58-
Generated(&'static str),
59-
Loose(&'static str),
60-
}
61-
use Kind::*;
62-
6353
for fixture in [
6454
Loose("extended-flags"),
6555
Loose("conflicting-file"),
@@ -87,10 +77,8 @@ fn state_comparisons_with_various_extension_configurations() {
8777
end_of_index_entry: true,
8878
}),
8979
] {
90-
let (path, fixture) = match fixture {
91-
Generated(name) => (fixture_index_path(name), name),
92-
Loose(name) => (loose_file_path(name), name),
93-
};
80+
let path = fixture.to_path();
81+
let fixture = fixture.to_name();
9482
let expected = git_index::File::at(&path, Default::default()).unwrap();
9583

9684
let mut out = Vec::<u8>::new();

git-index/tests/index/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ pub fn fixture_index_path(name: &str) -> PathBuf {
99
dir.join(".git").join("index")
1010
}
1111

12+
pub fn loose_file_path(name: &str) -> PathBuf {
13+
git_testtools::fixture_path(Path::new("loose_index").join(name).with_extension("git-index"))
14+
}
15+
1216
#[test]
1317
fn size_of_entry() {
1418
assert_eq!(std::mem::size_of::<git_index::Entry>(), 80);
@@ -17,3 +21,22 @@ fn size_of_entry() {
1721
assert_eq!(std::mem::size_of::<git_index::entry::Time>(), 8);
1822
assert_eq!(std::mem::size_of::<filetime::FileTime>(), 16);
1923
}
24+
25+
enum Fixture {
26+
Generated(&'static str),
27+
Loose(&'static str),
28+
}
29+
30+
impl Fixture {
31+
pub fn to_path(&self) -> PathBuf {
32+
match self {
33+
Fixture::Generated(name) => fixture_index_path(name),
34+
Fixture::Loose(name) => loose_file_path(name),
35+
}
36+
}
37+
pub fn to_name(&self) -> &'static str {
38+
match self {
39+
Fixture::Generated(name) | Fixture::Loose(name) => name,
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)