mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-02-07 19:06:24 +00:00
tests for string normalization and comparison
This commit is contained in:
parent
ea83db7169
commit
031aaccf82
@ -136,7 +136,7 @@ namespace CompatBot.EventHandlers
|
||||
{
|
||||
UsernameLock.Release(1);
|
||||
}
|
||||
result = Normalizer.ToCanonicalForm(name);
|
||||
result = name.ToCanonicalForm();
|
||||
if (UsernameLock.Wait(0))
|
||||
try
|
||||
{
|
||||
|
@ -317,6 +317,13 @@ namespace CompatBot.Utils
|
||||
return match.Coefficient;
|
||||
}
|
||||
|
||||
internal static bool EqualsIgnoringDiacritics(this string strA, string strB)
|
||||
{
|
||||
var a = strA.ToCanonicalForm();
|
||||
var b = strB.ToCanonicalForm();
|
||||
return string.Compare(a, b, CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase) == 0;
|
||||
}
|
||||
|
||||
private static double GetScoreWithAcronym(this string strA, string strB)
|
||||
{
|
||||
var fullMatch = strA.DiceCoefficient(strB);
|
||||
|
@ -25,7 +25,7 @@ namespace HomoglyphConverter
|
||||
};
|
||||
|
||||
// as per http://www.unicode.org/reports/tr39/#Confusable_Detection
|
||||
public static string ToSkeletonString(this string input)
|
||||
private static string ToSkeletonString(this string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return input;
|
||||
|
@ -1,4 +1,7 @@
|
||||
using CompatBot.Utils;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using CompatBot.Utils;
|
||||
using HomoglyphConverter;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests
|
||||
@ -23,5 +26,12 @@ namespace Tests
|
||||
Assert.That("abc".TrimVisible(3), Is.EqualTo("abc"));
|
||||
Assert.That("abc".TrimVisible(2), Is.EqualTo("a…"));
|
||||
}
|
||||
|
||||
[TestCase("cockatrice", "сockаtrice")]
|
||||
[TestCase("cockatrice", "çöćķåťřĩĉȅ")]
|
||||
public void HomoglyphDetectionTest(string strA, string strB)
|
||||
{
|
||||
Assert.That(strA.EqualsIgnoringDiacritics(strB), Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user