Skip to content

Commit

Permalink
chore: More adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jan 5, 2025
1 parent bf0dd59 commit 368179d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
41 changes: 35 additions & 6 deletions src/Uno.UI.Tests/Windows_Globalization/Given_CalendarFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,55 @@
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace Uno.UI.Tests.Windows_Globalization
{
[TestClass]
public class Given_CalendarFormatter
{
[TestMethod]
[DataRow("day month year", "en-US", "{month.numeric}/{day.integer}/{year.full}")]
[DataRow("day month year", "en-CA", "{year.full}-{month.numeric}-{day.integer(2)}")]
[DataRow("day month year", "en-GB", "{day.integer(2)}/{month.numeric}/{year.full}")]
[DataRow("day month year", "fr-CA", "{year.full}-{month.numeric}-{day.integer(2)}")]
[DataRow("day month year", "fr-FR", "{day.integer(2)}/{month.numeric}/{year.full}")]
[DataRow("day month year", "hu-HU", "{year.full}. {month.numeric}. {day.integer(2)}.")]
[DataRow("day month year", "en-US", "{month.integer}/{day.integer}/{year.full}")]
[DataRow("day month year", "en-CA", "{year.full}-{month.integer(2)}-{day.integer(2)}")]
[DataRow("day month year", "en-GB", "{day.integer(2)}/{month.integer(2)}/{year.full}")]
[DataRow("day month year", "fr-CA", "{year.full}-{month.integer(2)}-{day.integer(2)}")]
[DataRow("day month year", "fr-FR", "{day.integer(2)}/{month.integer(2)}/{year.full}")]
[DataRow("day month year", "hu-HU", "{year.full}. {month.integer(2)}. {day.integer(2)}.")]
public void When_UsingVariousLanguages(string format, string language, string expectedPattern)
{
var sut = new DateTimeFormatter(format, new[] { language });
var firstPattern = sut.Patterns[0];
firstPattern.Should().Be(expectedPattern);
}

[TestMethod]
public void When_FormattingDateVariants_ShouldProduceExpectedFormats()
{
var expectedResults = new Dictionary<string, string>
{
{ "{day.integer}/{month.integer}/{year.full}", "27/6/2024" },
{ "{month.full} {year.full}", "June 2024" },
{ "{month.full} {day.integer}", "June 27" },
{ "{dayofweek.abbreviated}, {day.integer} {month.abbreviated} {year.full}", "Thu, 27 Jun 2024" },
{ "{year.full}-{month.integer}-{day.integer}", "2024-6-27" },
{ "{day.integer}/{month.integer}/{year.abbreviated}", "27/6/24" },
{ "{day.integer} {month.abbreviated} {year.full}", "27 Jun 2024" },
{ "{month.full} {day.integer}, {year.full}", "June 27, 2024" },
{ "{month.abbreviated} {day.integer}, {year.full}", "Jun 27, 2024" },
{ "{dayofweek.full}, {day.integer} {month.full} {year.full}", "Thursday, 27 June 2024" },
{ "{dayofweek.abbreviated}, {day.integer} {month.abbreviated} {year.abbreviated}", "Thu, 27 Jun 24" }
};
foreach (var kvp in expectedResults)
{
var template = kvp.Key;
var expected = kvp.Value;
var formatter = new DateTimeFormatter(template);
var formattedDate = formatter.Format(new(2024, 6, 27, 14, 30, 0, TimeSpan.Zero));
Assert.AreEqual(expected, formattedDate, $"Mismatch for template: {template}");
}
}

#if !NET7_0_OR_GREATER // https://github.com/unoplatform/uno/issues/9080
[TestMethod]
[DataRow("day", "en-US|fr-CA|ru-RU", "{day.integer}|{day.integer}|{day.integer}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ void AddToBuilder(StringBuilder builder, char lastChar, int count)

while (count >= 4)
{
builder.Append("{year.full(4)}");
builder.Append("{year.full}");
count -= 4;
}

Expand Down Expand Up @@ -668,7 +668,7 @@ void AddToBuilder(StringBuilder builder, char lastChar, int count)

while (count >= 1)
{
builder.Append("{month.integer(1)}");
builder.Append("{month.integer}");
count -= 1;
}

Expand All @@ -695,7 +695,7 @@ void AddToBuilder(StringBuilder builder, char lastChar, int count)

while (count >= 1)
{
builder.Append("{day.integer(1)}");
builder.Append("{day.integer}");
count -= 1;
}

Expand Down

0 comments on commit 368179d

Please sign in to comment.