-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStringHelperTests.cs
More file actions
68 lines (59 loc) · 3.01 KB
/
StringHelperTests.cs
File metadata and controls
68 lines (59 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using NUnit.Framework;
namespace Simplify.String.Tests;
[TestFixture]
public class StringHelperTests
{
[Test]
public void IsMobilePhoneParsingCorrectly()
{
Assert.That(StringHelper.ParseMobilePhone("+7 701 22 56 245"), Is.EqualTo("+77012256245"));
Assert.That(StringHelper.ParseMobilePhone("+7701 2256 245"), Is.EqualTo("+77012256245"));
Assert.That(StringHelper.ParseMobilePhone("7-701-22-56-245"), Is.EqualTo("77012256245"));
Assert.That(StringHelper.ParseMobilePhone("8(701)2256245"), Is.EqualTo("87012256245"));
}
[Test]
public void IsEMailValidatingCorrectly()
{
Assert.That(StringHelper.ValidateEMail("testname@pupkin.org"), Is.True);
Assert.That(StringHelper.ValidateEMail("someaddress.test.company@pupkin.org"), Is.True);
Assert.That(StringHelper.ValidateEMail("someaddress.test@company"), Is.True);
Assert.That(StringHelper.ValidateEMail("someaddress.test@companyorg"), Is.True);
Assert.That(StringHelper.ValidateEMail(null), Is.False);
Assert.That(StringHelper.ValidateEMail("someaddress"), Is.False);
Assert.That(StringHelper.ValidateEMail("someaddress.test.company.org"), Is.False);
Assert.That(StringHelper.ValidateEMail("someaddress@test@company.org"), Is.False);
Assert.That(StringHelper.ValidateEMail("someaddress.test..company.org"), Is.False);
}
[Test]
public void IsMobilePhoneValid()
{
Assert.That(StringHelper.ValidateMobilePhone("+77015634321"), Is.True);
Assert.That(StringHelper.ValidateMobilePhone("+7015634321"), Is.True);
Assert.That(StringHelper.ValidateMobilePhone("+666567890345"), Is.True);
Assert.That(StringHelper.ValidateMobilePhone("+9944511122333"), Is.True);
Assert.That(StringHelper.ValidateMobilePhone("+9941234"), Is.True);
Assert.That(StringHelper.ValidateMobilePhone(null), Is.False);
Assert.That(StringHelper.ValidateMobilePhone("8 (701) 56 34 321"), Is.False);
Assert.That(StringHelper.ValidateMobilePhone("+7701563432A"), Is.False);
Assert.That(StringHelper.ValidateMobilePhone("+7701563432*"), Is.False);
}
[Test]
public void IsIndistinctMatchingMatchCorrectly()
{
Assert.That(StringHelper.IndistinctMatching("asdfghjkl", "fghasdjkl"), Is.EqualTo(75));
Assert.That(StringHelper.IndistinctMatching("asdfghjkl", "asdfghjkl"), Is.EqualTo(100));
Assert.That(StringHelper.IndistinctMatching("qwerty", "asdfgh"), Is.EqualTo(0));
Assert.That(StringHelper.IndistinctMatching("qwerty", "ytrewq"), Is.EqualTo(40));
Assert.That(Math.Round(StringHelper.IndistinctMatching("qwe asd", "asd qwe"), 2), Is.EqualTo(72.22));
Assert.That(StringHelper.IndistinctMatching("qweasdzxc", "qwezxcasd"), Is.EqualTo(75));
Assert.That(Math.Round(StringHelper.IndistinctMatching("qweasdzxc", "qweasdzxx"), 2), Is.EqualTo(89.58));
Assert.That(StringHelper.IndistinctMatching(null, "fghasdjkl"), Is.EqualTo(0));
Assert.That(StringHelper.IndistinctMatching("a", "fghasdjkl", 0), Is.EqualTo(0));
}
[Test]
public void IsStripHtmlTagsCorrectly()
{
Assert.That(StringHelper.StripHtmlTags("<a href=\"link\">text</a><input name=\"login\" />"), Is.EqualTo("text"));
}
}