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
6pub(crate) mod types;6pub(crate) mod types;
7pub use types::{Item, Mapping, Outcome, Source};7pub use types::{Item, Mapping, Outcome, Source};
8 8
9///
10pub 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
9/// Initialization33/// Initialization
10impl<'a> MatchGroup<'a> {34impl<'a> MatchGroup<'a> {
11 /// Take all the fetch ref specs from `specs` get a match group ready.35 /// 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
130 .unwrap_or_else(|| panic!("BUG: Need {:?} added to the baseline", key))130 .unwrap_or_else(|| panic!("BUG: Need {:?} added to the baseline", key))
131 .as_ref();131 .as_ref();
132 132
133 let actual = match_group.match_remotes(input()).mappings;133 let actual = match_group.match_remotes(input()).validated();
134 let expected = match &mode {134 let (actual, expected) = match &mode {
135 Mode::Normal { validate_err } => match validate_err {135 Mode::Normal { validate_err } => match validate_err {
136 Some(_err_message) => todo!("validation and error comparison"),136 Some(err_message) => {
137 None => expected.expect("no error"),137 assert_eq!(actual.unwrap_err().to_string(), *err_message);
138 return;
139 }
140 None => (actual.unwrap().mappings, expected.expect("no error")),
138 },141 },
139 Mode::Custom { expected } => expected,142 Mode::Custom { expected } => (actual.unwrap().mappings, expected),
140 };143 };
141 assert_eq!(144 assert_eq!(
142 actual.len(),145 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