< Summary

Information
Class: TeleFlow.Telegram.Internal.Handlers.TelegramTextFilter
Assembly: TeleFlow.Framework
File(s): /_/src/TeleFlow.Framework/Internal/Handlers/TelegramTextFilter.cs
Line coverage
66%
Covered lines: 8
Uncovered lines: 4
Coverable lines: 12
Total lines: 39
Line coverage: 66.6%
Branch coverage
37%
Covered branches: 3
Total branches: 8
Branch coverage: 37.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Matches(...)37.5%12860%

File(s)

/_/src/TeleFlow.Framework/Internal/Handlers/TelegramTextFilter.cs

#LineLine coverage
 1using TeleFlow.Annotations;
 2
 3namespace TeleFlow.Telegram.Internal.Handlers;
 4
 5internal sealed class TelegramTextFilter
 6{
 7    public TelegramTextFilter(string value, TextMatchMode mode, bool ignoreCase)
 8    {
 1619        ArgumentException.ThrowIfNullOrWhiteSpace(value);
 10
 11        Value = value;
 12        Mode = mode;
 13        IgnoreCase = ignoreCase;
 16114    }
 15
 16    public string Value { get; }
 17
 18    public TextMatchMode Mode { get; }
 19
 20    public bool IgnoreCase { get; }
 21
 22    public bool Matches(string? text)
 23    {
 15224        if (text is null)
 25        {
 026            return false;
 27        }
 28
 15229        var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
 30
 15231        return Mode switch
 15232        {
 15233            TextMatchMode.Equals => string.Equals(text, Value, comparison),
 034            TextMatchMode.StartsWith => text.StartsWith(Value, comparison),
 035            TextMatchMode.Contains => text.Contains(Value, comparison),
 036            _ => throw new InvalidOperationException($"Unsupported text match mode '{Mode}'.")
 15237        };
 38    }
 39}