Skip to content

Commit 542e5f1

Browse files
authored
Tests for abbdrivated genitive month names parsing (dotnet/corefx#40595)
Commit migrated from dotnet/corefx@e62f9b6
1 parent 176de9b commit 542e5f1

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoAbbreviatedMonthGenitiveNames.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,36 @@ public void AbbreviatedMonthGenitiveNames_Format_ReturnsExpected()
8484
format.AbbreviatedMonthGenitiveNames = new string[] { "GenJan", "GenFeb", "GenMar", "GenApr", "GenMay", "GenJun", "GenJul", "GenAug", "GenSep", "GenOct", "GenNov", "GenDec", "Gen" };
8585

8686
var dateTime = new DateTime(1976, 6, 19);
87-
Assert.Equal("19 GenJun 76", dateTime.ToString("d MMM yy", format));
87+
string formattedDate = dateTime.ToString("d MMM yy", format);
88+
Assert.Equal("19 GenJun 76", formattedDate);
89+
Assert.Equal(dateTime, DateTime.ParseExact(formattedDate, "d MMM yy", format));
90+
Assert.Equal(dateTime, DateTime.Parse(formattedDate, format));
91+
}
92+
93+
[Fact]
94+
public void TestAbbreviatedGenitiveNamesWithAllCultures()
95+
{
96+
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
97+
DateTime dt = new DateTime(2000, 1, 20);
98+
99+
foreach (CultureInfo ci in cultures)
100+
{
101+
string formattedDate = dt.ToString("d MMM yyyy", ci);
102+
103+
for (int i = 0; i < 12; i++)
104+
{
105+
if (!ci.DateTimeFormat.MonthNames[i].Equals(ci.DateTimeFormat.MonthGenitiveNames[i]) ||
106+
!ci.DateTimeFormat.AbbreviatedMonthNames[i].Equals(ci.DateTimeFormat.AbbreviatedMonthGenitiveNames[i]))
107+
{
108+
// We have genitive month names, we expect parsing to work and produce the exact original result.
109+
Assert.Equal(dt, DateTime.Parse(formattedDate, ci));
110+
break;
111+
}
112+
}
113+
114+
// ParseExact should succeeded all the time even with non genitive cases .
115+
Assert.Equal(dt, DateTime.ParseExact(formattedDate, "d MMM yyyy", ci));
116+
}
88117
}
89118

90119
[Fact]

0 commit comments

Comments
 (0)