Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Rhythm.Core/StringExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ public static string ToSnakeCase(this string source)
}

/// <summary>
/// Converts a snake case string to camel case (e.g., converts "this-thing" to "thisThing").
/// Converts a string to camel case (e.g., converts "this-thing" to "thisThing").
/// </summary>
/// <param name="source">
/// The snake case string to convert.
/// The string to convert.
/// </param>
/// <returns>
/// The camel case string.
Expand All @@ -147,10 +147,13 @@ public static string ToCamelCase(this string source)
{
return null;
}
return DashAndCharRegex.Replace(source, x =>

var camelCase = DashAndCharRegex.Replace(source, x =>
{
return x.Groups["CHAR"].Value.ToUpper();
});

return char.ToLowerInvariant(camelCase[0]) + camelCase.Substring(1);
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions src/Tests/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public void CamelCase()
/// Test if pascal case works.
/// </summary>
[TestMethod]
public void PascalCase()
[DataRow("hello-world-test", "helloWorldTest")]
[DataRow("HelloWorldTest", "helloWorldTest")]
public void CamelCase(string input, string expected)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you've removed the PascalCase test method, which should not have happened. If anything, you can add the CamelCase method while leaving the PascalCase method untouched. Also, I recommend adding a data row for a single letter to ensure it doesn't throw an error (since I see there is new logic that concatenates the first letter followed by everything else).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! It is done right now, please take a look

{
var result = "hello-world-test".ToPascalCase();
Assert.AreEqual("HelloWorldTest", result);
var result = input.ToCamelCase();
Assert.AreEqual(expected, result);
}

/// <summary>
Expand Down