Skip to content

Commit

Permalink
Register Portuguese TimeSpan localisation as "pt".
Browse files Browse the repository at this point in the history
According to #601, the localisation is good for
Portuguese in general, not just for Brazilian Portuguese.
I copied the unit test, so that we can prove that there's no regression.

Additionally, I copied the `OrginalizeTests`, because those were
already registered as "pt", not "pt-BR".

Note that `NumberToWords` is still only valid for pt-BR unless confirmed
otherwise.
  • Loading branch information
hangy committed Dec 7, 2016
1 parent 7e0d462 commit a1d03cc
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Humanizer.Tests.Shared/Humanizer.Tests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Localisation\pt-BR\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\pt-BR\OrdinalizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\pt-BR\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\pt\OrdinalizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\pt\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ResourcesTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ro-Ro\CollectionFormatterTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ro-Ro\DateHumanizeTests.cs" />
Expand Down
87 changes: 87 additions & 0 deletions src/Humanizer.Tests.Shared/Localisation/pt/OrdinalizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Xunit;

namespace Humanizer.Tests.Localisation.pt
{
[UseCulture("pt")]
public class OrdinalizeTests
{

[Theory]
[InlineData("0", "0")]
[InlineData("1", "1º")]
[InlineData("2", "2º")]
[InlineData("3", "3º")]
[InlineData("4", "4º")]
[InlineData("5", "5º")]
[InlineData("6", "6º")]
[InlineData("23", "23º")]
[InlineData("100", "100º")]
[InlineData("101", "101º")]
[InlineData("102", "102º")]
[InlineData("103", "103º")]
[InlineData("1001", "1001º")]
public void OrdinalizeString(string number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Masculine), ordinalized);
}

[Theory]
[InlineData("0", "0")]
[InlineData("1", "1ª")]
[InlineData("2", "2ª")]
[InlineData("3", "3ª")]
[InlineData("4", "4ª")]
[InlineData("5", "5ª")]
[InlineData("6", "6ª")]
[InlineData("23", "23ª")]
[InlineData("100", "100ª")]
[InlineData("101", "101ª")]
[InlineData("102", "102ª")]
[InlineData("103", "103ª")]
[InlineData("1001", "1001ª")]
public void OrdinalizeStringFeminine(string number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized);
}

[Theory]
[InlineData(0, "0")]
[InlineData(1, "1º")]
[InlineData(2, "2º")]
[InlineData(3, "3º")]
[InlineData(4, "4º")]
[InlineData(5, "5º")]
[InlineData(6, "6º")]
[InlineData(10, "10º")]
[InlineData(23, "23º")]
[InlineData(100, "100º")]
[InlineData(101, "101º")]
[InlineData(102, "102º")]
[InlineData(103, "103º")]
[InlineData(1001, "1001º")]
public void OrdinalizeNumber(int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Masculine), ordinalized);
}

[Theory]
[InlineData(0, "0")]
[InlineData(1, "1ª")]
[InlineData(2, "2ª")]
[InlineData(3, "3ª")]
[InlineData(4, "4ª")]
[InlineData(5, "5ª")]
[InlineData(6, "6ª")]
[InlineData(10, "10ª")]
[InlineData(23, "23ª")]
[InlineData(100, "100ª")]
[InlineData(101, "101ª")]
[InlineData(102, "102ª")]
[InlineData(103, "103ª")]
[InlineData(1001, "1001ª")]
public void OrdinalizeNumberFeminine(int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using Xunit;

namespace Humanizer.Tests.Localisation.pt
{
[UseCulture("pt")]
public class TimeSpanHumanizeTests
{
[Fact]
public void TwoWeeks()
{
Assert.Equal("2 semanas", TimeSpan.FromDays(14).Humanize());
}

[Fact]
public void OneWeek()
{
Assert.Equal("1 semana", TimeSpan.FromDays(7).Humanize());
}

[Fact]
public void SixDays()
{
Assert.Equal("6 dias", TimeSpan.FromDays(6).Humanize());
}

[Fact]
public void TwoDays()
{
Assert.Equal("2 dias", TimeSpan.FromDays(2).Humanize());
}

[Fact]
public void OneDay()
{
Assert.Equal("1 dia", TimeSpan.FromDays(1).Humanize());
}

[Fact]
public void TwoHours()
{
Assert.Equal("2 horas", TimeSpan.FromHours(2).Humanize());
}

[Fact]
public void OneHour()
{
Assert.Equal("1 hora", TimeSpan.FromHours(1).Humanize());
}

[Fact]
public void TwoMinutes()
{
Assert.Equal("2 minutos", TimeSpan.FromMinutes(2).Humanize());
}

[Fact]
public void OneMinute()
{
Assert.Equal("1 minuto", TimeSpan.FromMinutes(1).Humanize());
}

[Fact]
public void TwoSeconds()
{
Assert.Equal("2 segundos", TimeSpan.FromSeconds(2).Humanize());
}

[Fact]
public void OneSecond()
{
Assert.Equal("1 segundo", TimeSpan.FromSeconds(1).Humanize());
}

[Fact]
public void TwoMilliseconds()
{
Assert.Equal("2 milisegundos", TimeSpan.FromMilliseconds(2).Humanize());
}

[Fact]
public void OneMillisecond()
{
Assert.Equal("1 milisegundo", TimeSpan.FromMilliseconds(1).Humanize());
}

[Fact]
public void NoTime()
{
// This one doesn't make a lot of sense but ... w/e
Assert.Equal("sem horário", TimeSpan.Zero.Humanize());
}
}
}
2 changes: 1 addition & 1 deletion src/Humanizer/Configuration/FormatterRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US"))
RegisterCzechSlovakPolishFormatter("pl");
RegisterCzechSlovakPolishFormatter("sk");
RegisterDefaultFormatter("bg");
RegisterDefaultFormatter("pt-BR");
RegisterDefaultFormatter("pt");
RegisterDefaultFormatter("sv");
RegisterDefaultFormatter("tr");
RegisterDefaultFormatter("vi");
Expand Down

0 comments on commit a1d03cc

Please sign in to comment.