HashSet -> BTreeSet: Make parsing or results and thus tests deterministic. Add comments.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
Machine, MachineConfig, QueryResult, QueryResolutionLine,
|
Machine, MachineConfig, QueryResult, QueryResolutionLine,
|
||||||
@@ -36,19 +36,24 @@ impl Machine {
|
|||||||
Err(output)
|
Err(output)
|
||||||
} else {
|
} else {
|
||||||
// Remove duplicate lines
|
// Remove duplicate lines
|
||||||
let output = output
|
Ok(output
|
||||||
.lines()
|
// 1. Split into disjunct matches
|
||||||
.collect::<HashSet<&str>>()
|
.split(";")
|
||||||
|
.map(|s| s.trim())
|
||||||
|
// 2. Dedupe through Set
|
||||||
|
.collect::<BTreeSet<&str>>()
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
// 3. Back to Vec
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n");
|
.iter()
|
||||||
Ok(output
|
// 4. Trim and remove empty lines
|
||||||
.split(";")
|
|
||||||
.map(|s| s.trim())
|
.map(|s| s.trim())
|
||||||
.map(|s| s.replace(".", ""))
|
.map(|s| s.replace(".", ""))
|
||||||
.filter(|s| !s.is_empty())
|
.filter(|s| !s.is_empty())
|
||||||
|
// 5. Parse into QueryResolutionLine
|
||||||
.map(QueryResolutionLine::try_from)
|
.map(QueryResolutionLine::try_from)
|
||||||
|
// 6. Remove lines that couldn't be parsed, so we still keep the ones they did
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect::<Vec<QueryResolutionLine>>()
|
.collect::<Vec<QueryResolutionLine>>()
|
||||||
.into())
|
.into())
|
||||||
@@ -154,10 +159,10 @@ mod tests {
|
|||||||
result,
|
result,
|
||||||
Ok(QueryResolution::Matches(vec![
|
Ok(QueryResolution::Matches(vec![
|
||||||
QueryMatch::from(btreemap! {
|
QueryMatch::from(btreemap! {
|
||||||
"Class" => Value::from("Todo")
|
"Class" => Value::from("Recipe")
|
||||||
}),
|
}),
|
||||||
QueryMatch::from(btreemap! {
|
QueryMatch::from(btreemap! {
|
||||||
"Class" => Value::from("Recipe")
|
"Class" => Value::from("Todo")
|
||||||
}),
|
}),
|
||||||
]))
|
]))
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user