tests for string normalization and comparison

This commit is contained in:
13xforever 2019-11-15 18:32:39 +05:00
parent ea83db7169
commit 031aaccf82
4 changed files with 20 additions and 3 deletions

View File

@ -136,7 +136,7 @@ namespace CompatBot.EventHandlers
{
UsernameLock.Release(1);
}
result = Normalizer.ToCanonicalForm(name);
result = name.ToCanonicalForm();
if (UsernameLock.Wait(0))
try
{

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
}
}