< Summary

Class:DCL.Social.Chat.Mentions.MentionsUtils
Assembly:Mentions
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Mentions/MentionsUtils.cs
Covered lines:4
Uncovered lines:5
Coverable lines:9
Total lines:39
Line coverage:44.4% (4 of 9)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:6
Method coverage:50% (3 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MentionsUtils()0%110100%
IsAMention(...)0%2100%
IsUserMentionedInText(...)0%110100%
TextContainsMention(...)0%2100%
GetAllMentions(...)0%220100%
ReplaceMentionPattern(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Mentions/MentionsUtils.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text.RegularExpressions;
 5
 6namespace DCL.Social.Chat.Mentions
 7{
 8    public static class MentionsUtils
 9    {
 10        private const string MENTION_PATTERN = @"\B@[a-zA-Z\d]{3,15}(#[a-zA-Z\d]{4})?";
 111        private static readonly Regex MENTION_REGEX = new (MENTION_PATTERN);
 12
 13        public static bool IsAMention(string text)
 14        {
 015            var match = MENTION_REGEX.Match(text);
 016            return match.Success;
 17        }
 18
 19        public static bool IsUserMentionedInText(string userName, string text) =>
 2420            text.Contains($"@{userName}", StringComparison.OrdinalIgnoreCase);
 21
 22        public static bool TextContainsMention(string text)
 23        {
 024            Match match = MENTION_REGEX.Match(text);
 025            return match.Success;
 26        }
 27
 28        public static IEnumerable<string> GetAllMentions(string input)
 29        {
 1630            MatchCollection matches = MENTION_REGEX.Matches(input);
 1631            return matches.Select(match => match.Value);
 32        }
 33
 34        public static string ReplaceMentionPattern(string input, Func<string, string> replacementCallback)
 35        {
 036            return MENTION_REGEX.Replace(input, match => replacementCallback?.Invoke(match.Value));
 37        }
 38    }
 39}