From 80e22aa6ca22254e2263c84fa6417c376d9c6843 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 11:31:45 +0430 Subject: [PATCH 01/10] added new PRs to release-notes --- release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release_notes.md b/release_notes.md index da96eac3f..2e47c6561 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,6 @@ ###In Development + - [#124](https://github.com/MehdiK/Humanizer/pull/124): Added Slovak localization (strings, formatter, tests) + - [#130](https://github.com/MehdiK/Humanizer/pull/130): Added Czech localization (strings, formatter, tests) [Commits](https://github.com/MehdiK/Humanizer/compare/v1.16.4...master) From 801b967032004d7af0ae13caa6dd8bf7a79e8af9 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:08:27 +0430 Subject: [PATCH 02/10] refactored DateHumanizeTests & Verify logic --- src/Humanizer.Tests/DateHumanize.cs | 33 +++ src/Humanizer.Tests/DateHumanizeTests.cs | 269 +++++++-------------- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 + src/Humanizer/Humanizer.csproj | 4 +- 4 files changed, 126 insertions(+), 181 deletions(-) create mode 100644 src/Humanizer.Tests/DateHumanize.cs diff --git a/src/Humanizer.Tests/DateHumanize.cs b/src/Humanizer.Tests/DateHumanize.cs new file mode 100644 index 000000000..3110feffe --- /dev/null +++ b/src/Humanizer.Tests/DateHumanize.cs @@ -0,0 +1,33 @@ +using System; +using Xunit; + +namespace Humanizer.Tests +{ + public class DateHumanize + { + static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow) + { + var utcNow = DateTime.UtcNow; + var localNow = DateTime.Now; + + // feels like the only way to avoid breaking tests because CPU ticks over is to inject the base date + Assert.Equal(expectedString, utcNow.Add(deltaFromNow).Humanize(utcDate: true, dateToCompareAgainst: utcNow)); + Assert.Equal(expectedString, localNow.Add(deltaFromNow).Humanize(utcDate: false, dateToCompareAgainst: localNow)); + } + + static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow) + { + var utcNow = new DateTime(2013, 6, 20, 9, 58, 22, DateTimeKind.Utc); + var now = new DateTime(2013, 6, 20, 11, 58, 22, DateTimeKind.Local); + + Assert.Equal(expectedString, utcNow.Add(deltaFromNow).Humanize(utcDate: true, dateToCompareAgainst: utcNow)); + Assert.Equal(expectedString, now.Add(deltaFromNow).Humanize(false, now)); + } + + public static void Verify(string expectedString, TimeSpan deltaFromNow) + { + VerifyWithCurrentDate(expectedString, deltaFromNow); + VerifyWithDateInjection(expectedString, deltaFromNow); + } + } +} \ No newline at end of file diff --git a/src/Humanizer.Tests/DateHumanizeTests.cs b/src/Humanizer.Tests/DateHumanizeTests.cs index 9ff961f2e..f1ecceeb8 100644 --- a/src/Humanizer.Tests/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/DateHumanizeTests.cs @@ -1,223 +1,132 @@ using System; -using Humanizer.Localisation; -using Xunit; +using Xunit.Extensions; namespace Humanizer.Tests { public class DateHumanizeTests { - static void VerifyWithCurrentDate(string expectedString, TimeSpan deltaFromNow) + [Theory] + [InlineData(1, "one second ago")] + [InlineData(10, "10 seconds ago")] + [InlineData(59, "59 seconds ago")] + [InlineData(60, "a minute ago")] + public void SecondsAgo(int seconds, string expected) { - var utcNow = DateTime.UtcNow; - var localNow = DateTime.Now; - - // feels like the only way to avoid breaking tests because CPU ticks over is to inject the base date - Assert.Equal(expectedString, utcNow.Add(deltaFromNow).Humanize(utcDate: true, dateToCompareAgainst: utcNow)); - Assert.Equal(expectedString, localNow.Add(deltaFromNow).Humanize(utcDate: false, dateToCompareAgainst: localNow)); - } - - static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow) - { - var utcNow = new DateTime(2013, 6, 20, 9, 58, 22, DateTimeKind.Utc); - var now = new DateTime(2013, 6, 20, 11, 58, 22, DateTimeKind.Local); - - Assert.Equal(expectedString, utcNow.Add(deltaFromNow).Humanize(dateToCompareAgainst: utcNow)); - Assert.Equal(expectedString, now.Add(deltaFromNow).Humanize(false, now)); - } - - static void Verify(string expectedString, TimeSpan deltaFromNow) - { - VerifyWithCurrentDate(expectedString, deltaFromNow); - VerifyWithDateInjection(expectedString, deltaFromNow); - } - - [Fact] - public void OneSecondFromNow() - { - var oneSecondFromNow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Future, count: 1)); - Verify(oneSecondFromNow, new TimeSpan(0, 0, 0, 1)); - } - - [Fact] - public void SecondsFromNow() - { - var secsFromNow = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Future, count: 10)), 10); - Verify(secsFromNow, new TimeSpan(0, 0, 0, 10)); - } - - [Fact] - public void OneMinuteFromNow() - { - var oneMinFromNow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Future, count: 1)); - Verify(oneMinFromNow, new TimeSpan(0, 0, 1, 1)); - } - - [Fact] - public void AFewMinutesFromNow() - { - var minsFromNow = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Future, count: 10)), 10); - Verify(minsFromNow, new TimeSpan(0, 0, 10, 0)); - } - - [Fact] - public void AnHourFromNow() - { - var anHourFromNow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Future, count: 1)); - Verify(anHourFromNow, new TimeSpan(0, 1, 10, 0)); - } - - [Fact] - public void HoursFromNow() - { - var hoursFromNow = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Future, count: 10)), 10); - Verify(hoursFromNow, new TimeSpan(0, 10, 0, 0)); - } - - [Fact] - public void Tomorrow() - { - var tomorrow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Future, count: 1)); - Verify(tomorrow, new TimeSpan(1, 10, 0, 0)); - } - - [Fact] - public void AFewDaysFromNow() - { - var daysFromNow = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Future, count: 10)), 10); - Verify(daysFromNow, new TimeSpan(10, 1, 0, 0)); - } - - [Fact] - public void OneMonthFromNow() - { - var oneMonthFromNow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Future, count: 1)); - Verify(oneMonthFromNow, new TimeSpan(31, 1, 0, 0)); - } - - [Fact] - public void AFewMonthsFromNow() - { - var monthsFromNow = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Future, count: 2)), 2); - Verify(monthsFromNow, new TimeSpan(62, 1, 0, 0)); - } - - [Fact] - public void OneYearFromNowIsNotAccureate() - { - var aYearFromNow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Future, count: 1)); - Verify(aYearFromNow, new TimeSpan(360, 0, 0, 0)); - } - - [Fact] - public void OneYearFromNow() - { - var aYearFromNow = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Future, count: 1)); - Verify(aYearFromNow, new TimeSpan(400, 0, 0, 0)); - } - - [Fact] - public void FewYearsFromNow() - { - var fewYearsFromNow = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Future, count: 2)), 2); - Verify(fewYearsFromNow, new TimeSpan(900, 0, 0, 0)); - } - - [Fact] - public void JustNow() - { - var now = Resources.GetResource(ResourceKeys.DateHumanize.Now); - Verify(now, new TimeSpan(0, 0, 0, 0)); - } - - [Fact] - public void OneSecondAgo() - { - var aSecAgo = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Past)); - Verify(aSecAgo, new TimeSpan(0, 0, 0, -1)); - } - - [Fact] - public void SecondsAgo() - { - var secondsAgo = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Past, count: 10)), 10); - Verify(secondsAgo, new TimeSpan(0, 0, 0, -10)); + DateHumanize.Verify(expected, TimeSpan.FromSeconds(-seconds)); } - [Fact] - public void OneMinuteAgo() + [Theory] + [InlineData(1, "one second from now")] + [InlineData(10, "10 seconds from now")] + [InlineData(59, "59 seconds from now")] + [InlineData(60, "a minute from now")] + public void SecondsFromNow(int seconds, string expected) { - var aMinuteAgo = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Past)); - Verify(aMinuteAgo, new TimeSpan(0, 0, -1, -10)); + DateHumanize.Verify(expected, TimeSpan.FromSeconds(seconds)); } - [Fact] - public void AFewMinutesAgo() + [Theory] + [InlineData(1, "a minute ago")] + [InlineData(10, "10 minutes ago")] + [InlineData(44, "44 minutes ago")] + [InlineData(45, "an hour ago")] + [InlineData(119, "an hour ago")] + [InlineData(120, "2 hours ago")] + public void MinutesAgo(int minutes, string expected) { - var minsAgo = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Past, count: 10)), 10); - Verify(minsAgo, new TimeSpan(0, 0, -10, 0)); + DateHumanize.Verify(expected, TimeSpan.FromMinutes(-minutes)); } - [Fact] - public void AnHourAgo() + [Theory] + [InlineData(1, "a minute from now")] + [InlineData(10, "10 minutes from now")] + [InlineData(44, "44 minutes from now")] + [InlineData(45, "an hour from now")] + [InlineData(119, "an hour from now")] + [InlineData(120, "2 hours from now")] + public void MinutesFromNow(int minutes, string expected) { - var anHourAgo = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Past)); - Verify(anHourAgo, new TimeSpan(0, -1, -10, 0)); + DateHumanize.Verify(expected, TimeSpan.FromMinutes(minutes)); } - [Fact] - public void HoursAgo() + [Theory] + [InlineData(1, "an hour ago")] + [InlineData(10, "10 hours ago")] + [InlineData(23, "23 hours ago")] + [InlineData(24, "yesterday")] + public void HoursAgo(int hours, string expected) { - var hoursAgo = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Past, count: 10)), 10); - Verify(hoursAgo, new TimeSpan(0, -10, 0, 0)); + DateHumanize.Verify(expected, TimeSpan.FromHours(-hours)); } - [Fact] - public void Yesterday() + [Theory] + [InlineData(1, "an hour from now")] + [InlineData(10, "10 hours from now")] + [InlineData(23, "23 hours from now")] + [InlineData(24, "tomorrow")] + public void HoursFfomNow(int hours, string expected) { - var yesterday = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Past)); - Verify(yesterday, new TimeSpan(-1, -10, 0, 0)); + DateHumanize.Verify(expected, TimeSpan.FromHours(hours)); } - [Fact] - public void AFewDaysAgo() + [Theory] + [InlineData(1, "yesterday")] + [InlineData(10, "10 days ago")] + [InlineData(28, "28 days ago")] + [InlineData(32, "one month ago")] + public void DaysAgo(int days, string expected) { - var fewDaysAgo = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Past, count: 10)), 10); - Verify(fewDaysAgo, new TimeSpan(-10, -1, 0, 0)); + DateHumanize.Verify(expected, TimeSpan.FromDays(-days)); } - [Fact] - public void OneMonthAgo() + [Theory] + [InlineData(1, "tomorrow")] + [InlineData(10, "10 days from now")] + [InlineData(28, "28 days from now")] + [InlineData(32, "one month from now")] + public void DaysFromNow(int days, string expected) { - var aMonthAgo = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Past)); - Verify(aMonthAgo, new TimeSpan(-31, -1, 0, 0)); + DateHumanize.Verify(expected, TimeSpan.FromDays(days)); } - [Fact] - public void AFewMonthsAgo() + [Theory] + [InlineData(1, "one month ago")] + [InlineData(10, "10 months ago")] + [InlineData(11, "11 months ago")] + [InlineData(12, "one year ago")] + public void MonthsAgo(int months, string expected) { - var monthsAgo = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Past, count: 2)), 2); - Verify(monthsAgo, new TimeSpan(-62, -1, 0, 0)); + // ToDo should come up with a more solid logic + DateHumanize.Verify(expected, TimeSpan.FromDays(-months * 31)); } - [Fact] - public void OneYearAgoIsNotAccureate() + [Theory] + [InlineData(1, "one month from now")] + [InlineData(10, "10 months from now")] + [InlineData(11, "11 months from now")] + [InlineData(12, "one year from now")] + public void MonthsFromNow(int months, string expected) { - var aYearAgo = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Past)); - Verify(aYearAgo, new TimeSpan(-360, 0, 0, 0)); + // ToDo should come up with a more solid logic + DateHumanize.Verify(expected, TimeSpan.FromDays(months * 31)); } - [Fact] - public void OneYearAgo() + [Theory] + [InlineData(1, "one year ago")] + [InlineData(2, "2 years ago")] + public void YearsAgo(int years, string expected) { - var aYearAgo = Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Past)); - Verify(aYearAgo, new TimeSpan(-400, 0, 0, 0)); + // ToDo should come up with a more solid logic + DateHumanize.Verify(expected, TimeSpan.FromDays(-years * 366)); } - [Fact] - public void FewYearsAgo() + [Theory] + [InlineData(1, "one year from now")] + [InlineData(2, "2 years from now")] + public void YearsFromNow(int years, string expected) { - var yearsAgo = string.Format(Resources.GetResource(ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Past, count: 2)), 2); - Verify(yearsAgo, new TimeSpan(-900, 0, 0, 0)); + // ToDo should come up with a more solid logic + DateHumanize.Verify(expected, TimeSpan.FromDays( years * 366)); } } } diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 5fa5d0369..8aa941188 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -75,6 +75,7 @@ + diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 82a3cd3b0..0cbcd0d9e 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -158,7 +158,9 @@ - + + Designer + From d11a6525fbce6fe648b0e75d4d3ffde653e654c9 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:35:37 +0430 Subject: [PATCH 03/10] changed the Verify signature & refactored arabic tests --- src/Humanizer.Tests/DateHumanize.cs | 31 ++++++++++++++++++- src/Humanizer.Tests/DateHumanizeTests.cs | 30 ++++++++---------- .../Localisation/ar/DateHumanizeTests.cs | 15 +++++---- 3 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/Humanizer.Tests/DateHumanize.cs b/src/Humanizer.Tests/DateHumanize.cs index 3110feffe..54852d2be 100644 --- a/src/Humanizer.Tests/DateHumanize.cs +++ b/src/Humanizer.Tests/DateHumanize.cs @@ -1,4 +1,5 @@ using System; +using Humanizer.Localisation; using Xunit; namespace Humanizer.Tests @@ -24,8 +25,36 @@ static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow Assert.Equal(expectedString, now.Add(deltaFromNow).Humanize(false, now)); } - public static void Verify(string expectedString, TimeSpan deltaFromNow) + public static void Verify(string expectedString, int unit, TimeUnit timeUnit, TimeUnitTense tense) { + var deltaFromNow = new TimeSpan(); + unit = Math.Abs(unit); + + if (tense == TimeUnitTense.Past) + unit = -unit; + + switch (timeUnit) + { + case TimeUnit.Second: + deltaFromNow = TimeSpan.FromSeconds(unit); + break; + case TimeUnit.Minute: + deltaFromNow = TimeSpan.FromMinutes(unit); + break; + case TimeUnit.Hour: + deltaFromNow = TimeSpan.FromHours(unit); + break; + case TimeUnit.Day: + deltaFromNow = TimeSpan.FromDays(unit); + break; + case TimeUnit.Month: + deltaFromNow = TimeSpan.FromDays(unit*31); + break; + case TimeUnit.Year: + deltaFromNow = TimeSpan.FromDays(unit*366); + break; + } + VerifyWithCurrentDate(expectedString, deltaFromNow); VerifyWithDateInjection(expectedString, deltaFromNow); } diff --git a/src/Humanizer.Tests/DateHumanizeTests.cs b/src/Humanizer.Tests/DateHumanizeTests.cs index f1ecceeb8..dbfdd06a5 100644 --- a/src/Humanizer.Tests/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/DateHumanizeTests.cs @@ -1,4 +1,4 @@ -using System; +using Humanizer.Localisation; using Xunit.Extensions; namespace Humanizer.Tests @@ -12,7 +12,7 @@ public class DateHumanizeTests [InlineData(60, "a minute ago")] public void SecondsAgo(int seconds, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromSeconds(-seconds)); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Past); } [Theory] @@ -22,7 +22,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(60, "a minute from now")] public void SecondsFromNow(int seconds, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromSeconds(seconds)); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Future); } [Theory] @@ -34,7 +34,7 @@ public void SecondsFromNow(int seconds, string expected) [InlineData(120, "2 hours ago")] public void MinutesAgo(int minutes, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromMinutes(-minutes)); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Past); } [Theory] @@ -46,7 +46,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(120, "2 hours from now")] public void MinutesFromNow(int minutes, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromMinutes(minutes)); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Future); } [Theory] @@ -56,7 +56,7 @@ public void MinutesFromNow(int minutes, string expected) [InlineData(24, "yesterday")] public void HoursAgo(int hours, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromHours(-hours)); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Past); } [Theory] @@ -66,7 +66,7 @@ public void HoursAgo(int hours, string expected) [InlineData(24, "tomorrow")] public void HoursFfomNow(int hours, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromHours(hours)); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Future); } [Theory] @@ -76,7 +76,7 @@ public void HoursFfomNow(int hours, string expected) [InlineData(32, "one month ago")] public void DaysAgo(int days, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromDays(-days)); + DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Past); } [Theory] @@ -86,7 +86,7 @@ public void DaysAgo(int days, string expected) [InlineData(32, "one month from now")] public void DaysFromNow(int days, string expected) { - DateHumanize.Verify(expected, TimeSpan.FromDays(days)); + DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Future); } [Theory] @@ -96,8 +96,7 @@ public void DaysFromNow(int days, string expected) [InlineData(12, "one year ago")] public void MonthsAgo(int months, string expected) { - // ToDo should come up with a more solid logic - DateHumanize.Verify(expected, TimeSpan.FromDays(-months * 31)); + DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Past); } [Theory] @@ -107,8 +106,7 @@ public void MonthsAgo(int months, string expected) [InlineData(12, "one year from now")] public void MonthsFromNow(int months, string expected) { - // ToDo should come up with a more solid logic - DateHumanize.Verify(expected, TimeSpan.FromDays(months * 31)); + DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Future); } [Theory] @@ -116,8 +114,7 @@ public void MonthsFromNow(int months, string expected) [InlineData(2, "2 years ago")] public void YearsAgo(int years, string expected) { - // ToDo should come up with a more solid logic - DateHumanize.Verify(expected, TimeSpan.FromDays(-years * 366)); + DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Past); } [Theory] @@ -125,8 +122,7 @@ public void YearsAgo(int years, string expected) [InlineData(2, "2 years from now")] public void YearsFromNow(int years, string expected) { - // ToDo should come up with a more solid logic - DateHumanize.Verify(expected, TimeSpan.FromDays( years * 366)); + DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Future); } } } diff --git a/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs index 98da12974..bf4d9b44e 100644 --- a/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs @@ -1,5 +1,4 @@ -using System; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; namespace Humanizer.Tests.Localisation.ar @@ -16,7 +15,7 @@ public class DateHumanizeTests : AmbientCulture [InlineData(-11, "منذ 11 يوم")] public void DaysAgo(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Past); } [Theory] @@ -26,7 +25,7 @@ public void DaysAgo(int days, string expected) [InlineData(-11, "منذ 11 ساعة")] public void HoursAgo(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Past); } [Theory] @@ -36,7 +35,7 @@ public void HoursAgo(int hours, string expected) [InlineData(-11, "منذ 11 دقيقة")] public void MinutesAgo(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Past); } [Theory] @@ -46,7 +45,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(-11, "منذ 11 شهر")] public void MonthsAgo(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Past); } [Theory] @@ -56,7 +55,7 @@ public void MonthsAgo(int months, string expected) [InlineData(-11, "منذ 11 ثانية")] public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Past); } [Theory] @@ -66,7 +65,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(-11, "منذ 11 عام")] public void YearsAgo(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Past); } } } From ea0a6fcfe78209334e61437021e98800d6736947 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:40:43 +0430 Subject: [PATCH 04/10] updated cs DateHumanizeTests to use Verify --- .../Localisation/cs/DateHumanizeTests.cs | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs index 21bd02741..3215b0bd5 100644 --- a/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs @@ -1,5 +1,4 @@ -using System; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; namespace Humanizer.Tests.Localisation.cs @@ -19,9 +18,9 @@ public DateHumanizeTests() [InlineData(5, "za 5 sekund")] [InlineData(6, "za 6 sekund")] [InlineData(10, "za 10 sekund")] - public void SecondsFromNow(int number, string expected) + public void SecondsFromNow(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(number).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Future); } [Theory] @@ -32,9 +31,9 @@ public void SecondsFromNow(int number, string expected) [InlineData(5, "za 5 minut")] [InlineData(6, "za 6 minut")] [InlineData(10, "za 10 minut")] - public void MinutesFromNow(int number, string expected) + public void MinutesFromNow(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(number).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Future); } [Theory] @@ -45,9 +44,9 @@ public void MinutesFromNow(int number, string expected) [InlineData(5, "za 5 hodin")] [InlineData(6, "za 6 hodin")] [InlineData(10, "za 10 hodin")] - public void HoursFromNow(int number, string expected) + public void HoursFromNow(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(number).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Future); } [Theory] @@ -57,9 +56,9 @@ public void HoursFromNow(int number, string expected) [InlineData(4, "za 4 dny")] [InlineData(9, "za 9 dnů")] [InlineData(10, "za 10 dnů")] - public void DayFromNow(int number, string expected) + public void DayFromNow(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(number).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Future); } [Theory] @@ -70,9 +69,9 @@ public void DayFromNow(int number, string expected) [InlineData(5, "za 5 měsíců")] [InlineData(6, "za 6 měsíců")] [InlineData(10, "za 10 měsíců")] - public void MonthsFromNow(int number, string expected) + public void MonthsFromNow(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(number).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Future); } [Theory] @@ -83,9 +82,9 @@ public void MonthsFromNow(int number, string expected) [InlineData(5, "za 5 let")] [InlineData(6, "za 6 let")] [InlineData(10, "za 10 let")] - public void YearsFromNow(int number, string expected) + public void YearsFromNow(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(number).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Future); } [Theory] @@ -96,9 +95,9 @@ public void YearsFromNow(int number, string expected) [InlineData(5, "před 5 sekundami")] [InlineData(6, "před 6 sekundami")] [InlineData(10, "před 10 sekundami")] - public void SecondsAgo(int number, string expected) + public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(-1 * number).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Past); } [Theory] @@ -109,9 +108,9 @@ public void SecondsAgo(int number, string expected) [InlineData(5, "před 5 minutami")] [InlineData(6, "před 6 minutami")] [InlineData(10, "před 10 minutami")] - public void MinutesAgo(int number, string expected) + public void MinutesAgo(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(-1 * number).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Past); } [Theory] @@ -122,9 +121,9 @@ public void MinutesAgo(int number, string expected) [InlineData(5, "před 5 hodinami")] [InlineData(6, "před 6 hodinami")] [InlineData(10, "před 10 hodinami")] - public void HoursAgo(int number, string expected) + public void HoursAgo(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(-1 * number).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Past); } [Theory] @@ -134,9 +133,9 @@ public void HoursAgo(int number, string expected) [InlineData(4, "před 4 dny")] [InlineData(9, "před 9 dny")] [InlineData(10, "před 10 dny")] - public void DayAgo(int number, string expected) + public void DayAgo(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(-1 * number).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Past); } [Theory] @@ -147,9 +146,9 @@ public void DayAgo(int number, string expected) [InlineData(5, "před 5 měsíci")] [InlineData(6, "před 6 měsíci")] [InlineData(10, "před 10 měsíci")] - public void MonthsAgo(int number, string expected) + public void MonthsAgo(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(-1 * number).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Past); } [Theory] @@ -160,9 +159,9 @@ public void MonthsAgo(int number, string expected) [InlineData(5, "před 5 lety")] [InlineData(6, "před 6 lety")] [InlineData(10, "před 10 lety")] - public void YearsAgo(int number, string expected) + public void YearsAgo(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(-1 * number).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Past); } } } From 1f8410e68a5d12a0e76f2c863db1e06eb269ed10 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:42:11 +0430 Subject: [PATCH 05/10] renamed TimeUnitTense to Tense --- ...provalTest.approve_public_api.approved.txt | 18 +++--- src/Humanizer.Tests/DateHumanize.cs | 4 +- src/Humanizer.Tests/DateHumanizeTests.cs | 24 +++---- .../Localisation/ar/DateHumanizeTests.cs | 12 ++-- .../Localisation/cs/DateHumanizeTests.cs | 24 +++---- src/Humanizer.Tests/ResourceKeyTests.cs | 64 +++++++++---------- src/Humanizer/DateHumanizeExtensions.cs | 4 +- src/Humanizer/Humanizer.csproj | 2 +- .../Localisation/DefaultFormatter.cs | 6 +- src/Humanizer/Localisation/IFormatter.cs | 2 +- .../Localisation/ResourceKeys.DateHumanize.cs | 4 +- .../{TimeUnitTense.cs => Tense.cs} | 2 +- 12 files changed, 83 insertions(+), 83 deletions(-) rename src/Humanizer/Localisation/{TimeUnitTense.cs => Tense.cs} (72%) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index 47b0e9e8d..482b10d6d 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -149,7 +149,7 @@ public enum LetterCasing public class DefaultFormatter { public DefaultFormatter() { } - public string DateHumanize(Humanizer.Localisation.TimeUnit timeUnit, Humanizer.Localisation.TimeUnitTense timeUnitTense, int unit) { } + public string DateHumanize(Humanizer.Localisation.TimeUnit timeUnit, Humanizer.Localisation.Tense timeUnitTense, int unit) { } public string DateHumanize_Now() { } public string TimeSpanHumanize(Humanizer.Localisation.TimeUnit timeUnit, int unit) { } public string TimeSpanHumanize_Zero() { } @@ -157,7 +157,7 @@ public class DefaultFormatter public interface IFormatter { - string DateHumanize(Humanizer.Localisation.TimeUnit timeUnit, Humanizer.Localisation.TimeUnitTense timeUnitTense, int unit); + string DateHumanize(Humanizer.Localisation.TimeUnit timeUnit, Humanizer.Localisation.Tense timeUnitTense, int unit); string DateHumanize_Now(); string TimeSpanHumanize(Humanizer.Localisation.TimeUnit timeUnit, int unit); string TimeSpanHumanize_Zero(); @@ -173,6 +173,13 @@ public class Resources public string GetResource(string resourceKey) { } } +public enum Tense +{ + Future, + Past, + value__, +} + public enum TimeUnit { Day, @@ -186,13 +193,6 @@ public enum TimeUnit Year, } -public enum TimeUnitTense -{ - Future, - Past, - value__, -} - public class NoMatchFoundException { public NoMatchFoundException() { } diff --git a/src/Humanizer.Tests/DateHumanize.cs b/src/Humanizer.Tests/DateHumanize.cs index 54852d2be..871b561c5 100644 --- a/src/Humanizer.Tests/DateHumanize.cs +++ b/src/Humanizer.Tests/DateHumanize.cs @@ -25,12 +25,12 @@ static void VerifyWithDateInjection(string expectedString, TimeSpan deltaFromNow Assert.Equal(expectedString, now.Add(deltaFromNow).Humanize(false, now)); } - public static void Verify(string expectedString, int unit, TimeUnit timeUnit, TimeUnitTense tense) + public static void Verify(string expectedString, int unit, TimeUnit timeUnit, Tense tense) { var deltaFromNow = new TimeSpan(); unit = Math.Abs(unit); - if (tense == TimeUnitTense.Past) + if (tense == Tense.Past) unit = -unit; switch (timeUnit) diff --git a/src/Humanizer.Tests/DateHumanizeTests.cs b/src/Humanizer.Tests/DateHumanizeTests.cs index dbfdd06a5..857afb282 100644 --- a/src/Humanizer.Tests/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/DateHumanizeTests.cs @@ -12,7 +12,7 @@ public class DateHumanizeTests [InlineData(60, "a minute ago")] public void SecondsAgo(int seconds, string expected) { - DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Past); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -22,7 +22,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(60, "a minute from now")] public void SecondsFromNow(int seconds, string expected) { - DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Future); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); } [Theory] @@ -34,7 +34,7 @@ public void SecondsFromNow(int seconds, string expected) [InlineData(120, "2 hours ago")] public void MinutesAgo(int minutes, string expected) { - DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Past); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -46,7 +46,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(120, "2 hours from now")] public void MinutesFromNow(int minutes, string expected) { - DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Future); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); } [Theory] @@ -56,7 +56,7 @@ public void MinutesFromNow(int minutes, string expected) [InlineData(24, "yesterday")] public void HoursAgo(int hours, string expected) { - DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Past); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -66,7 +66,7 @@ public void HoursAgo(int hours, string expected) [InlineData(24, "tomorrow")] public void HoursFfomNow(int hours, string expected) { - DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Future); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); } [Theory] @@ -76,7 +76,7 @@ public void HoursFfomNow(int hours, string expected) [InlineData(32, "one month ago")] public void DaysAgo(int days, string expected) { - DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Past); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -86,7 +86,7 @@ public void DaysAgo(int days, string expected) [InlineData(32, "one month from now")] public void DaysFromNow(int days, string expected) { - DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Future); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); } [Theory] @@ -96,7 +96,7 @@ public void DaysFromNow(int days, string expected) [InlineData(12, "one year ago")] public void MonthsAgo(int months, string expected) { - DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Past); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -106,7 +106,7 @@ public void MonthsAgo(int months, string expected) [InlineData(12, "one year from now")] public void MonthsFromNow(int months, string expected) { - DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Future); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); } [Theory] @@ -114,7 +114,7 @@ public void MonthsFromNow(int months, string expected) [InlineData(2, "2 years ago")] public void YearsAgo(int years, string expected) { - DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Past); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } [Theory] @@ -122,7 +122,7 @@ public void YearsAgo(int years, string expected) [InlineData(2, "2 years from now")] public void YearsFromNow(int years, string expected) { - DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Future); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); } } } diff --git a/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs index bf4d9b44e..00151b5cb 100644 --- a/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs @@ -15,7 +15,7 @@ public class DateHumanizeTests : AmbientCulture [InlineData(-11, "منذ 11 يوم")] public void DaysAgo(int days, string expected) { - DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Past); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -25,7 +25,7 @@ public void DaysAgo(int days, string expected) [InlineData(-11, "منذ 11 ساعة")] public void HoursAgo(int hours, string expected) { - DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Past); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -35,7 +35,7 @@ public void HoursAgo(int hours, string expected) [InlineData(-11, "منذ 11 دقيقة")] public void MinutesAgo(int minutes, string expected) { - DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Past); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -45,7 +45,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(-11, "منذ 11 شهر")] public void MonthsAgo(int months, string expected) { - DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Past); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -55,7 +55,7 @@ public void MonthsAgo(int months, string expected) [InlineData(-11, "منذ 11 ثانية")] public void SecondsAgo(int seconds, string expected) { - DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Past); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -65,7 +65,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(-11, "منذ 11 عام")] public void YearsAgo(int years, string expected) { - DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Past); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } } } diff --git a/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs index 3215b0bd5..c476954dd 100644 --- a/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs @@ -20,7 +20,7 @@ public DateHumanizeTests() [InlineData(10, "za 10 sekund")] public void SecondsFromNow(int seconds, string expected) { - DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Future); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); } [Theory] @@ -33,7 +33,7 @@ public void SecondsFromNow(int seconds, string expected) [InlineData(10, "za 10 minut")] public void MinutesFromNow(int minutes, string expected) { - DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Future); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); } [Theory] @@ -46,7 +46,7 @@ public void MinutesFromNow(int minutes, string expected) [InlineData(10, "za 10 hodin")] public void HoursFromNow(int hours, string expected) { - DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Future); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); } [Theory] @@ -58,7 +58,7 @@ public void HoursFromNow(int hours, string expected) [InlineData(10, "za 10 dnů")] public void DayFromNow(int days, string expected) { - DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Future); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); } [Theory] @@ -71,7 +71,7 @@ public void DayFromNow(int days, string expected) [InlineData(10, "za 10 měsíců")] public void MonthsFromNow(int months, string expected) { - DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Future); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); } [Theory] @@ -84,7 +84,7 @@ public void MonthsFromNow(int months, string expected) [InlineData(10, "za 10 let")] public void YearsFromNow(int years, string expected) { - DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Future); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); } [Theory] @@ -97,7 +97,7 @@ public void YearsFromNow(int years, string expected) [InlineData(10, "před 10 sekundami")] public void SecondsAgo(int seconds, string expected) { - DateHumanize.Verify(expected, seconds, TimeUnit.Second, TimeUnitTense.Past); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -110,7 +110,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(10, "před 10 minutami")] public void MinutesAgo(int minutes, string expected) { - DateHumanize.Verify(expected, minutes, TimeUnit.Minute, TimeUnitTense.Past); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -123,7 +123,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(10, "před 10 hodinami")] public void HoursAgo(int hours, string expected) { - DateHumanize.Verify(expected, hours, TimeUnit.Hour, TimeUnitTense.Past); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -135,7 +135,7 @@ public void HoursAgo(int hours, string expected) [InlineData(10, "před 10 dny")] public void DayAgo(int days, string expected) { - DateHumanize.Verify(expected, days, TimeUnit.Day, TimeUnitTense.Past); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -148,7 +148,7 @@ public void DayAgo(int days, string expected) [InlineData(10, "před 10 měsíci")] public void MonthsAgo(int months, string expected) { - DateHumanize.Verify(expected, months, TimeUnit.Month, TimeUnitTense.Past); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -161,7 +161,7 @@ public void MonthsAgo(int months, string expected) [InlineData(10, "před 10 lety")] public void YearsAgo(int years, string expected) { - DateHumanize.Verify(expected, years, TimeUnit.Year, TimeUnitTense.Past); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } } } diff --git a/src/Humanizer.Tests/ResourceKeyTests.cs b/src/Humanizer.Tests/ResourceKeyTests.cs index c0c541a9a..d75b17f39 100644 --- a/src/Humanizer.Tests/ResourceKeyTests.cs +++ b/src/Humanizer.Tests/ResourceKeyTests.cs @@ -40,40 +40,40 @@ public static IEnumerable DateHumanizeResourceKeys get { return new[] { - new object[]{ "DateHumanize_SingleSecondAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Past) }, - new object[]{ "DateHumanize_SingleMinuteAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Past) }, - new object[]{ "DateHumanize_SingleHourAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Past) }, - new object[]{ "DateHumanize_SingleDayAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Past) }, - new object[]{ "DateHumanize_SingleMonthAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Past) }, - new object[]{ "DateHumanize_SingleYearAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Past) }, - new object[]{ "DateHumanize_MultipleSecondsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Past, count: 10) }, - new object[]{ "DateHumanize_MultipleMinutesAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Past, count: 10) }, - new object[]{ "DateHumanize_MultipleHoursAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Past, count: 10) }, - new object[]{ "DateHumanize_MultipleDaysAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Past, count: 10) }, - new object[]{ "DateHumanize_MultipleMonthsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Past, count: 10) }, - new object[]{ "DateHumanize_MultipleYearsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Past, count: 10) }, + new object[]{ "DateHumanize_SingleSecondAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past) }, + new object[]{ "DateHumanize_SingleMinuteAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past) }, + new object[]{ "DateHumanize_SingleHourAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past) }, + new object[]{ "DateHumanize_SingleDayAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past) }, + new object[]{ "DateHumanize_SingleMonthAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past) }, + new object[]{ "DateHumanize_SingleYearAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past) }, + new object[]{ "DateHumanize_MultipleSecondsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past, count: 10) }, + new object[]{ "DateHumanize_MultipleMinutesAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past, count: 10) }, + new object[]{ "DateHumanize_MultipleHoursAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past, count: 10) }, + new object[]{ "DateHumanize_MultipleDaysAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past, count: 10) }, + new object[]{ "DateHumanize_MultipleMonthsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past, count: 10) }, + new object[]{ "DateHumanize_MultipleYearsAgo", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past, count: 10) }, - new object[]{ "DateHumanize_SingleSecondFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: TimeUnitTense.Future, count: 1) }, - new object[]{ "DateHumanize_SingleMinuteFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: TimeUnitTense.Future, count: 1) }, - new object[]{ "DateHumanize_SingleHourFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: TimeUnitTense.Future, count: 1) }, - new object[]{ "DateHumanize_SingleDayFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: TimeUnitTense.Future, count: 1) }, - new object[]{ "DateHumanize_SingleMonthFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: TimeUnitTense.Future, count: 1) }, - new object[]{ "DateHumanize_SingleYearFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: TimeUnitTense.Future, count: 1) }, - new object[]{ "DateHumanize_MultipleSecondsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: TimeUnitTense.Future, count: 10) }, - new object[]{ "DateHumanize_MultipleMinutesFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: TimeUnitTense.Future, count: 10) }, - new object[]{ "DateHumanize_MultipleHoursFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: TimeUnitTense.Future, count: 10) }, - new object[]{ "DateHumanize_MultipleDaysFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: TimeUnitTense.Future, count: 10) }, - new object[]{ "DateHumanize_MultipleMonthsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: TimeUnitTense.Future, count: 10) }, - new object[]{ "DateHumanize_MultipleYearsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: TimeUnitTense.Future, count: 10) }, + new object[]{ "DateHumanize_SingleSecondFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: Tense.Future, count: 1) }, + new object[]{ "DateHumanize_SingleMinuteFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: Tense.Future, count: 1) }, + new object[]{ "DateHumanize_SingleHourFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: Tense.Future, count: 1) }, + new object[]{ "DateHumanize_SingleDayFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: Tense.Future, count: 1) }, + new object[]{ "DateHumanize_SingleMonthFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: Tense.Future, count: 1) }, + new object[]{ "DateHumanize_SingleYearFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: Tense.Future, count: 1) }, + new object[]{ "DateHumanize_MultipleSecondsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, timeUnitTense: Tense.Future, count: 10) }, + new object[]{ "DateHumanize_MultipleMinutesFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, timeUnitTense: Tense.Future, count: 10) }, + new object[]{ "DateHumanize_MultipleHoursFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, timeUnitTense: Tense.Future, count: 10) }, + new object[]{ "DateHumanize_MultipleDaysFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, timeUnitTense: Tense.Future, count: 10) }, + new object[]{ "DateHumanize_MultipleMonthsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, timeUnitTense: Tense.Future, count: 10) }, + new object[]{ "DateHumanize_MultipleYearsFromNow", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, timeUnitTense: Tense.Future, count: 10) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Millisecond, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Week, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, TimeUnitTense.Past, count: 0) }, - new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, TimeUnitTense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Millisecond, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Second, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Minute, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Hour, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Day, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Week, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Month, Tense.Past, count: 0) }, + new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.GetResourceKey(TimeUnit.Year, Tense.Past, count: 0) }, new object[]{ "DateHumanize_Now", ResourceKeys.DateHumanize.Now } }; } diff --git a/src/Humanizer/DateHumanizeExtensions.cs b/src/Humanizer/DateHumanizeExtensions.cs index 90d054f6a..fdc59257f 100644 --- a/src/Humanizer/DateHumanizeExtensions.cs +++ b/src/Humanizer/DateHumanizeExtensions.cs @@ -31,7 +31,7 @@ public static string Humanize(this DateTime input, bool utcDate = true, DateTime if (input <= comparisonBase && comparisonBase.Subtract(input) < TimeSpan.FromMilliseconds(500)) return formatter.DateHumanize_Now(); - var timeUnitTense = input > comparisonBase ? TimeUnitTense.Future : TimeUnitTense.Past; + var timeUnitTense = input > comparisonBase ? Tense.Future : Tense.Past; var ts = new TimeSpan(Math.Abs(comparisonBase.Ticks - input.Ticks)); if (ts.TotalSeconds < 60) @@ -57,7 +57,7 @@ public static string Humanize(this DateTime input, bool utcDate = true, DateTime if (ts.TotalDays >= 28 && ts.TotalDays < 30) { - if (comparisonBase.Date.AddMonths(timeUnitTense == TimeUnitTense.Future ? 1 : -1) == input.Date) + if (comparisonBase.Date.AddMonths(timeUnitTense == Tense.Future ? 1 : -1) == input.Date) return formatter.DateHumanize(TimeUnit.Month, timeUnitTense, 1); return formatter.DateHumanize(TimeUnit.Day, timeUnitTense, ts.Days); diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 0cbcd0d9e..d9f49bf8b 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -71,7 +71,7 @@ - + True diff --git a/src/Humanizer/Localisation/DefaultFormatter.cs b/src/Humanizer/Localisation/DefaultFormatter.cs index c1a8a949e..867031be4 100644 --- a/src/Humanizer/Localisation/DefaultFormatter.cs +++ b/src/Humanizer/Localisation/DefaultFormatter.cs @@ -11,10 +11,10 @@ public class DefaultFormatter : IFormatter /// Time expressed in words public virtual string DateHumanize_Now() { - return GetResourceForDate(TimeUnit.Millisecond, TimeUnitTense.Past, 0); + return GetResourceForDate(TimeUnit.Millisecond, Tense.Past, 0); } - public virtual string DateHumanize(TimeUnit timeUnit, TimeUnitTense timeUnitTense, int unit) + public virtual string DateHumanize(TimeUnit timeUnit, Tense timeUnitTense, int unit) { return GetResourceForDate(timeUnit, timeUnitTense, unit); } @@ -33,7 +33,7 @@ public virtual string TimeSpanHumanize(TimeUnit timeUnit, int unit) return GetResourceForTimeSpan(timeUnit, unit); } - private string GetResourceForDate(TimeUnit unit, TimeUnitTense timeUnitTense, int count) + private string GetResourceForDate(TimeUnit unit, Tense timeUnitTense, int count) { string resourceKey = ResourceKeys.DateHumanize.GetResourceKey(unit, timeUnitTense: timeUnitTense, count: count); return count == 1 ? Format(resourceKey) : Format(resourceKey, count); diff --git a/src/Humanizer/Localisation/IFormatter.cs b/src/Humanizer/Localisation/IFormatter.cs index d280fdc36..49eac15ab 100644 --- a/src/Humanizer/Localisation/IFormatter.cs +++ b/src/Humanizer/Localisation/IFormatter.cs @@ -8,7 +8,7 @@ public interface IFormatter { string DateHumanize_Now(); - string DateHumanize(TimeUnit timeUnit, TimeUnitTense timeUnitTense, int unit); + string DateHumanize(TimeUnit timeUnit, Tense timeUnitTense, int unit); string TimeSpanHumanize_Zero(); string TimeSpanHumanize(TimeUnit timeUnit, int unit); diff --git a/src/Humanizer/Localisation/ResourceKeys.DateHumanize.cs b/src/Humanizer/Localisation/ResourceKeys.DateHumanize.cs index 63f53699c..3c49856fd 100644 --- a/src/Humanizer/Localisation/ResourceKeys.DateHumanize.cs +++ b/src/Humanizer/Localisation/ResourceKeys.DateHumanize.cs @@ -25,7 +25,7 @@ public static class DateHumanize /// Is time unit in future or past /// Number of units, default is One. /// Resource key, like DateHumanize_SingleMinuteAgo - public static string GetResourceKey(TimeUnit timeUnit, TimeUnitTense timeUnitTense, int count = 1) + public static string GetResourceKey(TimeUnit timeUnit, Tense timeUnitTense, int count = 1) { ValidateRange(count); @@ -33,7 +33,7 @@ public static string GetResourceKey(TimeUnit timeUnit, TimeUnitTense timeUnitTen return Now; var singularity = count == 1 ? Single : Multiple; - var tense = timeUnitTense == TimeUnitTense.Future ? FromNow : Ago; + var tense = timeUnitTense == Tense.Future ? FromNow : Ago; var unit = timeUnit.ToString().ToQuantity(count, ShowQuantityAs.None); return DateTimeFormat.FormatWith(singularity, unit, tense); } diff --git a/src/Humanizer/Localisation/TimeUnitTense.cs b/src/Humanizer/Localisation/Tense.cs similarity index 72% rename from src/Humanizer/Localisation/TimeUnitTense.cs rename to src/Humanizer/Localisation/Tense.cs index 41f20d15f..af6fd3a54 100644 --- a/src/Humanizer/Localisation/TimeUnitTense.cs +++ b/src/Humanizer/Localisation/Tense.cs @@ -1,6 +1,6 @@ namespace Humanizer.Localisation { - public enum TimeUnitTense + public enum Tense { Future, Past From 34e15c2569e0725a4a8d1a9d60e20f63235b71d0 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:45:04 +0430 Subject: [PATCH 06/10] moved DateHumanize.fi-FI tests to its folder & used Verify --- src/Humanizer.Tests/Humanizer.Tests.csproj | 2 +- .../DateHumanizeTests.cs} | 25 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) rename src/Humanizer.Tests/Localisation/{DateHumanizeTests.fi-FI.cs => fi-FI/DateHumanizeTests.cs} (69%) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 8aa941188..c4cc37de4 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -125,7 +125,7 @@ - + diff --git a/src/Humanizer.Tests/Localisation/DateHumanizeTests.fi-FI.cs b/src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs similarity index 69% rename from src/Humanizer.Tests/Localisation/DateHumanizeTests.fi-FI.cs rename to src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs index 3ee83fb58..a76b0268f 100644 --- a/src/Humanizer.Tests/Localisation/DateHumanizeTests.fi-FI.cs +++ b/src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs @@ -1,12 +1,11 @@ -using System; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; namespace Humanizer.Tests.Localisation { - public class DateHumanizeTests_fiFI : AmbientCulture + public class DateHumanizeTests : AmbientCulture { - public DateHumanizeTests_fiFI() + public DateHumanizeTests() : base("fi-Fi") { } @@ -18,8 +17,7 @@ public DateHumanizeTests_fiFI() [InlineData(-1, "eilen")] public void DaysAgo(int days, string expected) { - var date = DateTime.UtcNow.AddDays(days); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -29,8 +27,7 @@ public void DaysAgo(int days, string expected) [InlineData(-1, "tunti sitten")] public void HoursAgo(int hours, string expected) { - var date = DateTime.UtcNow.AddHours(hours); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -40,8 +37,7 @@ public void HoursAgo(int hours, string expected) [InlineData(-1, "minuutti sitten")] public void MinutesAgo(int minutes, string expected) { - var date = DateTime.UtcNow.AddMinutes(minutes); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -51,8 +47,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(-1, "kuukausi sitten")] public void MonthsAgo(int months, string expected) { - var date = DateTime.UtcNow.AddMonths(months); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -62,8 +57,7 @@ public void MonthsAgo(int months, string expected) [InlineData(-1, "sekuntti sitten")] public void SecondsAgo(int seconds, string expected) { - var date = DateTime.UtcNow.AddSeconds(seconds); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -73,8 +67,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(-1, "vuosi sitten")] public void YearsAgo(int years, string expected) { - var date = DateTime.UtcNow.AddYears(years); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } } } From 751c4c6196921fcdfc161c7c4b5a45dba010902b Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:47:39 +0430 Subject: [PATCH 07/10] moved DateHumanize.nb-NO tests to its folder & used Verify --- src/Humanizer.Tests/Humanizer.Tests.csproj | 2 +- .../Localisation/fi-FI/DateHumanizeTests.cs | 2 +- .../DateHumanizeTests.cs} | 27 +++++++------------ 3 files changed, 12 insertions(+), 19 deletions(-) rename src/Humanizer.Tests/Localisation/{DateHumanizeTests.nb-NO.cs => nb-NO/DateHumanizeTests.cs} (67%) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index c4cc37de4..dec73dc70 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -82,7 +82,7 @@ - + diff --git a/src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs index a76b0268f..99d9445f1 100644 --- a/src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/fi-FI/DateHumanizeTests.cs @@ -1,7 +1,7 @@ using Humanizer.Localisation; using Xunit.Extensions; -namespace Humanizer.Tests.Localisation +namespace Humanizer.Tests.Localisation.fiFI { public class DateHumanizeTests : AmbientCulture { diff --git a/src/Humanizer.Tests/Localisation/DateHumanizeTests.nb-NO.cs b/src/Humanizer.Tests/Localisation/nb-NO/DateHumanizeTests.cs similarity index 67% rename from src/Humanizer.Tests/Localisation/DateHumanizeTests.nb-NO.cs rename to src/Humanizer.Tests/Localisation/nb-NO/DateHumanizeTests.cs index 9cfc5ff0b..b8ac85b51 100644 --- a/src/Humanizer.Tests/Localisation/DateHumanizeTests.nb-NO.cs +++ b/src/Humanizer.Tests/Localisation/nb-NO/DateHumanizeTests.cs @@ -1,12 +1,11 @@ -using System; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; -namespace Humanizer.Tests.Localisation +namespace Humanizer.Tests.Localisation.nbNO { - public class DateHumanizeTests_nbNO : AmbientCulture + public class DateHumanizeTests : AmbientCulture { - public DateHumanizeTests_nbNO() + public DateHumanizeTests() : base("nb-NO") { } @@ -18,8 +17,7 @@ public DateHumanizeTests_nbNO() [InlineData(-1, "i går")] public void DaysAgo(int days, string expected) { - var date = DateTime.UtcNow.AddDays(days); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -29,8 +27,7 @@ public void DaysAgo(int days, string expected) [InlineData(-1, "en time siden")] public void HoursAgo(int hours, string expected) { - var date = DateTime.UtcNow.AddHours(hours); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -40,8 +37,7 @@ public void HoursAgo(int hours, string expected) [InlineData(-1, "et minutt siden")] public void MinutesAgo(int minutes, string expected) { - var date = DateTime.UtcNow.AddMinutes(minutes); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -51,8 +47,7 @@ public void MinutesAgo(int minutes, string expected) [InlineData(-1, "en måned siden")] public void MonthsAgo(int months, string expected) { - var date = DateTime.UtcNow.AddMonths(months); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -62,8 +57,7 @@ public void MonthsAgo(int months, string expected) [InlineData(-1, "et sekund siden")] public void SecondsAgo(int seconds, string expected) { - var date = DateTime.UtcNow.AddSeconds(seconds); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -73,8 +67,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(-1, "et år siden")] public void YearsAgo(int years, string expected) { - var date = DateTime.UtcNow.AddYears(years); - Assert.Equal(expected, date.Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } } } From f4e41ed43dab0b3f857152ad8aed3dd400ffb0e0 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:51:49 +0430 Subject: [PATCH 08/10] moved date ro & ru tests to their folders & used Verify --- src/Humanizer.Tests/Humanizer.Tests.csproj | 4 +- .../DateHumanizeTests.cs} | 6 +-- .../DateHumanizeTests.cs} | 39 ++++++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) rename src/Humanizer.Tests/Localisation/{DateHumanizeTests.ro-RO.cs => ro-Ro/DateHumanizeTests.cs} (94%) rename src/Humanizer.Tests/Localisation/{DateHumanizeTests.ru-RU.cs => ru-RU/DateHumanizeTests.cs} (77%) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index dec73dc70..444ac46d6 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -101,7 +101,7 @@ - + @@ -111,7 +111,7 @@ - + diff --git a/src/Humanizer.Tests/Localisation/DateHumanizeTests.ro-RO.cs b/src/Humanizer.Tests/Localisation/ro-Ro/DateHumanizeTests.cs similarity index 94% rename from src/Humanizer.Tests/Localisation/DateHumanizeTests.ro-RO.cs rename to src/Humanizer.Tests/Localisation/ro-Ro/DateHumanizeTests.cs index 9047d13a9..1dcbd091d 100644 --- a/src/Humanizer.Tests/Localisation/DateHumanizeTests.ro-RO.cs +++ b/src/Humanizer.Tests/Localisation/ro-Ro/DateHumanizeTests.cs @@ -1,16 +1,16 @@ using System; using Xunit; -namespace Humanizer.Tests.Localisation +namespace Humanizer.Tests.Localisation.roRo { /// /// Test that for values bigger than 19 "de" is added between the numeral /// and the time unit: http://ebooks.unibuc.ro/filologie/NForascu-DGLR/numerale.htm. /// There is no test for months since there are only 12 of them in a year. /// - public class RomanianDateHumanizeTests : AmbientCulture + public class DateHumanizeTests : AmbientCulture { - public RomanianDateHumanizeTests() : base("ro-RO") + public DateHumanizeTests() : base("ro-RO") { } diff --git a/src/Humanizer.Tests/Localisation/DateHumanizeTests.ru-RU.cs b/src/Humanizer.Tests/Localisation/ru-RU/DateHumanizeTests.cs similarity index 77% rename from src/Humanizer.Tests/Localisation/DateHumanizeTests.ru-RU.cs rename to src/Humanizer.Tests/Localisation/ru-RU/DateHumanizeTests.cs index aaf040fd6..4d9d207cc 100644 --- a/src/Humanizer.Tests/Localisation/DateHumanizeTests.ru-RU.cs +++ b/src/Humanizer.Tests/Localisation/ru-RU/DateHumanizeTests.cs @@ -1,12 +1,11 @@ -using System; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; -namespace Humanizer.Tests.Localisation +namespace Humanizer.Tests.Localisation.ruRU { - public class RussianDateHumanizeTests : AmbientCulture + public class DateHumanizeTests : AmbientCulture { - public RussianDateHumanizeTests() : base("ru-RU") + public DateHumanizeTests() : base("ru-RU") { } @@ -27,10 +26,9 @@ public RussianDateHumanizeTests() : base("ru-RU") [InlineData(24, "24 секунды назад")] [InlineData(25, "25 секунд назад")] [InlineData(40, "40 секунд назад")] - public void NSecondsAgo(int number, string expected) + public void SecondsAgo(int seconds, string expected) { - var humanize = DateTime.UtcNow.AddSeconds(-1 * number).Humanize(); - Assert.Equal(expected, humanize); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -50,10 +48,9 @@ public void NSecondsAgo(int number, string expected) [InlineData(24, "24 минуты назад")] [InlineData(25, "25 минут назад")] [InlineData(40, "40 минут назад")] - public void NMinutesAgo(int number, string expected) + public void MinutesAgo(int minutes, string expected) { - var humanize = DateTime.UtcNow.AddMinutes(-1 * number).Humanize(); - Assert.Equal(expected, humanize); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -70,10 +67,9 @@ public void NMinutesAgo(int number, string expected) [InlineData(21, "21 час назад")] [InlineData(22, "22 часа назад")] [InlineData(23, "23 часа назад")] - public void NHoursAgo(int number, string expected) + public void HoursAgo(int hours, string expected) { - var humanize = DateTime.UtcNow.AddHours(-1 * number).Humanize(); - Assert.Equal(expected, humanize); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -92,10 +88,9 @@ public void NHoursAgo(int number, string expected) [InlineData(23, "23 дня назад")] [InlineData(24, "24 дня назад")] [InlineData(25, "25 дней назад")] - public void NDaysAgo(int number, string expected) + public void DaysAgo(int days, string expected) { - var humanize = DateTime.UtcNow.Date.AddDays(-1 * number).Humanize(); - Assert.Equal(expected, humanize); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -107,10 +102,9 @@ public void NDaysAgo(int number, string expected) [InlineData(6, "6 месяцев назад")] [InlineData(10, "10 месяцев назад")] [InlineData(11, "11 месяцев назад")] - public void NMonthsAgo(int number, string expected) + public void MonthsAgo(int months, string expected) { - var humanize = DateTime.UtcNow.Date.AddMonths(-1 * number).Humanize(); - Assert.Equal(expected, humanize); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -128,10 +122,9 @@ public void NMonthsAgo(int number, string expected) [InlineData(121, "121 год назад")] [InlineData(222, "222 года назад")] [InlineData(325, "325 лет назад")] - public void NYearsAgo(int number, string expected) + public void YearsAgo(int years, string expected) { - var humanize = DateTime.UtcNow.Date.AddYears(-1 * number).Humanize(); - Assert.Equal(expected, humanize); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } } } From 52920fe3e8e42d96581d4d234778f63de9ddfeef Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 12:56:21 +0430 Subject: [PATCH 09/10] changed de DateTests to use Verify --- src/Humanizer.Tests/DateHumanizeTests.cs | 2 +- .../Localisation/de/DateHumanizeTests.cs | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Humanizer.Tests/DateHumanizeTests.cs b/src/Humanizer.Tests/DateHumanizeTests.cs index 857afb282..b5892e2b9 100644 --- a/src/Humanizer.Tests/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/DateHumanizeTests.cs @@ -64,7 +64,7 @@ public void HoursAgo(int hours, string expected) [InlineData(10, "10 hours from now")] [InlineData(23, "23 hours from now")] [InlineData(24, "tomorrow")] - public void HoursFfomNow(int hours, string expected) + public void HoursFromNow(int hours, string expected) { DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); } diff --git a/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs index cef1b60f8..d9d9f6a73 100644 --- a/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs @@ -1,4 +1,5 @@ using System; +using Humanizer.Localisation; using Xunit; using Xunit.Extensions; @@ -15,15 +16,15 @@ public class DateHumanizeTests : AmbientCulture [InlineData(-1, "gestern")] public void DaysAgo(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] [InlineData(2, "in 2 Tagen")] [InlineData(1, "morgen")] - public void InDays(int days, string expected) + public void DaysFromNow(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); } [Theory] @@ -33,15 +34,15 @@ public void InDays(int days, string expected) [InlineData(-1, "vor einer Stunde")] public void HoursAgo(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] [InlineData(2, "in 2 Stunden")] [InlineData(1, "in einer Stunde")] - public void InHours(int hours, string expected) + public void HoursFromNow(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); } [Theory] @@ -51,15 +52,15 @@ public void InHours(int hours, string expected) [InlineData(-1, "vor einer Minute")] public void MinutesAgo(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] [InlineData(2, "in 2 Minuten")] [InlineData(1, "in einer Minute")] - public void InMinutes(int minutes, string expected) + public void MinutesFromNow(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); } [Theory] @@ -69,15 +70,15 @@ public void InMinutes(int minutes, string expected) [InlineData(-1, "vor einem Monat")] public void MonthsAgo(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] [InlineData(2, "in 2 Monaten")] [InlineData(1, "in einem Monat")] - public void InMonths(int months, string expected) + public void MonthsFromNow(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); } [Theory] @@ -87,15 +88,15 @@ public void InMonths(int months, string expected) [InlineData(-1, "vor einer Sekunde")] public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] [InlineData(2, "in 2 Sekunden")] [InlineData(1, "in einer Sekunde")] - public void InSeconds(int seconds, string expected) + public void SecondsFromNow(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); } [Theory] @@ -105,15 +106,15 @@ public void InSeconds(int seconds, string expected) [InlineData(-1, "vor einem Jahr")] public void YearsAgo(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } [Theory] [InlineData(2, "in 2 Jahren")] [InlineData(1, "in einem Jahr")] - public void InYears(int years, string expected) + public void YearsFromNow(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); } } } From 17c55ae2c919abc1ab7d606303db9807aa421a28 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Sun, 6 Apr 2014 13:00:32 +0430 Subject: [PATCH 10/10] updated sk date tests to use Verify --- .../Localisation/de/DateHumanizeTests.cs | 4 +- .../Localisation/sk/DateHumanizeTests.cs | 67 +++++++++---------- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs index d9d9f6a73..f11917b46 100644 --- a/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs @@ -1,6 +1,4 @@ -using System; -using Humanizer.Localisation; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; namespace Humanizer.Tests.Localisation.de diff --git a/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs index 9ce873cef..0842d4175 100644 --- a/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs @@ -1,5 +1,4 @@ -using System; -using Xunit; +using Humanizer.Localisation; using Xunit.Extensions; namespace Humanizer.Tests.Localisation.sk @@ -19,9 +18,9 @@ public DateHumanizeTests() [InlineData(5, "o 5 sekúnd")] [InlineData(6, "o 6 sekúnd")] [InlineData(10, "o 10 sekúnd")] - public void SecondsFromNow(int number, string expected) - { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(number).Humanize()); + public void SecondsFromNow(int seconds, string expected) + { + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); } [Theory] @@ -32,9 +31,9 @@ public void SecondsFromNow(int number, string expected) [InlineData(5, "o 5 minút")] [InlineData(6, "o 6 minút")] [InlineData(10, "o 10 minút")] - public void MinutesFromNow(int number, string expected) - { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(number).Humanize()); + public void MinutesFromNow(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); } [Theory] @@ -45,11 +44,11 @@ public void MinutesFromNow(int number, string expected) [InlineData(5, "o 5 hodín")] [InlineData(6, "o 6 hodín")] [InlineData(10, "o 10 hodín")] - public void HoursFromNow(int number, string expected) - { - Assert.Equal(expected, DateTime.UtcNow.AddHours(number).Humanize()); + public void HoursFromNow(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); } - + [Theory] [InlineData(1, "zajtra")] [InlineData(2, "o 2 dni")] @@ -57,9 +56,9 @@ public void HoursFromNow(int number, string expected) [InlineData(4, "o 4 dni")] [InlineData(9, "o 9 dní")] [InlineData(10, "o 10 dní")] - public void DayFromNow(int number, string expected) - { - Assert.Equal(expected, DateTime.UtcNow.AddDays(number).Humanize()); + public void DaysFromNow(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); } [Theory] @@ -70,9 +69,9 @@ public void DayFromNow(int number, string expected) [InlineData(5, "o 5 mesiacov")] [InlineData(6, "o 6 mesiacov")] [InlineData(10, "o 10 mesiacov")] - public void MonthsFromNow(int number, string expected) - { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(number).Humanize()); + public void MonthsFromNow(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); } [Theory] @@ -83,9 +82,9 @@ public void MonthsFromNow(int number, string expected) [InlineData(5, "o 5 rokov")] [InlineData(6, "o 6 rokov")] [InlineData(10, "o 10 rokov")] - public void YearsFromNow(int number, string expected) - { - Assert.Equal(expected, DateTime.UtcNow.AddYears(number).Humanize()); + public void YearsFromNow(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); } [Theory] @@ -96,9 +95,9 @@ public void YearsFromNow(int number, string expected) [InlineData(5, "pred 5 sekundami")] [InlineData(6, "pred 6 sekundami")] [InlineData(10, "pred 10 sekundami")] - public void SecondsAgo(int number, string expected) + public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(-1*number).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -109,9 +108,9 @@ public void SecondsAgo(int number, string expected) [InlineData(5, "pred 5 minútami")] [InlineData(6, "pred 6 minútami")] [InlineData(10, "pred 10 minútami")] - public void MinutesAgo(int number, string expected) + public void MinutesAgo(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(-1*number).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -122,9 +121,9 @@ public void MinutesAgo(int number, string expected) [InlineData(5, "pred 5 hodinami")] [InlineData(6, "pred 6 hodinami")] [InlineData(10, "pred 10 hodinami")] - public void HoursAgo(int number, string expected) + public void HoursAgo(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(-1*number).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -134,9 +133,9 @@ public void HoursAgo(int number, string expected) [InlineData(4, "pred 4 dňami")] [InlineData(9, "pred 9 dňami")] [InlineData(10, "pred 10 dňami")] - public void DayAgo(int number, string expected) + public void DaysAgo(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(-1*number).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -147,9 +146,9 @@ public void DayAgo(int number, string expected) [InlineData(5, "pred 5 mesiacmi")] [InlineData(6, "pred 6 mesiacmi")] [InlineData(10, "pred 10 mesiacmi")] - public void MonthsAgo(int number, string expected) + public void MonthsAgo(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(-1*number).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -160,9 +159,9 @@ public void MonthsAgo(int number, string expected) [InlineData(5, "pred 5 rokmi")] [InlineData(6, "pred 6 rokmi")] [InlineData(10, "pred 10 rokmi")] - public void YearsAgo(int number, string expected) + public void YearsAgo(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(-1*number).Humanize()); - } + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); + } } }