From 672aef8ba29f51ec551d3059f98430e52be7d0ca Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Jan 2014 12:17:11 +0000 Subject: [PATCH 1/2] Added a Hyphenate method which calls Dasherize --- src/Humanizer/InflectorExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index a75197f6a..c860c72e8 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -260,6 +260,16 @@ public static string Underscore(this string input) public static string Dasherize(this string underscoredWord) { return underscoredWord.Replace('_', '-'); + } + + /// + /// Replaces underscores with hyphens in the string + /// + /// + /// + public static string Hyphenate(this string underscoredWord) + { + return Dasherize(underscoredWord) } } } \ No newline at end of file From 5b81d32a7451e842a408ec6bdf209f94a357bd37 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 6 Jan 2014 16:04:16 +0000 Subject: [PATCH 2/2] Added tests for Hyphenate, sorted out whitespace issues. --- src/Humanizer.Tests/InflectorTests.cs | 10 ++++++++++ src/Humanizer/InflectorExtensions.cs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests/InflectorTests.cs b/src/Humanizer.Tests/InflectorTests.cs index 13d452e92..dc68f54f4 100644 --- a/src/Humanizer.Tests/InflectorTests.cs +++ b/src/Humanizer.Tests/InflectorTests.cs @@ -76,6 +76,16 @@ public void Dasherize(string input, string expectedOutput) Assert.Equal(input.Dasherize(), expectedOutput); } + [InlineData("some_title", "some-title")] + [InlineData("some-title", "some-title")] + [InlineData("some_title_goes_here", "some-title-goes-here")] + [InlineData("some_title and_another", "some-title and-another")] + [Theory] + public void Hyphenate(string input, string expectedOutput) + { + Assert.Equal(input.Hyphenate(), expectedOutput); + } + [Theory] [InlineData("customer", "Customer")] [InlineData("CUSTOMER", "CUSTOMER")] diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index c860c72e8..c6019a5d6 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -262,14 +262,14 @@ public static string Dasherize(this string underscoredWord) return underscoredWord.Replace('_', '-'); } - /// + /// /// Replaces underscores with hyphens in the string /// /// /// public static string Hyphenate(this string underscoredWord) { - return Dasherize(underscoredWord) + return Dasherize(underscoredWord); } } } \ No newline at end of file