< Summary

Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 216
Line coverage: 100%
Branch coverage
100%
Covered branches: 20
Total branches: 20
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: TryParseProductKey(...)100%1010100%
File 1: TryExtractBareArticleToken(...)100%22100%
File 1: TryParseBareArticle(...)100%88100%
File 2: ProductKeyRegex()100%11100%
File 2: LabeledArticleRegex()100%11100%
File 2: ForArticleRegex()100%11100%
File 2: BareArticleTokenRegex()100%11100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/AiAssistant/AiArticleParser.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2
 3namespace Services.AiAssistant;
 4
 5/// <summary>
 6/// Разбор артикула / product key (09146=FEB) из текста запроса.
 7/// </summary>
 8public static partial class AiArticleParser
 9{
 10    [GeneratedRegex(@"\b([\w\.\-]+)=([\w]+)\b", RegexOptions.Compiled)]
 11    private static partial Regex ProductKeyRegex();
 12
 13    [GeneratedRegex(@"(?:товар|артикул|article|product\s*key)\s+([\w\.\-=]+)", RegexOptions.IgnoreCase | RegexOptions.Co
 14    private static partial Regex LabeledArticleRegex();
 15
 16    [GeneratedRegex(@"(?:для\s+)?артикул[ау]?\s+([\w\.\-=]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled)]
 17    private static partial Regex ForArticleRegex();
 18
 19    public static (string Article, string? ManufacturerPrefix)? TryParseProductKey(string text)
 20    {
 3221        var pk = ProductKeyRegex().Match(text);
 3122        if (pk.Success)
 723            return (pk.Groups[1].Value.Trim(), pk.Groups[2].Value.Trim());
 24
 2425        var forArt = ForArticleRegex().Match(text);
 2426        if (forArt.Success)
 27        {
 1028            var rawFor = forArt.Groups[1].Value.Trim();
 1029            var eqFor = rawFor.IndexOf('=');
 1030            if (eqFor > 0)
 131                return (rawFor[..eqFor].Trim(), rawFor[(eqFor + 1)..].Trim());
 932            return (rawFor, null);
 33        }
 34
 1435        var labeled = LabeledArticleRegex().Match(text);
 1436        if (!labeled.Success)
 537            return null;
 38
 939        var raw = labeled.Groups[1].Value.Trim();
 940        var eq = raw.IndexOf('=');
 941        if (eq > 0)
 142            return (raw[..eq].Trim(), raw[(eq + 1)..].Trim());
 43
 844        return (raw, null);
 45    }
 46
 47    [GeneratedRegex(@"\b(\d{5,}[\w\.\-]*)\b", RegexOptions.Compiled)]
 48    private static partial Regex BareArticleTokenRegex();
 49
 50    public static string? TryExtractBareArticleToken(string text)
 51    {
 2352        var m = BareArticleTokenRegex().Match(text);
 2253        return m.Success ? m.Groups[1].Value.Trim() : null;
 54    }
 55
 56    public static string? TryParseBareArticle(string text)
 57    {
 3258        var forArt = ForArticleRegex().Match(text);
 3159        if (forArt.Success)
 60        {
 1161            var raw = forArt.Groups[1].Value.Trim();
 1162            var eq = raw.IndexOf('=');
 1163            return eq > 0 ? raw[..eq].Trim() : raw;
 64        }
 65
 2066        var labeled = LabeledArticleRegex().Match(text);
 2067        if (!labeled.Success)
 1068            return TryExtractBareArticleToken(text);
 69
 1070        var rawLabeled = labeled.Groups[1].Value.Trim();
 1071        var eqLabeled = rawLabeled.IndexOf('=');
 1072        return eqLabeled > 0 ? rawLabeled[..eqLabeled].Trim() : rawLabeled;
 73    }
 74}

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/obj/Release/net8.0/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs

File '/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/obj/Release/net8.0/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs' does not exist (any more).