-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathStringHumanizeTests.cs
More file actions
186 lines (166 loc) · 8.54 KB
/
Copy pathStringHumanizeTests.cs
File metadata and controls
186 lines (166 loc) · 8.54 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
public class StringHumanizeTests
{
[Theory]
[InlineData("PascalCaseInputStringIsTurnedIntoSentence", "Pascal case input string is turned into sentence")]
[InlineData("WhenIUseAnInputAHere", "When I use an input a here")]
[InlineData("10IsInTheBegining", "10 is in the begining")]
[InlineData("NumberIsFollowedByLowerCase5th", "Number is followed by lower case 5th")]
[InlineData("NumberIsAtTheEnd100", "Number is at the end 100")]
[InlineData("XIsFirstWordInTheSentence", "X is first word in the sentence")]
[InlineData("XIsFirstWordInTheSentence ThenThereIsASpace", "X is first word in the sentence then there is a space")]
[InlineData("ContainsSpecial?)@Characters", "Contains special characters")]
[InlineData("a", "A")]
[InlineData("A", "A")]
[InlineData("?)@", "")]
[InlineData("?", "")]
[InlineData("", "")]
[InlineData("JeNeParlePasFrançais", "Je ne parle pas français")]
public void CanHumanizeStringInPascalCase(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize());
[Theory, UseCulture("tr-TR")]
[InlineData("istanbul", "İstanbul")]
[InlineData("diyarbakır", "Diyarbakır")]
public void CanHumanizeStringInPascalCaseInTurkish(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize());
[Theory, UseCulture("tr-TR")]
[InlineData("istanbulInputString", "İstanbul Input String")]
public void CanHumanizeStringIntoTitleCaseInTurkish(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize(LetterCasing.Title));
[Theory, UseCulture("ar")]
[InlineData("جمهورية ألمانيا الاتحادية", "جمهورية ألمانيا الاتحادية")]
public void CanHumanizeOtherUnicodeLetter(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize());
[Theory]
[InlineData("Underscored_input_string_is_turned_into_sentence", "Underscored input string is turned into sentence")]
[InlineData("Underscored_input_String_is_turned_INTO_sentence", "Underscored input String is turned INTO sentence")]
[InlineData("TEST 1 - THIS IS A TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1 -THIS IS A TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1- THIS IS A TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1_ THIS IS A TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1 _THIS IS A TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1 _ THIS IS A TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1 - THIS_IS_A_TEST", "TEST 1 THIS IS A TEST")]
[InlineData("TEST 1 - THIS is A Test", "TEST 1 THIS is A test")]
public void CanHumanizeStringWithUnderscoresAndDashes(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize());
[Theory]
[InlineData("HTML", "HTML")]
[InlineData("TheHTMLLanguage", "The HTML language")]
[InlineData("HTMLIsTheLanguage", "HTML is the language")]
[InlineData("TheLanguage IsHTML", "The language is HTML")]
[InlineData("TheLanguageIsHTML", "The language is HTML")]
[InlineData("HTML5", "HTML 5")]
[InlineData("1HTML", "1 HTML")]
public void CanHumanizeStringWithAcronyms(string input, string expectedValue) =>
Assert.Equal(expectedValue, input.Humanize());
[Fact, UseCulture("tr-TR")]
public void CanHumanizeStringsWithCustomAcronyms()
{
Vocabularies.Default.RemoveAcronym("HS");
Vocabularies.Default.RemoveAcronym("iOS");
Vocabularies.Default.RemoveAcronym("API");
try
{
Assert.Equal("Hs access", "HsAccess".Humanize());
Vocabularies.Default.AddAcronym("HS");
Vocabularies.Default.AddAcronym("hs");
Assert.Equal("HS access", "hsAccess".Humanize());
Assert.Equal("HS access", "HsAccess".Humanize());
Assert.Equal("Uses HS", "UsesHs".Humanize());
Assert.Equal("The HTML language", "TheHTMLLanguage".Humanize());
Vocabularies.Default.AddAcronym("iOS");
Vocabularies.Default.AddAcronym("API");
Assert.Equal("iOS", "IOS".Humanize());
Assert.Equal("iOS", "iOS".Humanize());
Assert.Equal("iOS settings", "iOSSettings".Humanize());
Assert.Equal("iOS API settings", "iOSAPISettings".Humanize());
Assert.Equal("iOS 5", "iOS5".Humanize());
Assert.Equal("iOS Settings", "iOS_Settings".Humanize());
Assert.Equal("iOS API Settings", "iOSAPI_Settings".Humanize());
Assert.Equal("BIOS settings", "BIOSSettings".Humanize());
}
finally
{
Vocabularies.Default.RemoveAcronym("HS");
Vocabularies.Default.RemoveAcronym("iOS");
Vocabularies.Default.RemoveAcronym("API");
}
Assert.Equal("Hs access", "HsAccess".Humanize());
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("HS2")]
public void CannotAddInvalidAcronym(string? acronym) =>
Assert.ThrowsAny<ArgumentException>(() => Vocabularies.Default.AddAcronym(acronym!));
[Fact]
public void CanRegisterCustomAcronymsWhileMatching()
{
var vocabulary = new Vocabulary();
vocabulary.AddAcronym("AA");
Parallel.Invoke(
() =>
{
foreach (var letter in Enumerable.Range('B', 25))
{
vocabulary.AddAcronym($"A{(char)letter}");
}
},
() =>
{
for (var i = 0; i < 1000; i++)
{
_ = vocabulary.ApplyAcronyms("Uses aa");
}
});
Assert.Equal("Uses AA", vocabulary.ApplyAcronyms("Uses aa"));
}
[Theory]
[InlineData("Enable & Disable", "Enable & disable")]
[InlineData("&EnableDisable", "& Enable disable")]
[InlineData("&&EnableDisable", "& & Enable disable")]
[InlineData("EnableDisable&", "Enable disable &")]
[InlineData("Enable&Disable", "Enable & disable")]
[InlineData("HTML&CSS", "Html & css")]
[InlineData("TheHTML&CSS", "The HTML & CSS")]
public void CanHumanizeStringWithAmpersands(string input, string expectedValue) =>
Assert.Equal(expectedValue, input.Humanize());
[Theory]
[InlineData("Enable + Disable", "Enable disable")]
[InlineData("Enable / Disable", "Enable disable")]
public void OtherPunctuationIsStillRemoved(string input, string expectedValue) =>
Assert.Equal(expectedValue, input.Humanize());
[Theory]
[InlineData("CanReturnTitleCase", "Can Return Title Case")]
[InlineData("Can_return_title_Case", "Can Return Title Case")]
[InlineData("In titles use lower case for prepositions an article or conjunctions", "In Titles Use Lower Case for Prepositions an Article or Conjunctions")]
[InlineData("Title_humanization_Honors_ALLCAPS", "Title Humanization Honors ALLCAPS")]
[InlineData("MühldorferStraße23", "Mühldorfer Straße 23")]
[InlineData("mühldorfer_STRAẞE_23", "Mühldorfer STRAẞE 23")]
[InlineData("CAN RETURN TITLE CASE", "Can Return Title Case")]
[InlineData("Enable & Disable", "Enable & Disable")]
public void CanHumanizeIntoTitleCase(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize(LetterCasing.Title));
[Theory]
[InlineData("CanReturnLowerCase", "can return lower case")]
[InlineData("LOWERCASE", "lowercase")]
[InlineData("STRAẞE", "straße")]
public void CanHumanizeIntoLowerCase(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize(LetterCasing.LowerCase));
[Theory]
[InlineData("CanReturnSentenceCase", "Can return sentence case")]
[InlineData("", "")]
[InlineData("égoïste", "Égoïste")]
[InlineData("Normal; Normal and PascalCase", "Normal; normal and pascal case")]
[InlineData("I,and No One else", "I, and no one else")]
[InlineData("first. second", "First second")]
[InlineData("&EnableDisable", "& Enable disable")]
public void CanHumanizeIntoSentenceCase(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize(LetterCasing.Sentence));
[Theory]
[InlineData("CanHumanizeIntoUpperCase", "CAN HUMANIZE INTO UPPER CASE")]
[InlineData("Can_Humanize_into_Upper_case", "CAN HUMANIZE INTO UPPER CASE")]
[InlineData("coûts_privés", "COÛTS PRIVÉS")]
public void CanHumanizeIntoUpperCase(string input, string expectedResult) =>
Assert.Equal(expectedResult, input.Humanize(LetterCasing.AllCaps));
}