ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
//! What the escaping keeps out of the pattern, where the three matches anchor, and what the kind
//! writes once both are settled.
//!
//! The load-bearing tests here are DIFFERENTIAL and evaluate the pattern this family writes beside
//! the one a dropped escape would write, over the same subjects. Nothing about the defect is
//! visible in the rendering: `a.b` is a well-formed pattern, the filter document carries one BSON
//! value either way, and the difference is entirely in which documents come back.

use bson::{Bson, Document, Regex, doc};

use super::{MongoTextComparison, text_regex};
use crate::{
  At, ComplexComparison, FieldName, Mongo, RecordAddress, TextFilter, ToDatabaseComparison,
  TryFromFilter,
  comparison::{
    TextMatch,
    mongo::{MongoConjunction, MongoOperator},
  },
};

/// The pattern `operand` renders to under `kind`, as text.
///
/// Case folding is `false` throughout the differentials below because it lives in the OPTIONS and
/// never in the pattern — which is itself asserted, once, further down.
fn pattern(operand: &str, kind: TextMatch) -> String {
  text_regex(operand, kind, false).pattern.into_string()
}

/// **The mutation**, spelled once: the same three anchorings with the escaping removed.
///
/// Written out rather than reached by editing [`super::escape_into`], so the two productions exist
/// side by side in one run and the assertion is over what each ADMITS rather than over a diff.
fn unescaped(operand: &str, kind: TextMatch) -> String {
  match kind {
    TextMatch::Contains => operand.to_owned(),
    TextMatch::Prefix => format!("\\A{operand}"),
    TextMatch::Suffix => format!("{operand}\\z"),
  }
}

/// One production of the pattern language this evaluator reads.
enum Token {
  /// Exactly this character.
  Literal(char),
  /// `.` — any character except a newline.
  AnyCharacter,
  /// `\A`, and `^` outside multiline mode: the start of the subject.
  StartOfSubject,
  /// `\z`: the end of the subject.
  EndOfSubject,
  /// `$`: the end of the subject, or immediately before a newline at the end of it.
  EndOrBeforeFinalNewline,
}

/// `pattern`'s productions, or [`None`] where it leaves the language below.
///
/// # The instrument is the pattern's MEANING and not its text
///
/// A dropped escape renders a pattern that is well-formed, the same length class as the right one,
/// and carried in the document as one BSON regular expression exactly as the right one is. A
/// differential over the rendered text reports it as a different spelling, which is the one thing
/// about it that does not matter. So these tests evaluate both.
///
/// # What it reads, and what it refuses
///
/// Exactly the productions this family writes — a literal, a quoted literal, `\x{…}`, `\A`, `\z` —
/// plus the three a dropped escape leaves behind that the differentials turn on: `.`, `^` and `$`.
/// Their semantics are PCRE2's, read from its own pattern documentation rather than measured
/// against a server: `.` excludes a newline by default, `^` and `$` are the line anchors this
/// family never enables `m` for, and `$` is true before a newline at the end of the subject as well
/// as at the end of it.
///
/// Anything else — a group, a class, a quantifier, an alternation — is [`None`] rather than
/// guessed at. That is also the observable for the second half of the escaping hazard: an
/// unescaped `(` leaves the language this family emits, and the server's answer to the same
/// pattern is a refusal to compile it.
fn tokens(pattern: &str) -> Option<Vec<Token>> {
  let mut characters = pattern.chars();
  let mut read = Vec::new();
  while let Some(ch) = characters.next() {
    read.push(match ch {
      '\\' => match characters.next()? {
        'A' => Token::StartOfSubject,
        'z' => Token::EndOfSubject,
        'x' => {
          let digits: String = characters
            .by_ref()
            .skip_while(|ch| *ch == '{')
            .take_while(|ch| *ch != '}')
            .collect();
          Token::Literal(char::from_u32(u32::from_str_radix(&digits, 16).ok()?)?)
        }
        quoted if !quoted.is_ascii_alphanumeric() => Token::Literal(quoted),
        _ => return None,
      },
      '.' => Token::AnyCharacter,
      '^' => Token::StartOfSubject,
      '$' => Token::EndOrBeforeFinalNewline,
      meta if "[]|(){}?*+".contains(meta) => return None,
      literal => Token::Literal(literal),
    });
  }
  Some(read)
}

/// Whether `read` matches `subject` starting at `from`, each token consuming one character or none.
fn matches_at(read: &[Token], subject: &[char], from: usize) -> bool {
  let mut at = from;
  for token in read {
    match token {
      Token::StartOfSubject => {
        if at != 0 {
          return false;
        }
      }
      Token::EndOfSubject => {
        if at != subject.len() {
          return false;
        }
      }
      Token::EndOrBeforeFinalNewline => {
        if at != subject.len() && !(at + 1 == subject.len() && subject[at] == '\n') {
          return false;
        }
      }
      Token::Literal(expected) => {
        if subject.get(at) != Some(expected) {
          return false;
        }
        at += 1;
      }
      Token::AnyCharacter => {
        if !matches!(subject.get(at), Some(ch) if *ch != '\n') {
          return false;
        }
        at += 1;
      }
    }
  }
  true
}

/// Which of `subjects` the rendered `pattern` matches — a MongoDB `$regex` is a search rather than
/// a whole-value comparison, so every starting position is tried.
fn admitted<'a>(pattern: &str, subjects: &[&'a str]) -> Vec<&'a str> {
  let read = tokens(pattern).expect("this evaluator reads the pattern under test");
  subjects
    .iter()
    .copied()
    .filter(|subject| {
      let characters: Vec<char> = subject.chars().collect();
      (0..=characters.len()).any(|from| matches_at(&read, &characters, from))
    })
    .collect()
}

/// The three matches differ in their ANCHORS and in nothing else, which is what makes them one
/// lowering here where SQL needs three different pieces of SQL.
#[test]
fn the_three_matches_differ_only_in_their_anchors() {
  assert_eq!(pattern("cam", TextMatch::Contains), "cam");
  assert_eq!(pattern("cam", TextMatch::Prefix), "\\Acam");
  assert_eq!(pattern("cam", TextMatch::Suffix), "cam\\z");
}

/// **The one the escaping exists for.** Dropping it changes WHAT MATCHES, not what renders: both
/// patterns are well-formed, both are carried as one BSON regular expression, and only the second
/// answers a question the caller did not ask.
///
/// `axb` is the witness — no operand names it, and the unescaped pattern lets it through, because
/// an unquoted `.` is *any character*.
#[test]
fn dropping_the_escape_changes_which_subjects_match() {
  const SUBJECTS: [&str; 4] = ["a.b", "axb", "ab", "zza.bzz"];

  let escaped = pattern("a.b", TextMatch::Contains);
  let dropped = unescaped("a.b", TextMatch::Contains);

  assert_eq!(escaped, "a\\.b");
  assert_eq!(dropped, "a.b");

  assert_eq!(admitted(&escaped, &SUBJECTS), ["a.b", "zza.bzz"]);
  assert_eq!(admitted(&dropped, &SUBJECTS), ["a.b", "axb", "zza.bzz"]);
}

/// The anchors go on OUTSIDE the escaped operand, so an operand that IS an anchor cannot become
/// one — and the two result sets here are DISJOINT rather than merely different, which is as far
/// apart as one filter can be from another.
#[test]
fn an_operand_that_looks_like_an_anchor_does_not_anchor() {
  const SUBJECTS: [&str; 3] = ["^abc", "abc", "x^abc"];

  let escaped = pattern("^a", TextMatch::Prefix);
  let dropped = unescaped("^a", TextMatch::Prefix);

  assert_eq!(escaped, "\\A\\^a");
  assert_eq!(dropped, "\\A^a");

  assert_eq!(admitted(&escaped, &SUBJECTS), ["^abc"]);
  assert_eq!(admitted(&dropped, &SUBJECTS), ["abc"]);
}

/// A suffix ends at the SUBJECT, which is why the anchor is `\z` and not `$`: PCRE2's dollar is
/// true immediately before a newline at the end of the subject as well as at the end of it, so the
/// dollar spelling admits a field whose stored value ends in one.
#[test]
fn a_suffix_ends_at_the_subject_and_not_before_its_last_newline() {
  const SUBJECTS: [&str; 3] = ["acme corp", "acme corp\n", "corporate"];

  let exact = pattern("corp", TextMatch::Suffix);

  assert_eq!(exact, "corp\\z");
  assert_eq!(admitted(&exact, &SUBJECTS), ["acme corp"]);
  assert_eq!(admitted("corp$", &SUBJECTS), ["acme corp", "acme corp\n"]);
}

/// **Every ASCII character escapes to exactly itself**, which is the escaping's totality asserted
/// rather than argued: the pattern one character produces matches that character and no other.
///
/// A metacharacter left unescaped fails here loudly — an unquoted `.` would match all 128 — and so
/// would an escape that changed the character instead of quoting it.
#[test]
fn every_ascii_character_is_a_pattern_matching_only_itself() {
  let alphabet: Vec<String> = (0u8..=127)
    .map(|byte| char::from(byte).to_string())
    .collect();
  let subjects: Vec<&str> = alphabet.iter().map(String::as_str).collect();

  for one in &subjects {
    let escaped = pattern(one, TextMatch::Contains);
    assert_eq!(
      admitted(&escaped, &subjects),
      [*one],
      "{one:?} escaped to {escaped:?}"
    );
  }
}

/// A NUL is the one character the BSON type REFUSES — a regular expression is stored as two
/// cstrings — and a Rust string may hold one, so it reaches here and leaves as the same character
/// in bytes a cstring admits.
///
/// The subject `a0b` is why the escape is braced: it is what an operand of `"\0"` would match if
/// the hex digits ran into the operand's own next character.
#[test]
fn a_nul_operand_is_carried_as_a_braced_hex_escape() {
  let escaped = pattern("a\0b", TextMatch::Contains);

  assert_eq!(escaped, "a\\x{0}b");
  assert!(!escaped.contains('\0'));
  assert_eq!(
    admitted(&escaped, &["a\u{0}b", "ab", "a0b", "ax0b"]),
    ["a\u{0}b"]
  );
}

/// Non-ASCII passes through unquoted, which is PCRE2's own second half rather than an omission: no
/// metacharacter has a code point above 127, so a backslash before one changes nothing except the
/// size of every operand not written in ASCII.
#[test]
fn a_non_ascii_operand_is_carried_unchanged() {
  let escaped = pattern("café-中", TextMatch::Contains);

  assert_eq!(escaped, "café\\-中");
  assert_eq!(
    admitted(&escaped, &["a café-中 shop", "cafe-中"]),
    ["a café-中 shop"]
  );
}

/// The other half of the hazard: an unescaped bracket is not a wrong result set but NO result,
/// since it opens a group that never closes. Escaped, it is a character to look for.
#[test]
fn a_bracket_operand_is_a_character_and_not_a_group() {
  let escaped = pattern("(", TextMatch::Contains);

  assert_eq!(escaped, "\\(");
  assert_eq!(admitted(&escaped, &["f(x)", "fx"]), ["f(x)"]);
  assert!(
    tokens("(").is_none(),
    "an unescaped bracket leaves the language this family writes"
  );
}

/// Case folding is an OPTION here and the pattern is byte-identical, where SQL's `_nocase` changes
/// the SQL itself. The flag rides inside the regular expression rather than beside it as
/// `$options`, so a comparison that overflows into `$and` cannot leave its pattern folded and its
/// flag unfolded.
#[test]
fn the_case_insensitive_variant_moves_the_option_and_not_the_pattern() {
  let plain = text_regex("Cam", TextMatch::Contains, false);
  let folding = text_regex("Cam", TextMatch::Contains, true);

  assert_eq!(plain.pattern, folding.pattern);
  assert_eq!(plain.options.as_str(), "");
  assert_eq!(folding.options.as_str(), "i");
}

/// The row every address below names. Nothing here is correlated, so no test reads it.
const ROW: RecordAddress = RecordAddress::new(FieldName::new("media"), &[FieldName::new("id")]);

/// Lower one comparison at one field of [`ROW`] and finish the filter.
fn rendered<C: ComplexComparison<Mongo>>(comparison: &C, field: &str) -> Document {
  let frame = At::new(&ROW).frame(FieldName::new(field));
  comparison
    .apply(frame.at(), MongoConjunction::new())
    .expect("a MongoDB lowering cannot refuse")
    .into_document()
}

/// The regular expression `filter` holds under `field`'s `operator` key.
///
/// It reads the value rather than the whole document so a test can assert the PATTERN, which is
/// where a lowering that built its own would differ and where `Document`'s equality would not care.
fn written<'a>(filter: &'a Document, field: &str, operator: MongoOperator) -> &'a Regex {
  match filter.get(field) {
    Some(Bson::Document(operators)) => match operators.get(operator.as_str()) {
      Some(Bson::RegularExpression(regex)) => regex,
      other => panic!("{field}'s {} holds {other:?}", operator.as_str()),
    },
    other => panic!("{field} holds {other:?}"),
  }
}

/// A text comparison's eight VALUE operators are the scalar kind's eight, and they merge into one
/// key exactly as they do there — the affix slots are the whole of what this kind adds.
#[test]
fn the_value_operators_lower_as_the_scalar_kind_s_do() {
  let comparison = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new()
      .with_eq("a".to_owned())
      .with_ne("b".to_owned())
      .with_gt("c".to_owned())
      .with_gte("d".to_owned())
      .with_lt("e".to_owned())
      .with_lte("f".to_owned())
      .with_in_(["g".to_owned(), "h".to_owned()])
      .with_not_in(["i".to_owned()]),
  )
  .expect("the identity crossing cannot fail");

  assert_eq!(comparison.conjuncts(), 8);
  assert_eq!(
    rendered(&comparison, "n"),
    doc! {
      "n": {
        "$eq": "a",
        "$ne": "b",
        "$gt": "c",
        "$gte": "d",
        "$lt": "e",
        "$lte": "f",
        "$in": ["g", "h"],
        "$nin": ["i"],
      }
    }
  );
}

/// The three matches reach the document under ONE operator key and differ only in their anchors —
/// which is what a leaf per dialect buys the SQL family and what this backend needs none of.
#[test]
fn the_three_matches_reach_the_document_under_one_key() {
  for (filter, expected) in [
    (
      TextFilter::<String>::new().with_contains("cam".to_owned()),
      "cam",
    ),
    (
      TextFilter::<String>::new().with_starts_with("cam".to_owned()),
      "\\Acam",
    ),
    (
      TextFilter::<String>::new().with_ends_with("cam".to_owned()),
      "cam\\z",
    ),
  ] {
    let comparison = MongoTextComparison::<String>::try_from_filter(filter)
      .expect("the identity crossing cannot fail");
    let document = rendered(&comparison, "n");

    assert_eq!(
      written(&document, "n", MongoOperator::Regex)
        .pattern
        .as_str(),
      expected
    );
  }
}

/// A negated match is `$not` over the SAME regular expression, and not a second pattern: the
/// operand's rendering does not know it was negated, so nothing about the negation can change what
/// the escaping produced.
#[test]
fn a_negated_match_is_the_same_regex_under_not() {
  let plain = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new().with_contains("cam".to_owned()),
  )
  .expect("the identity crossing cannot fail");
  let negated = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new().with_not_contains("cam".to_owned()),
  )
  .expect("the identity crossing cannot fail");

  let positive = rendered(&plain, "n");
  let refused = rendered(&negated, "n");

  assert_eq!(
    written(&positive, "n", MongoOperator::Regex),
    written(&refused, "n", MongoOperator::Not)
  );
}

/// **The escaping reaches the DOCUMENT**, which is the half a test over [`text_regex`] alone cannot
/// say: a lowering that built its own pattern would pass every assertion above it and still admit
/// `axb`.
#[test]
fn the_lowering_carries_the_escaped_pattern_into_the_document() {
  const SUBJECTS: [&str; 3] = ["a.b", "axb", "ab"];

  let comparison = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new().with_contains("a.b".to_owned()),
  )
  .expect("the identity crossing cannot fail");

  let document = rendered(&comparison, "n");
  let carried = written(&document, "n", MongoOperator::Regex)
    .pattern
    .as_str();

  assert_eq!(carried, "a\\.b");
  assert_eq!(admitted(carried, &SUBJECTS), ["a.b"]);
}

/// Case folding rides in the regular expression's own OPTIONS, so the two spellings of one match
/// carry byte-identical patterns and differ in one character that is not part of the pattern at
/// all.
#[test]
fn a_case_insensitive_slot_carries_its_option_into_the_document() {
  let comparison = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new()
      .with_contains("Cam".to_owned())
      .with_starts_with_nocase("Cam".to_owned()),
  )
  .expect("the identity crossing cannot fail");

  let document = rendered(&comparison, "n");
  let plain = written(&document, "n", MongoOperator::Regex);
  let folding = match document.get_array("$and").expect("the second match folds")[0] {
    Bson::Document(ref branch) => written(branch, "n", MongoOperator::Regex).clone(),
    ref other => panic!("an `$and` branch holds {other:?}"),
  };

  assert_eq!(plain.options.as_str(), "");
  assert_eq!(folding.options.as_str(), "i");
  assert_eq!(folding.pattern.as_str(), "\\ACam");
}

/// **A text comparison is the first kind that overflows its own entry.** Twelve affix slots reach
/// exactly two operator keys, so ten of them cannot be merged and become `$and` branches — where
/// the scalar kind's eight operators are eight distinct keys and never fold from one comparison.
///
/// Nothing is dropped and nothing is refused, which is what the count and the branch total say
/// together: twenty operators in, ten keys and ten branches out.
#[test]
fn twelve_affix_slots_reach_two_keys_and_the_rest_fold() {
  let comparison = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new()
      .with_eq("a".to_owned())
      .with_ne("b".to_owned())
      .with_gt("c".to_owned())
      .with_gte("d".to_owned())
      .with_lt("e".to_owned())
      .with_lte("f".to_owned())
      .with_contains("g".to_owned())
      .with_contains_nocase("h".to_owned())
      .with_not_contains("i".to_owned())
      .with_not_contains_nocase("j".to_owned())
      .with_starts_with("k".to_owned())
      .with_starts_with_nocase("l".to_owned())
      .with_not_starts_with("m".to_owned())
      .with_not_starts_with_nocase("n".to_owned())
      .with_ends_with("o".to_owned())
      .with_ends_with_nocase("p".to_owned())
      .with_not_ends_with("q".to_owned())
      .with_not_ends_with_nocase("r".to_owned())
      .with_in_(["s".to_owned(), "t".to_owned()])
      .with_not_in(["u".to_owned()]),
  )
  .expect("the identity crossing cannot fail");

  assert_eq!(comparison.conjuncts(), 20);

  let document = rendered(&comparison, "n");
  let branches = document.get_array("$and").expect("ten operators fold");

  assert_eq!(branches.len(), 10);
  // The merged key holds the first affix slot of each sign, in the order the struct declares them.
  assert_eq!(
    written(&document, "n", MongoOperator::Regex)
      .pattern
      .as_str(),
    "g"
  );
  assert_eq!(
    written(&document, "n", MongoOperator::Not).pattern.as_str(),
    "i"
  );
}

/// The crossing carries DOMAIN values in and leaves STORAGE values behind, and it does so for all
/// twenty slots — the substring operands are not a separate vocabulary.
#[test]
fn a_crossing_replaces_every_operand_with_its_stored_form() {
  let crossed = MongoTextComparison::<String>::try_from_filter_with(
    TextFilter::<String>::new()
      .with_eq("Camera".to_owned())
      .with_starts_with("Cam".to_owned())
      .with_not_ends_with_nocase("RAW".to_owned())
      .with_in_(["A".to_owned(), "B".to_owned()]),
    |text: String| Ok::<_, core::convert::Infallible>(text.to_lowercase()),
  )
  .expect("a folding conversion cannot fail");

  assert_eq!(crossed.eq().map(String::as_str), Some("camera"));
  assert_eq!(crossed.starts_with().map(String::as_str), Some("cam"));
  assert_eq!(
    crossed.not_ends_with_nocase().map(String::as_str),
    Some("raw")
  );
  assert_eq!(crossed.in_().unwrap(), ["a".to_owned(), "b".to_owned()]);
}

/// A borrowed operand is the same struct with a different `V`: `&String` carries through the
/// reference blanket and reads its text through [`AsRef`]'s, so the borrowed text comparison needs
/// no lifetime and no parallel family.
#[test]
fn a_borrowed_operand_lowers_as_the_owned_one_does() {
  let owned = MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new().with_starts_with("cam".to_owned()),
  )
  .expect("the identity crossing cannot fail");
  let text = "cam".to_owned();
  let borrowed = MongoTextComparison::<&String>::try_from_filter(
    TextFilter::<&String>::new().with_starts_with(&text),
  )
  .expect("the identity crossing cannot fail");

  assert_eq!(rendered(&owned, "n"), rendered(&borrowed, "n"));
}

/// The projection an expansion writes for a text field, resolved — and the ANNOTATION is the
/// assertion: the crossing must land on this kind, and the kind must be the one that lowers for
/// this backend.
#[test]
fn the_codegen_projection_resolves_for_a_text_field() {
  type Crossed = <TextFilter<String> as ToDatabaseComparison<String, Mongo>>::Comparison;

  let comparison: Crossed = MongoTextComparison::<String>::new();
  assert!(comparison.is_empty());
}

/// The identity crossing is provably unable to fail rather than merely always succeeding, and the
/// `match` with NO arms is what proves it.
#[test]
fn the_identity_crossing_cannot_fail() {
  fn unreachable_reason(
    error: <MongoTextComparison<String> as TryFromFilter<TextFilter<String>>>::Error,
  ) -> ! {
    match error {}
  }

  match MongoTextComparison::<String>::try_from_filter(
    TextFilter::<String>::new().with_contains("cam".to_owned()),
  ) {
    Ok(comparison) => assert_eq!(comparison.conjuncts(), 1),
    Err(error) => unreachable_reason(error),
  }
}