Skip to content

Commit bfa3d58

Browse files
committed
test(stack-encrypt): pin the owned MatchTerms index and ContextExtension inspection
Covers two mutants that survived the in-diff gate: MatchTerms' EncryptTarget::indexes replaced with vec![] (each_owned_term_target_names_its_index, which also pins the other owned terms) and ContextExtension::into_inner replaced with None (a_context_extension_is_inspected_as_supplied_or_omitted). The third survivor, ExpectedContext's omitted replaced with Default::default(), is equivalent: the body is Self::default(). It is excluded in .cargo/mutants.toml beside the matching From<()> entry, with the test that pins the omitted behaviour named.
1 parent 9d3729a commit bfa3d58

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎.cargo/mutants.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ exclude_re = [
8181
'stack-encrypt/src/sem/mod\.rs:\d+:\d+: replace <impl MatchConfig for DefaultMatch>::options -> MatchOptions with Default::default\(\)$',
8282
# Both unit-context conversions explicitly return Self::default().
8383
'stack-encrypt/src/target/context\.rs:\d+:\d+: replace <impl From<\(\)> for (DeclaredContext|ExpectedContext<T>)>::from -> Self with Default::default\(\)$',
84+
# Omitting an expectation is expecting nothing: `ExpectedContext::omitted`
85+
# returns Self::default(). That an omitted expectation opens under the
86+
# stored context without checking it is pinned by
87+
# `a_stored_context_opens_as_stored_and_checks_an_expectation`.
88+
'stack-encrypt/src/target/input\.rs:\d+:\d+: replace <impl AllowsNoContext for ExpectedContext<T>>::omitted -> Self with Default::default\(\)$',
8489
# A caller-free declaration adds nothing to the declared context: the
8590
# conversion returns Self::default().
8691
'stack-encrypt/src/target/input\.rs:\d+:\d+: replace <impl From<NoCallerContext> for super::DeclaredContext>::from -> Self with Default::default\(\)$',

‎packages/stack-encrypt/tests/owned_records.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,45 @@ async fn a_searchable_column_is_one_batch_and_its_terms_match_a_query_term() {
527527
assert_eq!(retrieves.load(Ordering::SeqCst), 1);
528528
}
529529

530+
#[test]
531+
fn each_owned_term_target_names_its_index() {
532+
use stack_encrypt::sem::{DefaultMatch, MatchConfig, OpeTerm, OreBlockTerm};
533+
use stack_encrypt::IndexSpec;
534+
assert_eq!(
535+
<EqualityTerm as EncryptTarget<String>>::indexes(),
536+
[IndexSpec::Equality]
537+
);
538+
assert_eq!(
539+
<MatchTerms<DefaultMatch> as EncryptTarget<String>>::indexes(),
540+
[IndexSpec::Match(DefaultMatch::options())]
541+
);
542+
assert_eq!(
543+
<OreTerm<String> as EncryptTarget<String>>::indexes(),
544+
[IndexSpec::Ore]
545+
);
546+
assert_eq!(
547+
<OpeTerm<String> as EncryptTarget<String>>::indexes(),
548+
[IndexSpec::Ope]
549+
);
550+
assert_eq!(
551+
<OreBlockTerm<u32> as EncryptTarget<u32>>::indexes(),
552+
[IndexSpec::OreBlock]
553+
);
554+
}
555+
556+
#[test]
557+
fn a_context_extension_is_inspected_as_supplied_or_omitted() {
558+
use stack_encrypt::target::AllowsNoContext;
559+
assert_eq!(
560+
<ContextExtension<u64> as AcceptsContext>::supplied(7).into_inner(),
561+
Some(7)
562+
);
563+
assert_eq!(
564+
<ContextExtension<u64> as AllowsNoContext>::omitted().into_inner(),
565+
None
566+
);
567+
}
568+
530569
#[tokio::test]
531570
async fn a_searchable_email_standalone_requires_its_context() {
532571
let cipher = common::stack_cipher().await;

0 commit comments

Comments
 (0)