Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruni, Ottorino committed May 23, 2024
1 parent b362808 commit 391b82b
Show file tree
Hide file tree
Showing 16 changed files with 362 additions and 40 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ There are the cases currently available:
- PascalCase
- KebabCase
- SnackCase
- HashtagCase
- HashTagCase
- ConstantCase
- CobolCase
- InverseCase
- TrainCase

It's possible to count in the text:
- number of characters
Expand Down Expand Up @@ -73,8 +77,24 @@ TextCase.Convert("You talking to me?", Case.SnackCase);
"You talking to me?".ToSnackCase();
// #You #talking #to #me?
TextCase.Convert("You talking to me?", Case.HashtagCase);
"You talking to me?".ToHashtagCase();
TextCase.Convert("You talking to me?", Case.HashTagCase);
"You talking to me?".ToHashTagCase();
// YOU_TALKING_TO_ME
TextCase.Convert("You talking to me?", Case.ConstantCase);
"You talking to me?".ToConstantCase();
// YOU-TALKING-TO-ME
TextCase.Convert("You talking to me?", Case.CobolCase);
"You talking to me?".ToCobolCase();
// yOu TaLkInG tO mE?
TextCase.Convert("You talking to me?", Case.InverseCase);
"You talking to me?".ToInverseCase();
// You-Talking-To-Me
TextCase.Convert("You talking to me?", Case.TrainCase);
"You talking to me?".ToTrainCase();
// Text Count
TextCase.GetTextCount("You talking to me?");
Expand Down
4 changes: 2 additions & 2 deletions TextCase.UnitTests/CapitaliseCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public void Convert_WhenCapitaliseCase_TextShouldBeCapitaliseCase(string input,
[InlineData("Hello World", "Hello world")]
[InlineData("ICH BIN GLÜCKLICH", "Ich bin glücklich")]
[InlineData(" che ore SONO? ", "Che ore sono?")]
public void ToCapitaliseCase_WhenCapitaliseCase_TextShouldBeCapitaliseCase(string input, string output)
public void ToCapitalizeCase_WhenCapitalizeCase_TextShouldBeCapitalizeCase(string input, string output)
{
// Execute
var convertedText = input.ToCapitaliseCase();
var convertedText = input.ToCapitalizeCase();

// Assert
var expected = output;
Expand Down
8 changes: 4 additions & 4 deletions TextCase.UnitTests/CapitaliseWordsCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace TextCase.UnitTests
{
public class CapitaliseWordsCaseConverterTest
public class CapitalizeWordsCaseConverterTest
{
[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_WhenCapitaliseCase_TextShouldBeCapitaliseCase(string input, string output)
public void Convert_WhenCapitalizeCase_TextShouldBeCapitalizeCase(string input, string output)
{
// Setup
var service = new CapitaliseWordsCaseConverter();
Expand All @@ -29,10 +29,10 @@ public void Convert_WhenCapitaliseCase_TextShouldBeCapitaliseCase(string input,
[InlineData("Hello World", "Hello World")]
[InlineData("ICH BIN GLÜCKLICH", "Ich Bin Glücklich")]
[InlineData(" che ore SONO? ", " Che Ore Sono? ")]
public void ToCapitaliseWordsCase_WhenCapitaliseCase_TextShouldBeCapitaliseCase(string input, string output)
public void ToCapitalizeWordsCase_WhenCapitalizeCase_TextShouldBeCapitalizeCase(string input, string output)
{
// Execute
var convertedText = input.ToCapitaliseWordsCase();
var convertedText = input.ToCapitalizeWordsCase();

// Assert
var expected = output;
Expand Down
24 changes: 24 additions & 0 deletions TextCase.UnitTests/CobolCaseConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TextCase.Converters;
using TextCase.Extensions;
using Xunit;

namespace TextCase.UnitTests
Expand Down Expand Up @@ -28,5 +29,28 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri
// 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 ToCobolCase_WhenCobolCase_TextShouldBeCobolCase(string input, string output)
{
// Execute
var convertedText = input.ToCobolCase();

// Assert
var expected = output;
var actual = convertedText;
Assert.Equal(expected, actual);
}
}
}
24 changes: 24 additions & 0 deletions TextCase.UnitTests/ConstantCaseConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TextCase.Converters;
using TextCase.Extensions;
using Xunit;

namespace TextCase.UnitTests
Expand Down Expand Up @@ -28,5 +29,28 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri
// 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 ToConstantCase_WhenConstantCase_TextShouldBeConstantCase(string input, string output)
{
// Execute
var convertedText = input.ToConstantCase();

// Assert
var expected = output;
var actual = convertedText;
Assert.Equal(expected, actual);
}
}
}
10 changes: 5 additions & 5 deletions TextCase.UnitTests/HashtagCaseConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

namespace TextCase.UnitTests
{
public class HashtagCaseConverterTest
public class HashTagCaseConverterTest
{
[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_WhenHashtagCase_TextShouldBeHashtagCase(string input, string output)
public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output)
{
// Setup
var service = new HashtagCaseConverter();
var service = new HashTagCaseConverter();

// Execute
var convertedText = service.Convert(input);
Expand All @@ -29,10 +29,10 @@ public void Convert_WhenHashtagCase_TextShouldBeHashtagCase(string input, string
[InlineData("hello world", "#hello #world")]
[InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")]
[InlineData(" che ore sono? ", "#che #ore #sono?")]
public void ToHashtagCase_WhenHashtagCase_TextShouldBeHashtagCase(string input, string output)
public void ToHashTagCase_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output)
{
// Execute
var convertedText = input.ToHashtagCase();
var convertedText = input.ToHashTagCase();

// Assert
var expected = output;
Expand Down
44 changes: 44 additions & 0 deletions TextCase.UnitTests/InverseCaseConverterTest.cs
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);
}
}
}
20 changes: 20 additions & 0 deletions TextCase.UnitTests/PascalCaseConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using TextCase.Converters;
using TextCase.Extensions;
using Xunit;

namespace TextCase.UnitTests
Expand Down Expand Up @@ -27,5 +28,24 @@ public void Convert_WhenPascalCase_TextShouldBePascalCase(string input, string o
var actual = convertedText;
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("hello world", "HelloWorld")]
[InlineData("icH bIn glückLICH", "IchBinGlücklich")]
[InlineData(" che ore sono? ", "CheOreSono?")]
[InlineData("iPhone", "Iphone")]
[InlineData(" Hello World ", "HelloWorld")]
[InlineData("hello\tworld", "HelloWorld")]
[InlineData("Hello\nWorld", "HelloWorld")]
public void ToPascalCase_WhenUpperCase_TextShouldBePascalCase(string input, string output)
{
// Execute
var convertedText = input.ToPascalCase();

// Assert
var expected = output;
var actual = convertedText;
Assert.Equal(expected, actual);
}
}
}
61 changes: 61 additions & 0 deletions TextCase.UnitTests/TrainCaseConverterTest.cs
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);
}
}
}
10 changes: 5 additions & 5 deletions TextCase/Converters/HashtagCaseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
namespace TextCase.Converters
{
/// <summary>
/// Represents a hashtag converter
/// Represents a hash-tag converter
/// </summary>
public class HashtagCaseConverter : ICaseConverter
public class HashTagCaseConverter : ICaseConverter
{
/// <summary>
/// Converts the specified text to hashtag case.
/// Converts the specified text to hash-tag case.
/// </summary>
/// <param name="text">The string to convert to hashtag case.</param>
/// <returns>The specified text converted to hashtag case.</returns>
/// <param name="text">The string to convert to hash-tag case.</param>
/// <returns>The specified text converted to hash-tag case.</returns>
public string Convert(string text)
{
if (string.IsNullOrWhiteSpace(text))
Expand Down
40 changes: 40 additions & 0 deletions TextCase/Converters/InverseCaseConverter.cs
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();
}
}
}
Loading

0 comments on commit 391b82b

Please sign in to comment.