Unified · Split
| @@ -38,8 +38,3 @@ impl Kind { · 37 unmodified lines | ||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | pub mod parsed; |
| 41 | − | |
| 42 | −#[cfg(test)] | |
| 43 | −mod tests { | |
| 44 | − use super::*; | |
| 45 | −} | |
| @@ -2,6 +2,9 @@ use crate::{object, Sign, Time}; · 1 unmodified line | ||
| 2 | 2 | use hex::FromHex; |
| 3 | 3 | use std::str; |
| 4 | 4 | |
| 5 | +#[cfg(test)] | |
| 6 | +mod tests; | |
| 7 | + | |
| 5 | 8 | quick_error! { |
| 6 | 9 | #[derive(Debug)] |
| 7 | 10 | pub enum Error { |
| @@ -0,0 +1,64 @@ | ||
| 1 | +use super::*; | |
| 2 | +use crate::object::{parsed, Kind}; | |
| 3 | +use std::path::PathBuf; | |
| 4 | + | |
| 5 | +pub fn bin(hex: &str) -> [u8; 20] { | |
| 6 | + <[u8; 20]>::from_hex(hex).unwrap() | |
| 7 | +} | |
| 8 | + | |
| 9 | +pub fn fixture(path: &str) -> PathBuf { | |
| 10 | + PathBuf::from("tests").join("fixtures").join(path) | |
| 11 | +} | |
| 12 | + | |
| 13 | +fn fixture_bytes(path: &str) -> Vec<u8> { | |
| 14 | + std::fs::read(fixture(path)).unwrap() | |
| 15 | +} | |
| 16 | + | |
| 17 | +#[test] | |
| 18 | +fn tag_parse() { | |
| 19 | + let fixture = fixture_bytes("objects/tag.txt"); | |
| 20 | + let actual = parsed::Tag::from_bytes(&fixture).unwrap(); | |
| 21 | + assert_eq!(actual, tag_fixture(9000)); | |
| 22 | + assert_eq!( | |
| 23 | + actual.target(), | |
| 24 | + bin("ffa700b4aca13b80cb6b98a078e7c96804f8e0ec") | |
| 25 | + ); | |
| 26 | +} | |
| 27 | + | |
| 28 | +fn tag_fixture(offset: i32) -> parsed::Tag<'static> { | |
| 29 | + parsed::Tag { | |
| 30 | + target_raw: b"ffa700b4aca13b80cb6b98a078e7c96804f8e0ec", | |
| 31 | + name_raw: b"1.0.0", | |
| 32 | + target_kind: Kind::Commit, | |
| 33 | + message: Some(b"for the signature\n"), | |
| 34 | + pgp_signature: Some( | |
| 35 | + b"-----BEGIN PGP SIGNATURE----- | |
| 36 | +Comment: GPGTools - https://gpgtools.org | |
| 37 | + | |
| 38 | +iQIzBAABCgAdFiEEw7xSvXbiwjusbsBqZl+Z+p2ZlmwFAlsapyYACgkQZl+Z+p2Z | |
| 39 | +lmy6Ug/+KzvzqiNpzz1bMVVAzp8NCbiEO3QGYPyeQc521lBwpaTrRYR+oHJY15r3 | |
| 40 | +OdL5WDysTpjN8N5FNyfmvzkuPdTkK3JlYmO7VRjdA2xu/B6vIZLaOfAowFrhMvKo | |
| 41 | +8eoqwGcAP3rC5TuWEgzq2qhbjS4JXFLd4NLjWEFqT2Y2UKm+g8TeGOsa/0pF4Nq5 | |
| 42 | +xeW4qCYR0WcQLFedbpkKHxag2GfaXKvzNNJdqYhVQssNa6BeSmsfDvlWYNe617wV | |
| 43 | +NvsR/zJT0wHb5SSH+h6QmwA7LQIQF//83Vc3aF7kv9D54r3ibXW5TjZ3WoeTUZO7 | |
| 44 | +kefkzJ12EYDCFLPhHvXPog518nO8Ot46dX+okrF0/B4N3RFTvjKr7VAGTzv2D/Dg | |
| 45 | +DrD531S2F71b+JIRh641eeP7bjWFQi3tWLtrEOtjjsKPJfYRMKpYFnAO4UUJ6Rck | |
| 46 | +Z5fFXEUCO8d5WT56jzKDjmVoY01lA87O1YsP/J+zQAlc9v1k6jqeQ53LZNgTN+ue | |
| 47 | +5fJuSPT3T43pSOD1VQSr3aZ2Anc4Qu7K8uX9lkpxF9Sc0tDbeCosFLZMWNVp6m+e | |
| 48 | +cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB | |
| 49 | +2n8f2douw6624Tn/6Lm4a7AoxmU+CMiYagDxDL3RuZ8CAfh3bn0= | |
| 50 | +=aIns | |
| 51 | +-----END PGP SIGNATURE----- | |
| 52 | +", | |
| 53 | + ), | |
| 54 | + signature: parsed::Signature { | |
| 55 | + name: b"Sebastian Thiel", | |
| 56 | + email: b"byronimo@gmail.com", | |
| 57 | + time: Time { | |
| 58 | + time: 1528473343, | |
| 59 | + offset, | |
| 60 | + sign: Sign::Plus, | |
| 61 | + }, | |
| 62 | + }, | |
| 63 | + } | |
| 64 | +} | |
| @@ -37,27 +37,6 @@ fn loose_iter() { · 36 unmodified lines | ||
| 37 | 37 | ) |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | −#[test] | |
| 41 | −fn loose_find() { | |
| 42 | − let mut o = ldb() | |
| 43 | − .find(&bin("722fe60ad4f0276d5a8121970b5bb9dccdad4ef9")) | |
| 44 | − .unwrap(); | |
| 45 | − assert_eq!(o.kind, Kind::Tag); | |
| 46 | − assert_eq!(o.size, 1024); | |
| 47 | − assert_eq!(o.parsed().unwrap(), parsed::Object::Tag(tag_fixture(7200))) | |
| 48 | −} | |
| 49 | − | |
| 50 | −#[test] | |
| 51 | −fn loose_tag_parse() { | |
| 52 | − let fixture = fixture_bytes("objects/tag.txt"); | |
| 53 | − let actual = parsed::Tag::from_bytes(&fixture).unwrap(); | |
| 54 | − assert_eq!(actual, tag_fixture(9000)); | |
| 55 | − assert_eq!( | |
| 56 | − actual.target(), | |
| 57 | − bin("ffa700b4aca13b80cb6b98a078e7c96804f8e0ec") | |
| 58 | − ); | |
| 59 | −} | |
| 60 | − | |
| 61 | 40 | fn tag_fixture(offset: i32) -> parsed::Tag<'static> { |
| 62 | 41 | parsed::Tag { |
| 63 | 42 | target_raw: b"ffa700b4aca13b80cb6b98a078e7c96804f8e0ec", |
| @@ -95,3 +74,13 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB · 31 unmodified lines | ||
| 95 | 74 | }, |
| 96 | 75 | } |
| 97 | 76 | } |
| 77 | + | |
| 78 | +#[test] | |
| 79 | +fn loose_find() { | |
| 80 | + let mut o = ldb() | |
| 81 | + .find(&bin("722fe60ad4f0276d5a8121970b5bb9dccdad4ef9")) | |
| 82 | + .unwrap(); | |
| 83 | + assert_eq!(o.kind, Kind::Tag); | |
| 84 | + assert_eq!(o.size, 1024); | |
| 85 | + assert_eq!(o.parsed().unwrap(), parsed::Object::Tag(tag_fixture(7200))) | |
| 86 | +} | |
| @@ -3,8 +3,8 @@ use git_core; · 2 unmodified lines | ||
| 3 | 3 | use structopt::StructOpt; |
| 4 | 4 | |
| 5 | 5 | mod options { |
| 6 | − use structopt::StructOpt; | |
| 7 | 6 | use structopt::clap::AppSettings; |
| 7 | + use structopt::StructOpt; | |
| 8 | 8 | |
| 9 | 9 | #[derive(Debug, StructOpt)] |
| 10 | 10 | #[structopt(about = "The git, simply swift")] |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | * [x] remove failure and replace with quick-check/anyhow |
| 4 | 4 | * [x] minimize dependencies and test-runs |
| 5 | −* [ ] structopt for grit | |
| 5 | +* [x] structopt for grit | |
| 6 | 6 | * [ ] make parser tests unit tests that are close to the code they test |
| 7 | 7 | * [ ] parser tests handle binary strings nicely |
| 8 | 8 | * [ ] switch parsing to nom (binary only) |