Skip to content

Commit 53e7e41

Browse files
committed
add tests
1 parent e06dda7 commit 53e7e41

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

test/UnidecoderTest.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
using System;
2+
using System.Text;
23
using Xunit;
34

45
namespace Unidecode.NET.Tests
56
{
67
public class UnidecoderTest
78
{
89
[Fact]
9-
public void Test()
10+
public void DocTest()
1011
{
1112
Assert.Equal("Bei Jing ", "\u5317\u4EB0".Unidecode());
13+
}
14+
15+
[Fact]
16+
public void CustomTest()
17+
{
1218
Assert.Equal("Rabota s kirillitsey", "Работа с кириллицей".Unidecode());
1319
Assert.Equal("aouoAOUO", "äöűőÄÖŨŐ".Unidecode());
20+
}
21+
22+
[Fact]
23+
public void PythonTest()
24+
{
1425
Assert.Equal("Hello, World!", "Hello, World!".Unidecode());
26+
1527
Assert.Equal("'\"\r\n", "'\"\r\n".Unidecode());
1628
Assert.Equal("CZSczs", "ČŽŠčžš".Unidecode());
1729
Assert.Equal("a", "ア".Unidecode());
@@ -20,5 +32,45 @@ public void Test()
2032
Assert.Equal("chateau", "ch\u00e2teau".Unidecode());
2133
Assert.Equal("vinedos", "vi\u00f1edos".Unidecode());
2234
}
35+
36+
/// <summary>
37+
/// According to http://en.wikipedia.org/wiki/Romanization_of_Russian BGN/PCGN.
38+
/// http://en.wikipedia.org/wiki/BGN/PCGN_romanization_of_Russian
39+
/// With converting "ё" to "yo".
40+
/// </summary>
41+
[Fact]
42+
public void RussianAlphabetTest()
43+
{
44+
string russianAlphabetLowercase = "а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я";
45+
string russianAlphabetUppercase = "А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я";
46+
47+
string expectedLowercase = "a b v g d e yo zh z i y k l m n o p r s t u f kh ts ch sh shch \" y ' e yu ya";
48+
string expectedUppercase = "A B V G D E Yo Zh Z I Y K L M N O P R S T U F Kh Ts Ch Sh Shch \" Y ' E Yu Ya";
49+
50+
Assert.Equal(expectedLowercase, russianAlphabetLowercase.Unidecode());
51+
Assert.Equal(expectedUppercase, russianAlphabetUppercase.Unidecode());
52+
}
53+
54+
[Fact]
55+
public void CharUnidecodeTest()
56+
{
57+
string input = "а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я";
58+
string expected = "a b v g d e yo zh z i y k l m n o p r s t u f kh ts ch sh shch \" y ' e yu ya A B V G D E Yo Zh Z I Y K L M N O P R S T U F Kh Ts Ch Sh Shch \" Y ' E Yu Ya";
59+
60+
var sb = new StringBuilder(expected.Length);
61+
foreach (char c in input)
62+
{
63+
sb.Append(c.Unidecode());
64+
}
65+
string result = sb.ToString();
66+
67+
Assert.Equal(expected, result);
68+
}
69+
70+
[Fact]
71+
public void UnidecodeOnNullShouldReturnEmptyString()
72+
{
73+
Assert.Equal("", ((string)null).Unidecode());
74+
}
2375
}
2476
}

0 commit comments

Comments
 (0)