cockpitTextMatches function

bool cockpitTextMatches(
  1. String actual,
  2. String expected,
  3. CockpitTextMatchMode matchMode
)

Implementation

bool cockpitTextMatches(
  String actual,
  String expected,
  CockpitTextMatchMode matchMode,
) {
  final normalizedActual = cockpitNormalizeText(actual);
  final normalizedExpected = cockpitNormalizeText(expected);
  if (normalizedActual.isEmpty || normalizedExpected.isEmpty) return false;
  return switch (matchMode) {
    CockpitTextMatchMode.exact => normalizedActual == normalizedExpected,
    CockpitTextMatchMode.contains => normalizedActual.contains(
      normalizedExpected,
    ),
    CockpitTextMatchMode.fuzzy => cockpitFuzzyTextMatches(
      normalizedActual,
      normalizedExpected,
    ),
    CockpitTextMatchMode.regex => RegExp(
      expected.trim(),
    ).hasMatch(normalizedActual),
  };
}