-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from RubenMateus/feat/nonalphanumeric-removal
- Loading branch information
Showing
14 changed files
with
112 additions
and
21 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
1 change: 1 addition & 0 deletions
1
Sluggy.Tests/CompositionStrategyTests.cs → ...ts/Strategies/CompositionStrategyTests.cs
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Moq; | ||
using Sluggy.Strategies; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
|
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,34 @@ | ||
using System; | ||
using Sluggy.Strategies; | ||
using Xunit; | ||
|
||
namespace Sluggy.Tests | ||
{ | ||
public class NonAlphaNumericStrategyTests | ||
{ | ||
[Trait("Project", "Sluggy")] | ||
[Theory(DisplayName = "Should remove nonalphanumeric characters from string")] | ||
[InlineData("<>*.,;´`'~^!#%$&/()=}{[]@£€§¨+|", "")] | ||
[InlineData("a<>*.,;´`'~^!#%$&/()=}{[]@£€§¨+|-ba", "aba")] | ||
[InlineData("", "")] | ||
public void ShouldNormalize(string value, string expectation) | ||
{ | ||
var strategy = new NonAlphaNumericStrategy(); | ||
|
||
var translated = strategy.Translate(value); | ||
|
||
Assert.Equal(expectation, translated); | ||
} | ||
|
||
[Trait("Project", "Sluggy")] | ||
[Fact(DisplayName = "NonAlphaNumericStrategy Should Throw ArgumentNullException")] | ||
public void ShouldThrowNullArgumentException() | ||
{ | ||
const string text = null; | ||
|
||
var strategy = new NonAlphaNumericStrategy(); | ||
|
||
Assert.Throws<ArgumentNullException>(() => strategy.Translate(text)); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Sluggy.Tests/NormalizationStrategyTests.cs → .../Strategies/NormalizationStrategyTests.cs
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using Sluggy.Strategies; | ||
using Xunit; | ||
|
||
namespace Sluggy.Tests | ||
|
1 change: 1 addition & 0 deletions
1
Sluggy.Tests/ToLowerInvarianStrategyTests.cs → ...trategies/ToLowerInvarianStrategyTests.cs
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using Sluggy.Strategies; | ||
using Xunit; | ||
|
||
namespace Sluggy.Tests | ||
|
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
2 changes: 1 addition & 1 deletion
2
Sluggy/CompositeStrategy.cs → Sluggy/Strategies/CompositeStrategy.cs
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
2 changes: 1 addition & 1 deletion
2
Sluggy/ITranslationStrategy.cs → Sluggy/Strategies/ITranslationStrategy.cs
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,32 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Sluggy.Strategies | ||
{ | ||
/// <summary> | ||
/// The standard NonAlphaNumeric Strategy used by Sluggy. | ||
/// </summary> | ||
public class NonAlphaNumericStrategy : ITranslationStrategy | ||
{ | ||
/// <summary> | ||
/// This strategy is used for removing non alpha numeric characters from the provided text. | ||
/// </summary> | ||
/// <param name="text">The text to be translated.</param> | ||
/// <returns>The transformed text.</returns> | ||
/// <exception cref="ArgumentNullException">Thrown when text is null.</exception> | ||
public string Translate(string text) | ||
{ | ||
if (text == null) | ||
{ | ||
throw new ArgumentNullException(nameof(text)); | ||
} | ||
|
||
var nonAlphaNumericChars = text.Where(c => | ||
char.IsLetterOrDigit(c) || | ||
char.IsWhiteSpace(c)) | ||
.ToArray(); | ||
|
||
return new string(nonAlphaNumericChars); | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
Sluggy/ToLowerInvariantStrategy.cs → ...gy/Strategies/ToLowerInvariantStrategy.cs
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