Skip to content

Commit 7340ca5

Browse files
authored
πŸ› fix: Code Case Regex (#58)
* 🚨 tests: Add Kebab Case Tests * πŸ› fix: Code Case Regex * πŸ“œ docs: Update Changelog * Fix typo
1 parent b32005e commit 7340ca5

5 files changed

Lines changed: 90 additions & 12 deletions

File tree

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [0.5.0] - 2024-10-25
10+
### Fixed
11+
12+
- Bug with code case converter regex
1113

12-
## [0.4.3] - 2024-10-25
14+
## [0.5.0] - 2024-10-25
1315

14-
## [0.4.2] - 2024-10-25
16+
### Added
1517

16-
## [0.4.1] - 2024-10-25
18+
- Code case converters (Pascal, Camel, Snake, Kebab, Train)
1719

1820
## [0.4.0] - 2024-10-25
1921

@@ -27,10 +29,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2729

2830
- Codecov reporting
2931

30-
## [0.2.2] - 2024-10-20
31-
32-
## [0.2.1] - 2024-10-16
33-
3432
## [0.2.0] - 2024-10-10
3533

3634
### Added

β€ŽTJC.StringExtensions.Tests/Cases/KebabCaseExtensionsTests.csβ€Ž

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,74 @@ public void ToKebabCaseTest()
1818
// Assert
1919
Assert.AreEqual(expected, result);
2020
}
21+
22+
[TestMethod]
23+
public void FromPascalCase_ToKebabCase()
24+
{
25+
// Arrange
26+
var input = "KebabCaseExtensions";
27+
var expected = "kebab-case-extensions";
28+
29+
// Act
30+
var result = input.ToKebabCase();
31+
32+
// Assert
33+
Assert.AreEqual(expected, result);
34+
}
35+
36+
[TestMethod]
37+
public void FromCamelCase_ToKebabCase()
38+
{
39+
// Arrange
40+
var input = "kebabCaseExtensions";
41+
var expected = "kebab-case-extensions";
42+
43+
// Act
44+
var result = input.ToKebabCase();
45+
46+
// Assert
47+
Assert.AreEqual(expected, result);
48+
}
49+
50+
[TestMethod]
51+
public void FromTrainCase_ToKebabCase()
52+
{
53+
// Arrange
54+
var input = "Kebab-Case-Extensions";
55+
var expected = "kebab-case-extensions";
56+
57+
// Act
58+
var result = input.ToKebabCase();
59+
60+
// Assert
61+
Assert.AreEqual(expected, result);
62+
}
63+
64+
[TestMethod]
65+
public void FromSnakeCase_ToKebabCase()
66+
{
67+
// Arrange
68+
var input = "kebab_case_extensions";
69+
var expected = "kebab-case-extensions";
70+
71+
// Act
72+
var result = input.ToKebabCase();
73+
74+
// Assert
75+
Assert.AreEqual(expected, result);
76+
}
77+
78+
[TestMethod]
79+
public void FromKebabCase_ToKebabCase()
80+
{
81+
// Arrange
82+
var input = "kebab-case-extensions";
83+
var expected = "kebab-case-extensions";
84+
85+
// Act
86+
var result = input.ToKebabCase();
87+
88+
// Assert
89+
Assert.AreEqual(expected, result);
90+
}
2191
}

β€ŽTJC.StringExtensions/Cases/CodeCaseExtensions.csβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public static string[] CodeCaseToWords(this string input)
3636

3737
private static readonly Regex CaseWordSplitter = CaseWordSplitterRegex();
3838

39-
[GeneratedRegex(@"[a-z][A-Z]|[_\- ]", RegexOptions.Compiled)]
39+
[GeneratedRegex(@"(?<!^)(?=[A-Z])|[_\- ]", RegexOptions.Compiled)]
4040
private static partial Regex CaseWordSplitterRegex();
4141
}

β€ŽTJC.StringExtensions/TJC.StringExtensions.csprojβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
<Pack>True</Pack>
3131
<PackagePath>\</PackagePath>
3232
</None>
33-
<EmbeddedResource Include="..\LICENSE" />
33+
<EmbeddedResource Include="..\LICENSE" />
34+
<None Include="..\CHANGELOG.md">
35+
<Pack>True</Pack>
36+
<PackagePath>\</PackagePath>
37+
</None>
38+
<EmbeddedResource Include="..\CHANGELOG.md" />
3439
</ItemGroup>
3540
<!-- DEPENDENCIES -->
3641
<!-- TESTS -->

β€ŽTesting.slnβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.8.34316.72
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TJC.StringExtensions", "TJC.StringExtensions\TJC.StringExtensions.csproj", "{1D6CD7D0-42B8-403D-948F-CCC7452257D3}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TJC.StringExtensions", "TJC.StringExtensions\TJC.StringExtensions.csproj", "{1D6CD7D0-42B8-403D-948F-CCC7452257D3}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TJC.StringExtensions.Tests", "TJC.StringExtensions.Tests\TJC.StringExtensions.Tests.csproj", "{AE10271D-F595-48FB-8398-5CE3D1F9FB8C}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TJC.StringExtensions.Tests", "TJC.StringExtensions.Tests\TJC.StringExtensions.Tests.csproj", "{AE10271D-F595-48FB-8398-5CE3D1F9FB8C}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6120C59B-01DA-4A50-B125-F98787B726A7}"
11+
ProjectSection(SolutionItems) = preProject
12+
THIRD-PARTY-LICENSES = THIRD-PARTY-LICENSES
13+
EndProjectSection
914
EndProject
1015
Global
1116
GlobalSection(SolutionConfigurationPlatforms) = preSolution

0 commit comments

Comments
Β (0)