Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Tr<Pk> {
{
let script_keys_res = self
.iter_scripts()
.all(|(_d, ms)| ms.for_any_key(&mut pred));
.all(|(_d, ms)| ms.for_each_key(&mut pred));
script_keys_res && pred(ForEach::Key(&self.internal_key))
}
}
Expand Down Expand Up @@ -745,3 +745,32 @@ where
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use ForEachKey;

#[test]
fn test_for_each() {
let desc = "tr(acc0, {
multi_a(3, acc10, acc11, acc12), {
and_v(
v:multi_a(2, acc10, acc11, acc12),
after(10)
),
and_v(
v:multi_a(1, acc10, acc11, ac12),
after(100)
)
}
})";
let desc = desc.replace(&[' ', '\n'][..], "");
let tr = Tr::<String>::from_str(&desc).unwrap();
// Note the last ac12 only has ac and fails the predicate
assert!(!tr.for_each_key(|k| match k {
ForEach::Key(k) => k.starts_with("acc"),
ForEach::Hash(_h) => unreachable!(),
}));
}
}