Skip to content

Commit

Permalink
Merge pull request #1122 from GordonRudman/main
Browse files Browse the repository at this point in the history
  • Loading branch information
clairernovotny committed Sep 13, 2021
2 parents edc57f7 + c673638 commit 962e00f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/Humanizer.Tests.Shared/StringDehumanizeTests.cs
Expand Up @@ -5,15 +5,26 @@ namespace Humanizer.Tests
public class StringDehumanizeTests
{
[Theory]
[InlineData("Pascal case sentence is camelized", "PascalCaseSentenceIsCamelized")]
[InlineData("Title Case Sentence Is Camelized", "TitleCaseSentenceIsCamelized")]
[InlineData("Mixed case sentence Is Camelized", "MixedCaseSentenceIsCamelized")]
[InlineData("lower case sentence is camelized", "LowerCaseSentenceIsCamelized")]
[InlineData("AlreadyDehumanizedStringIsUntouched", "AlreadyDehumanizedStringIsUntouched")]
[InlineData("", "")]
[InlineData("Pascal case sentence is pascalized", "PascalCaseSentenceIsPascalized")]
[InlineData("Title Case Sentence Is Pascalized", "TitleCaseSentenceIsPascalized")]
[InlineData("Mixed case sentence Is Pascalized", "MixedCaseSentenceIsPascalized")]
[InlineData("lower case sentence is pascalized", "LowerCaseSentenceIsPascalized")]
[InlineData("A special character is removed?", "ASpecialCharacterIsRemoved")]
[InlineData("A special character is removed after a space ?", "ASpecialCharacterIsRemovedAfterASpace")]
[InlineData("Internal special characters ?)@ are removed", "InternalSpecialCharactersAreRemoved")]
[InlineData("AlreadyDehumanizedStringIsUntouched", "AlreadyDehumanizedStringIsUntouched")]
[InlineData("CanDehumanizeIntoAPascalCaseWord", "CanDehumanizeIntoAPascalCaseWord")]
[InlineData("CanDehumanizeIntoAPascalCaseWord AndAnother", "CanDehumanizeIntoAPascalCaseWordAndAnother")]
[InlineData("OneAndTwo", "OneAndTwo")]
[InlineData("OneOrTwo", "OneOrTwo")]
[InlineData("OneOfTwo", "OneOfTwo")]
[InlineData("OneButTwo", "OneButTwo")]
[InlineData("OneATwo", "OneATwo")]
[InlineData("OneAsTwo", "OneAsTwo")]
[InlineData("OneYetTwo", "OneYetTwo")]
[InlineData("OneNorTwo", "OneNorTwo")]
[InlineData("WordSoTwo", "WordSoTwo")]
public void CanDehumanizeIntoAPascalCaseWord(string input, string expectedResult)
{
Assert.Equal(expectedResult, input.Dehumanize());
Expand Down
10 changes: 8 additions & 2 deletions src/Humanizer/StringDehumanizeExtensions.cs
@@ -1,5 +1,7 @@
using System.Linq;

using Humanizer;

namespace Humanizer
{
/// <summary>
Expand All @@ -9,13 +11,17 @@ public static class StringDehumanizeExtensions
{
/// <summary>
/// Dehumanizes a string; e.g. 'some string', 'Some String', 'Some string' -> 'SomeString'
/// If a string is already dehumanized then it leaves it alone 'SomeStringAndAnotherString' -> 'SomeStringAndAnotherString'
/// </summary>
/// <param name="input">The string to be dehumanized</param>
/// <returns></returns>
public static string Dehumanize(this string input)
{
var titlizedWords = input.Split(' ').Select(word => word.Humanize(LetterCasing.Title));
return string.Join("", titlizedWords).Replace(" ", "");
var pascalizedWords = input.Split(' ').Select(word => word.Humanize().Pascalize());
return string.Join("", pascalizedWords).Replace(" ", "");
}
}
}



0 comments on commit 962e00f

Please sign in to comment.