Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1480 - ToCamelCase broken for a single word with multiple upperc… #1513

Merged
merged 1 commit into from Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/RestSharp/Extensions/StringExtensions.cs
Expand Up @@ -222,9 +222,12 @@ public static string ToPascalCase(this string text, bool removeUnderscores, Cult

string CaseWord(string word)
{
var restOfWord = word.Substring(1).ToLower(culture);
var restOfWord = word.Substring(1);
var firstChar = char.ToUpper(word[0], culture);

if (restOfWord.IsUpperCase())
restOfWord = restOfWord.ToLower(culture);

return string.Concat(firstChar, restOfWord);
}
}
Expand Down Expand Up @@ -274,6 +277,13 @@ public static string AddDashes(this string pascalCasedWord)
"-"
);

/// <summary>
/// Checks to see if a string is all uppper case
/// </summary>
/// <param name="inputString">String to check</param>
/// <returns>bool</returns>
public static bool IsUpperCase(this string inputString) => IsUpperCaseRegex.IsMatch(inputString);

/// <summary>
/// Add an underscore prefix to a pascal-cased string
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions test/RestSharp.Tests/StringExtensionsTests.cs
Expand Up @@ -66,6 +66,14 @@ public void ToPascalCase(string start, bool removeUnderscores, string finish)
Assert.AreEqual(finish, result);
}

[Test, TestCase("DueDate", "dueDate"), TestCase("ID", "id"), TestCase("IDENTIFIER", "identifier"), TestCase("primaryId", "primaryId"), TestCase("A", "a"), TestCase("ThisIsATest", "thisIsATest")]
public void ToCamelCase(string start, string finish)
{
var result = start.ToCamelCase(CultureInfo.InvariantCulture);

Assert.AreEqual(finish, result);
}

[Test]
public void Does_not_throw_on_invalid_encoding()
{
Expand Down