History

sketch of validation API along with test suite integration (#450)

Sebastian Thiel committed 4 years ago

Commit 70a765e1 parent 547129e2 files · +32 −5Browse files

Unified · Split

2 files
  1. git-refspec/src/match_group/mod.rs +24 −0
  2. git-refspec/tests/matching/mod.rs +8 −5
git-refspec/src/match_group/mod.rs+24−0
@@ -6,6 +6,30 @@ use std::collections::BTreeSet; · 5 unmodified lines
66 pub(crate) mod types;
77 pub use types::{Item, Mapping, Outcome, Source};
88
9+///
10+pub mod validate {
11+ use crate::match_group::Outcome;
12+
13+ /// All possible issues found while validating matched mappings.
14+ #[derive(Debug)]
15+ pub enum Issue {}
16+
17+ /// The error returned [outcome validation][Outcome::validated()].
18+ #[derive(Debug, thiserror::Error)]
19+ #[error("TBD")]
20+ pub struct Error {
21+ /// All issues discovered during validation.
22+ pub issues: Vec<Issue>,
23+ }
24+
25+ impl<'spec, 'item> Outcome<'spec, 'item> {
26+ /// Validate all mappings or dissolve them into an error stating the discovered issues.
27+ pub fn validated(self) -> Result<Self, Error> {
28+ Ok(self)
29+ }
30+ }
31+}
32+
933 /// Initialization
1034 impl<'a> MatchGroup<'a> {
1135 /// Take all the fetch ref specs from `specs` get a match group ready.
git-refspec/tests/matching/mod.rs+8−5
@@ -130,13 +130,16 @@ pub mod baseline { · 129 unmodified lines
130130 .unwrap_or_else(|| panic!("BUG: Need {:?} added to the baseline", key))
131131 .as_ref();
132132
133− let actual = match_group.match_remotes(input()).mappings;
134− let expected = match &mode {
133+ let actual = match_group.match_remotes(input()).validated();
134+ let (actual, expected) = match &mode {
135135 Mode::Normal { validate_err } => match validate_err {
136− Some(_err_message) => todo!("validation and error comparison"),
137− None => expected.expect("no error"),
136+ Some(err_message) => {
137+ assert_eq!(actual.unwrap_err().to_string(), *err_message);
138+ return;
139+ }
140+ None => (actual.unwrap().mappings, expected.expect("no error")),
138141 },
139− Mode::Custom { expected } => expected,
142+ Mode::Custom { expected } => (actual.unwrap().mappings, expected),
140143 };
141144 assert_eq!(
142145 actual.len(),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t