-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bruni, Ottorino
committed
May 23, 2024
1 parent
b362808
commit 391b82b
Showing
16 changed files
with
362 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using TextCase.Converters; | ||
using TextCase.Extensions; | ||
using Xunit; | ||
|
||
namespace TextCase.UnitTests | ||
{ | ||
public class InverseCaseConverterTest | ||
{ | ||
[Theory] | ||
[InlineData("hello world", "hElLo WoRlD")] | ||
[InlineData("icH bIn glückLICH", "iCh BiN gLüCkLiCh")] | ||
[InlineData(" che ore sono? ", " cHe OrE sOnO? ")] | ||
public void Convert_WhenCamelCase_TextShouldBeCamelCase(string input, string output) | ||
{ | ||
// Setup | ||
var service = new InverseCaseConverter(); | ||
|
||
// Execute | ||
var convertedText = service.Convert(input); | ||
|
||
// Assert | ||
var expected = output; | ||
var actual = convertedText; | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("hello world", "hElLo WoRlD")] | ||
[InlineData("icH bIn glückLICH", "iCh BiN gLüCkLiCh")] | ||
[InlineData(" che ore sono? ", " cHe OrE sOnO? ")] | ||
[InlineData("You talking to me?", "yOu TaLkInG tO mE?")] | ||
public void ToInverseCase_WhenCamelCase_TextShouldBeCamelCase(string input, string output) | ||
{ | ||
// Execute | ||
var convertedText = input.ToInverseCase(); | ||
|
||
// Assert | ||
var expected = output; | ||
var actual = convertedText; | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TextCase.Converters; | ||
using TextCase.Extensions; | ||
using Xunit; | ||
|
||
namespace TextCase.UnitTests | ||
{ | ||
public class TrainCaseConverterTest | ||
{ | ||
[Theory] | ||
[InlineData("hello world", "Hello-World")] | ||
[InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")] | ||
[InlineData("indent_style = space, 2-\nindent_size = 2", "Indent-Style-Space-2\nIndent-Size-2")] | ||
[InlineData("Hello World!", "Hello-World")] | ||
[InlineData("123 test", "123-Test")] | ||
[InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")] | ||
[InlineData("test_with_underscore", "Test-With-Underscore")] | ||
[InlineData("test-with-dash", "Test-With-Dash")] | ||
[InlineData("test.with.period", "Test-With-Period")] | ||
[InlineData("test/with/slash", "Test-With-Slash")] | ||
[InlineData("test\\with\\backslash", "Test-With-Backslash")] | ||
public void Convert_WhenTrainCase_TextShouldBeTrainCase(string input, string expected) | ||
{ | ||
// Setup | ||
var service = new TrainCaseConverter(); | ||
|
||
// Execute | ||
var actual = service.Convert(input); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("hello world", "Hello-World")] | ||
[InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")] | ||
[InlineData("indent_style = space, 2-\nindent_size = 2", "Indent-Style-Space-2\nIndent-Size-2")] | ||
[InlineData("Hello World!", "Hello-World")] | ||
[InlineData("123 test", "123-Test")] | ||
[InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")] | ||
[InlineData("test_with_underscore", "Test-With-Underscore")] | ||
[InlineData("test-with-dash", "Test-With-Dash")] | ||
[InlineData("test.with.period", "Test-With-Period")] | ||
[InlineData("test/with/slash", "Test-With-Slash")] | ||
[InlineData("test\\with\\backslash", "Test-With-Backslash")] | ||
public void ToTrainCase_WhenTrainCase_TextShouldBeTrainCase(string input, string output) | ||
{ | ||
// Execute | ||
var convertedText = input.ToTrainCase(); | ||
|
||
// Assert | ||
var expected = output; | ||
var actual = convertedText; | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
using TextCase.Extensions; | ||
|
||
namespace TextCase.Converters | ||
{ | ||
/// <summary> | ||
/// Represents an inverse converter | ||
/// </summary> | ||
public class InverseCaseConverter : ICaseConverter | ||
{ | ||
/// <summary> | ||
/// Converts the specified text to inverse case. | ||
/// </summary> | ||
/// <param name="text">The string to convert to inverse case.</param> | ||
/// <returns>The specified text converted to inverse case.</returns> | ||
public string Convert(string text) | ||
{ | ||
if (string.IsNullOrWhiteSpace(text)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var builder = new StringBuilder(); | ||
var isUpper = false; | ||
|
||
foreach (var c in text) | ||
{ | ||
builder.Append(isUpper ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)); | ||
if (!char.IsWhiteSpace(c)) | ||
{ | ||
isUpper = !isUpper; | ||
} | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.