Skip to content

Commit df42a01

Browse files
committed
Move git-object tests to top-level for separation and cleanness
1 parent ec3be19 commit df42a01

20 files changed

+34
-51
lines changed

git-object/src/borrowed/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use bstr::BStr;
33
use quick_error::quick_error;
44
use std::str;
55

6-
pub(crate) mod commit;
7-
pub(crate) mod tag;
8-
pub(crate) mod tree;
9-
pub(crate) mod util;
6+
mod commit;
7+
mod tag;
8+
mod tree;
9+
mod util;
1010

1111
pub use commit::Commit;
1212
use nom::error::ParseError;
1313
pub use tag::Tag;
14-
pub use tree::Tree;
14+
pub use tree::{Entry, Mode, Tree};
1515

1616
quick_error! {
1717
#[derive(Debug)]

git-object/src/borrowed/tag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Tag<'data> {
2828
pub pgp_signature: Option<&'data BStr>,
2929
}
3030

31-
pub(crate) fn parse(i: &[u8]) -> IResult<&[u8], Tag, Error> {
31+
fn parse(i: &[u8]) -> IResult<&[u8], Tag, Error> {
3232
let (i, target) = parse_header_field(i, b"object", parse_hex_sha1)
3333
.map_err(Error::context("object <40 lowercase hex char>"))?;
3434

git-object/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
pub mod borrowed;
44
mod types;
55

6-
#[cfg(test)]
7-
mod tests;
8-
96
pub use types::*;

git-object/src/tests/borrowed/commit.rs renamed to git-object/tests/borrowed/commit.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod method {
2-
use crate::borrowed::commit::Commit;
3-
use crate::tests::borrowed::fixture_bytes;
4-
use crate::tests::hex_to_id;
2+
use crate::{borrowed::fixture_bytes, hex_to_id};
3+
use git_object::borrowed::Commit;
54
use pretty_assertions::assert_eq;
65

76
#[test]
@@ -17,17 +16,15 @@ mod method {
1716
}
1817

1918
mod parse {
20-
use crate::{
21-
borrowed::{commit::parse, commit::Commit},
22-
tests::{borrowed::fixture_bytes, borrowed::signature},
23-
};
19+
use crate::{borrowed::fixture_bytes, borrowed::signature};
2420
use bstr::ByteSlice;
21+
use git_object::borrowed::Commit;
2522
use smallvec::SmallVec;
2623

2724
#[test]
2825
fn unsigned() {
2926
assert_eq!(
30-
parse(&fixture_bytes("commit", "unsigned.txt")).unwrap().1,
27+
Commit::from_bytes(&fixture_bytes("commit", "unsigned.txt")).unwrap(),
3128
Commit {
3229
tree: b"1b2dfb4ac5e42080b682fc676e9738c94ce6d54d".as_bstr(),
3330
parents: SmallVec::default(),
@@ -43,7 +40,7 @@ mod parse {
4340
#[test]
4441
fn whitespace() {
4542
assert_eq!(
46-
parse(&fixture_bytes("commit", "whitespace.txt")).unwrap().1,
43+
Commit::from_bytes(&fixture_bytes("commit", "whitespace.txt")).unwrap(),
4744
Commit {
4845
tree: b"9bed6275068a0575243ba8409253e61af81ab2ff".as_bstr(),
4946
parents: SmallVec::from(
@@ -61,9 +58,7 @@ mod parse {
6158
#[test]
6259
fn signed_singleline() {
6360
assert_eq!(
64-
parse(&fixture_bytes("commit", "signed-singleline.txt"))
65-
.unwrap()
66-
.1,
61+
Commit::from_bytes(&fixture_bytes("commit", "signed-singleline.txt")).unwrap(),
6762
Commit {
6863
tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(),
6964
parents: SmallVec::from(
@@ -81,7 +76,7 @@ mod parse {
8176
#[test]
8277
fn signed() {
8378
assert_eq!(
84-
parse(&fixture_bytes("commit", "signed.txt")).unwrap().1,
79+
Commit::from_bytes(&fixture_bytes("commit", "signed.txt")).unwrap(),
8580
Commit {
8681
tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(),
8782
parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]),
@@ -97,7 +92,7 @@ mod parse {
9792
#[test]
9893
fn signed_with_encoding() {
9994
assert_eq!(
100-
parse(&fixture_bytes("commit", "signed-with-encoding.txt")).unwrap().1,
95+
Commit::from_bytes(&fixture_bytes("commit", "signed-with-encoding.txt")).unwrap(),
10196
Commit {
10297
tree: b"1973afa74d87b2bb73fa884aaaa8752aec43ea88".as_bstr(),
10398
parents: SmallVec::from(vec![b"79c51cc86923e2b8ca0ee5c4eb75e48027133f9a".as_bstr()]),
@@ -113,9 +108,7 @@ mod parse {
113108
#[test]
114109
fn with_encoding() {
115110
assert_eq!(
116-
parse(&fixture_bytes("commit", "with-encoding.txt"))
117-
.unwrap()
118-
.1,
111+
Commit::from_bytes(&fixture_bytes("commit", "with-encoding.txt")).unwrap(),
119112
Commit {
120113
tree: b"4a1c03029e7407c0afe9fc0320b3258e188b115e".as_bstr(),
121114
parents: SmallVec::from(
@@ -133,7 +126,7 @@ mod parse {
133126
#[test]
134127
fn merge() {
135128
assert_eq!(
136-
parse(&fixture_bytes("commit", "merge.txt")).unwrap().1,
129+
Commit::from_bytes(&fixture_bytes("commit", "merge.txt")).unwrap(),
137130
Commit {
138131
tree: b"0cf16ce8e229b59a761198975f0c0263229faf82".as_bstr(),
139132
parents: SmallVec::from(vec![

git-object/src/tests/borrowed/mod.rs renamed to git-object/tests/borrowed/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::borrowed::Signature;
1+
use git_object::borrowed::Signature;
2+
use git_object::{Sign, Time};
23
use std::path::PathBuf;
34

45
mod commit;
@@ -10,7 +11,6 @@ fn fixture_bytes(kind: &str, path: &str) -> Vec<u8> {
1011
}
1112

1213
fn signature(time: u32) -> Signature<'static> {
13-
use crate::{Sign, Time};
1414
use bstr::ByteSlice;
1515
Signature {
1616
name: b"Sebastian Thiel".as_bstr(),

git-object/src/tests/borrowed/tag.rs renamed to git-object/tests/borrowed/tag.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use crate::{
1+
use bstr::ByteSlice;
2+
use git_object::{
23
borrowed::{Signature, Tag},
34
Kind, Sign, Time,
45
};
5-
use bstr::ByteSlice;
66

77
mod method {
8-
use crate::borrowed::Tag;
9-
use crate::tests::borrowed::fixture_bytes;
10-
use crate::tests::hex_to_id;
8+
use crate::{borrowed::fixture_bytes, hex_to_id};
9+
use git_object::borrowed::Tag;
1110
use pretty_assertions::assert_eq;
1211

1312
#[test]
@@ -23,26 +22,24 @@ mod method {
2322
}
2423

2524
mod parse {
26-
use crate::{
27-
borrowed::{tag::parse, Tag},
28-
tests::borrowed::signature,
29-
tests::{borrowed::fixture_bytes, borrowed::tag::tag_fixture},
30-
Kind,
31-
};
25+
use crate::borrowed::tag::tag_fixture;
26+
use crate::{borrowed::fixture_bytes, borrowed::signature};
3227
use bstr::ByteSlice;
28+
use git_object::borrowed::Tag;
29+
use git_object::Kind;
3330

3431
#[test]
3532
fn signed() {
3633
assert_eq!(
37-
parse(&fixture_bytes("tag", "signed.txt")).unwrap().1,
34+
Tag::from_bytes(&fixture_bytes("tag", "signed.txt")).unwrap(),
3835
tag_fixture(9000)
3936
);
4037
}
4138

4239
#[test]
4340
fn empty() {
4441
assert_eq!(
45-
parse(&fixture_bytes("tag", "empty.txt")).unwrap().1,
42+
Tag::from_bytes(&fixture_bytes("tag", "empty.txt")).unwrap(),
4643
Tag {
4744
target: b"01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc".as_bstr(),
4845
name: b"empty".as_bstr(),
@@ -57,7 +54,7 @@ mod parse {
5754
#[test]
5855
fn with_newlines() {
5956
assert_eq!(
60-
parse(&fixture_bytes("tag", "with-newlines.txt")).unwrap().1,
57+
Tag::from_bytes(&fixture_bytes("tag", "with-newlines.txt")).unwrap(),
6158
Tag {
6259
target: b"ebdf205038b66108c0331aa590388431427493b7".as_bstr(),
6360
name: b"baz".as_bstr(),
@@ -72,7 +69,7 @@ mod parse {
7269
#[test]
7370
fn whitespace() {
7471
assert_eq!(
75-
parse(&fixture_bytes("tag", "whitespace.txt")).unwrap().1,
72+
Tag::from_bytes(&fixture_bytes("tag", "whitespace.txt")).unwrap(),
7673
Tag {
7774
target: b"01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc".as_bstr(),
7875
name: b"whitespace".as_bstr(),

git-object/src/tests/borrowed/tree.rs renamed to git-object/tests/borrowed/tree.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
mod parse {
2-
use crate::{
3-
borrowed::tree::Tree,
4-
borrowed::tree::{Entry, Mode},
5-
tests::borrowed::fixture_bytes,
6-
tests::hex_to_id,
7-
};
2+
use crate::{borrowed::fixture_bytes, hex_to_id};
83
use bstr::ByteSlice;
4+
use git_object::borrowed::{Entry, Mode, Tree};
95

106
#[test]
117
fn everything() {
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)