You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
43
external/corefx/src/System.Globalization.Calendars/System.Globalization.Calendars.sln
vendored
Normal file
43
external/corefx/src/System.Globalization.Calendars/System.Globalization.Calendars.sln
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||

|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.22609.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Globalization.Calendars.Tests", "tests\System.Globalization.Calendars.Tests.csproj", "{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{} = {}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
|
||||
DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
|
||||
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
|
||||
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
|
||||
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
8
external/corefx/src/System.Globalization.Calendars/dir.props
vendored
Normal file
8
external/corefx/src/System.Globalization.Calendars/dir.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.1.0.0</AssemblyVersion>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
</PropertyGroup>
|
||||
</Project>
|
9
external/corefx/src/System.Globalization.Calendars/ref/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Globalization.Calendars/ref/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netcoreapp;
|
||||
uap;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@@ -0,0 +1,25 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.ChineseLunisolarCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.EastAsianLunisolarCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.GregorianCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.GregorianCalendarTypes))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.HebrewCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.HijriCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.JapaneseCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.JapaneseLunisolarCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.JulianCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.KoreanCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.KoreanLunisolarCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.PersianCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.TaiwanCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.TaiwanLunisolarCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.ThaiBuddhistCalendar))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Globalization.UmAlQuraCalendar))]
|
||||
|
||||
|
16
external/corefx/src/System.Globalization.Calendars/ref/System.Globalization.Calendars.csproj
vendored
Normal file
16
external/corefx/src/System.Globalization.Calendars/ref/System.Globalization.Calendars.csproj
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System.Globalization.Calendars.Forwards.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\System.Globalization\ref\System.Globalization.csproj" />
|
||||
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
9
external/corefx/src/System.Globalization.Calendars/src/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Globalization.Calendars/src/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
net463-Windows_NT;
|
||||
netcoreapp;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
21
external/corefx/src/System.Globalization.Calendars/src/System.Globalization.Calendars.csproj
vendored
Normal file
21
external/corefx/src/System.Globalization.Calendars/src/System.Globalization.Calendars.csproj
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyName>System.Globalization.Calendars</AssemblyName>
|
||||
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
|
||||
</PropertyGroup>
|
||||
<!-- Help VS understand available configurations -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<TargetingPackReference Include="mscorlib" Condition="'$(TargetGroup)' == 'net463'" />
|
||||
<TargetingPackReference Include="System.Private.CoreLib" Condition="'$(TargetGroup)' == 'netcoreapp'" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ReferenceFromRuntime Include="System.Private.CoreLib" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
464
external/corefx/src/System.Globalization.Calendars/tests/CalendarHelpers.cs
vendored
Normal file
464
external/corefx/src/System.Globalization.Calendars/tests/CalendarHelpers.cs
vendored
Normal file
@@ -0,0 +1,464 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public static class CalendarHelpers
|
||||
{
|
||||
public enum DataType
|
||||
{
|
||||
Year = 1,
|
||||
Month = 2,
|
||||
Day = 8
|
||||
}
|
||||
|
||||
public static Calendar[] s_calendars = new Calendar[]
|
||||
{
|
||||
new ThaiBuddhistCalendar(),
|
||||
new JapaneseCalendar(),
|
||||
new KoreanCalendar(),
|
||||
new TaiwanCalendar(),
|
||||
new GregorianCalendar(GregorianCalendarTypes.Arabic),
|
||||
new GregorianCalendar(GregorianCalendarTypes.Localized),
|
||||
new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench),
|
||||
new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish),
|
||||
new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench),
|
||||
new GregorianCalendar(GregorianCalendarTypes.USEnglish),
|
||||
new HijriCalendar(),
|
||||
new HebrewCalendar(),
|
||||
new JulianCalendar(),
|
||||
new TaiwanLunisolarCalendar(),
|
||||
new ChineseLunisolarCalendar(),
|
||||
new KoreanLunisolarCalendar(),
|
||||
new PersianCalendar(),
|
||||
|
||||
new JapaneseLunisolarCalendar(),
|
||||
new UmAlQuraCalendar()
|
||||
};
|
||||
|
||||
private static int MinEra(Calendar calendar) => calendar.GetEra(calendar.MinSupportedDateTime);
|
||||
private static int MaxEra(Calendar calendar) => calendar.GetEra(calendar.MaxSupportedDateTime);
|
||||
|
||||
private static int MaxCalendarYearInEra(Calendar calendar, int era)
|
||||
{
|
||||
int[] eras = calendar.Eras;
|
||||
Assert.InRange(era, 0, eras[0]);
|
||||
if (eras.Length == 1 || era == eras[0] || era == 0)
|
||||
{
|
||||
return calendar.GetYear(calendar.MaxSupportedDateTime);
|
||||
}
|
||||
return calendar.GetYear(calendar.ToDateTime(1, 1, 1, 0, 0, 0, 0, era + 1).AddDays(-1)) + 1;
|
||||
}
|
||||
|
||||
private static int MaxGregorianYearInEra(Calendar calendar, int era)
|
||||
{
|
||||
int[] eras = calendar.Eras;
|
||||
Assert.InRange(era, 0, eras[0]);
|
||||
if (eras.Length == 1 || era == eras[0] || era == 0)
|
||||
{
|
||||
return calendar.MaxSupportedDateTime.Year;
|
||||
}
|
||||
return (calendar.ToDateTime(1, 1, 1, 0, 0, 0, 0, era + 1).AddDays(-1)).Year;
|
||||
}
|
||||
|
||||
private static int MinGregorianYearInEra(Calendar calendar, int era)
|
||||
{
|
||||
int[] eras = calendar.Eras;
|
||||
Assert.InRange(era, 0, eras[0]);
|
||||
if (eras.Length == 1 || era == eras[eras.Length - 1] || era == 0)
|
||||
{
|
||||
return calendar.MinSupportedDateTime.Year;
|
||||
}
|
||||
return calendar.ToDateTime(1, 1, 1, 0, 0, 0, 0, era).Year;
|
||||
}
|
||||
|
||||
private static int MinCalendarYearInEra(Calendar calendar, int era)
|
||||
{
|
||||
int[] eras = calendar.Eras;
|
||||
Assert.InRange(era, 0, eras[0]);
|
||||
if (eras.Length == 1 || era == eras[eras.Length - 1] || era == 0)
|
||||
{
|
||||
return calendar.GetYear(calendar.MinSupportedDateTime);
|
||||
}
|
||||
return calendar.GetYear(calendar.ToDateTime(1, 1, 1, 0, 0, 0, 0, era));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Calendars_TestData()
|
||||
{
|
||||
foreach (Calendar calendar in s_calendars)
|
||||
{
|
||||
yield return new object[] { calendar };
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Year_Month_Day_Era_TestData(DataType type, bool ignoreJapaneseLunisolarCalendar)
|
||||
{
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
foreach (Calendar calendar in s_calendars)
|
||||
{
|
||||
if (ignoreJapaneseLunisolarCalendar && calendar is JapaneseLunisolarCalendar)
|
||||
{
|
||||
// desktop has a bug in JapaneseLunisolarCalendar which is fixed in .Net Core.
|
||||
// in case of a new era starts in the middle of a month which means part of the month will belong to one
|
||||
// era and the rest will belong to the new era. When calculating the calendar year number for dates which
|
||||
// in the rest of the month and exist in the new started era, we should still use the old era info instead
|
||||
// of the new era info because the rest of the month still belong to the year of last era.
|
||||
// https://github.com/dotnet/coreclr/pull/3662
|
||||
continue;
|
||||
}
|
||||
foreach (int era in calendar.Eras)
|
||||
{
|
||||
int year = MaxCalendarYearInEra(calendar, era) - 2;
|
||||
|
||||
// Year is invalid
|
||||
yield return new object[] { calendar, -1, month, day, era, "year" };
|
||||
yield return new object[] { calendar, 0, month, day, era, "year" };
|
||||
yield return new object[] { calendar, MaxCalendarYearInEra(calendar, era) + 1, month, day, era, "year" };
|
||||
|
||||
if ((type & DataType.Month) != 0)
|
||||
{
|
||||
// Month is invalid
|
||||
yield return new object[] { calendar, year, -1, day, era, "month" };
|
||||
yield return new object[] { calendar, year, 0, day, era, "month" };
|
||||
yield return new object[] { calendar, year, calendar.GetMonthsInYear(year, era) + 1, day, era, "month" };
|
||||
}
|
||||
|
||||
if ((type & DataType.Day) != 0)
|
||||
{
|
||||
// Day is invalid
|
||||
yield return new object[] { calendar, year, month, -1, era, "day" };
|
||||
yield return new object[] { calendar, year, month, 0, era, "day" };
|
||||
yield return new object[] { calendar, year, month, calendar.GetDaysInMonth(year, month, era) + 1, era, "day" };
|
||||
}
|
||||
}
|
||||
// Year is invalid
|
||||
yield return new object[] { calendar, MinCalendarYearInEra(calendar, MinEra(calendar)) - 1, month, day, MinEra(calendar), "year" };
|
||||
|
||||
// Era is invalid
|
||||
yield return new object[] { calendar, calendar.GetYear(calendar.MaxSupportedDateTime), month, day, MinEra(calendar) - 2, "era" };
|
||||
yield return new object[] { calendar, calendar.GetYear(calendar.MaxSupportedDateTime), month, day, MaxEra(calendar) + 1, "era" };
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> DateTime_TestData()
|
||||
{
|
||||
foreach (Calendar calendar in s_calendars)
|
||||
{
|
||||
DateTime minDate = calendar.MinSupportedDateTime;
|
||||
if (minDate != DateTime.MinValue)
|
||||
{
|
||||
yield return new object[] { calendar, minDate.AddDays(-1) };
|
||||
}
|
||||
DateTime maxDate = calendar.MaxSupportedDateTime;
|
||||
if (maxDate != DateTime.MaxValue)
|
||||
{
|
||||
yield return new object[] { calendar, maxDate.AddDays(1) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void GetDaysInYear_Invalid(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInYear(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void GetMonthsInYear_Invalid(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetMonthsInYear(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year | DataType.Month, true)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.NetcoreUwp)]
|
||||
public static void GetDaysInMonth_Invalid_net46(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year | DataType.Month, false)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void GetDaysInMonth_Invalid_netcore(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year | DataType.Month | DataType.Day, false)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void IsLeapDay_Invalid_netcore(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapDay(year, month, day, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year | DataType.Month | DataType.Day, true)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.NetcoreUwp)]
|
||||
public static void IsLeapDay_Invalid_net46(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapDay(year, month, day, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year | DataType.Month, false)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void IsLeapMonth_Invalid_netcore(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year | DataType.Month, true)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.NetcoreUwp)]
|
||||
public static void IsLeapMonth_Invalid_net46(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void IsLeapYear_Invalid(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapYear(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void GetLeapMonth_Invalid(Calendar calendar, int year, int month, int day, int era, string expectedParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(expectedParamName, () => calendar.GetLeapMonth(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddYears_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.ThrowsAny<ArgumentException>(() => calendar.AddYears(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.ThrowsAny<ArgumentException>(() => calendar.AddYears(calendar.MinSupportedDateTime, -1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddMonths_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.ThrowsAny<ArgumentException>(() => calendar.AddMonths(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.ThrowsAny<ArgumentException>(() => calendar.AddMonths(calendar.MinSupportedDateTime, -1)); // JapaneseCalendar throws ArgumentException
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("months", () => calendar.AddMonths(DateTime.Now, -120001));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("months", () => calendar.AddMonths(DateTime.Now, 120001));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddDays_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddDays(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddDays(calendar.MinSupportedDateTime, -1));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddDays(DateTime.Now, -120001 * 30));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddDays(DateTime.Now, 120001 * 30));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddHours_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddHours(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddHours(calendar.MinSupportedDateTime, -1));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddHours(DateTime.Now, -120001 * 30 * 24));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddHours(DateTime.Now, 120001 * 30 * 24));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddMinutes_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddMinutes(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddMinutes(calendar.MinSupportedDateTime, -1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddSeconds_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddSeconds(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddSeconds(calendar.MinSupportedDateTime, -1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AddMilliseconds_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddMilliseconds(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.Throws<ArgumentException>(() => calendar.AddMilliseconds(calendar.MinSupportedDateTime, -1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void GetWeekOfYear_Invalid(Calendar calendar)
|
||||
{
|
||||
// Rule is outside supported range
|
||||
Assert.Throws<ArgumentOutOfRangeException>("rule", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay - 1, DayOfWeek.Saturday));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("rule", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstFourDayWeek + 1, DayOfWeek.Saturday));
|
||||
|
||||
// FirstDayOfWeek is outside supported range
|
||||
Assert.Throws<ArgumentOutOfRangeException>("firstDayOfWeek", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday - 1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("firstDayOfWeek", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Saturday + 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void ToDateTime_Invalid(Calendar calendar)
|
||||
{
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
int hour = 1;
|
||||
int minute = 1;
|
||||
int second = 1;
|
||||
int millisecond = 1;
|
||||
foreach (int era in calendar.Eras)
|
||||
{
|
||||
int year = MaxCalendarYearInEra(calendar, era) - 2;
|
||||
|
||||
// Year is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(-1, month, day, hour, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(0, month, day, hour, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(MaxCalendarYearInEra(calendar, era) + 1, month, day, hour, minute, second, millisecond, era));
|
||||
|
||||
// Month is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, -1, day, hour, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, 0, day, hour, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, calendar.GetMonthsInYear(year, era) + 1, day, hour, minute, second, millisecond, era));
|
||||
|
||||
// Day is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, -1, hour, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, 0, hour, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, calendar.GetDaysInMonth(year, month, era) + 1, minute, second, millisecond, era));
|
||||
|
||||
// Hour is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, -1, minute, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, 60, minute, second, millisecond, era));
|
||||
|
||||
// Minute is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, hour, -1, second, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, hour, 60, second, millisecond, era));
|
||||
|
||||
// Second is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, hour, minute, -1, millisecond, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, hour, minute, 60, millisecond, era));
|
||||
|
||||
// Millisecond is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, hour, minute, second, -1, era));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(year, month, day, hour, minute, second, 1000, era));
|
||||
}
|
||||
// Year is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(MinCalendarYearInEra(calendar, MinEra(calendar)) - 1, month, day, hour, minute, second, millisecond, MinEra(calendar)));
|
||||
|
||||
// Era is invalid
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(calendar.GetYear(calendar.MaxSupportedDateTime), month, day, hour, minute, second, millisecond, MinEra(calendar) - 2));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(calendar.GetYear(calendar.MaxSupportedDateTime), month, day, hour, minute, second, millisecond, MaxEra(calendar) + 1));
|
||||
|
||||
// New date is out of range
|
||||
DateTime minDateTime = calendar.MinSupportedDateTime;
|
||||
int minEra = calendar.GetEra(minDateTime);
|
||||
int minYear = calendar.GetYear(minDateTime);
|
||||
|
||||
DateTime maxDateTime = calendar.MaxSupportedDateTime;
|
||||
int maxEra = calendar.GetEra(maxDateTime);
|
||||
int maxYear = calendar.GetYear(maxDateTime);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(minYear - 1, minDateTime.Month, minDateTime.Day, minDateTime.Hour, minDateTime.Minute, minDateTime.Second, minDateTime.Millisecond, minEra));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.ToDateTime(maxYear + 1, maxDateTime.Month, maxDateTime.Day, maxDateTime.Hour, maxDateTime.Minute, maxDateTime.Second, maxDateTime.Millisecond, maxEra));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void ToFourDigitYear_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(-1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(MaxCalendarYearInEra(calendar, MaxEra(calendar)) + 1));
|
||||
|
||||
if (!(calendar is JapaneseLunisolarCalendar))
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(MinCalendarYearInEra(calendar, MinEra(calendar)) - 2));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void TwoDigitYearMax_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.TwoDigitYearMax = 98);
|
||||
int max = Math.Max(MaxGregorianYearInEra(calendar, MaxEra(calendar)), MaxCalendarYearInEra(calendar, MaxEra(calendar)));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.TwoDigitYearMax = max + 1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetEra_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
// JapaneseCalendar throws on Unix (ICU), but not on Windows
|
||||
if ((calendar is JapaneseCalendar && PlatformDetection.IsWindows) || calendar is HebrewCalendar || calendar is TaiwanLunisolarCalendar || calendar is JapaneseLunisolarCalendar)
|
||||
{
|
||||
calendar.GetEra(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => calendar.GetEra(dt));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetYear_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetYear(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetMonth_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetMonth(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetDayOfYear_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfYear(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetDayOfMonth_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfMonth(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetDayOfWeek_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
if (calendar is HijriCalendar || calendar is UmAlQuraCalendar || calendar is PersianCalendar || calendar is HebrewCalendar)
|
||||
{
|
||||
calendar.GetDayOfWeek(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfWeek(dt));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
external/corefx/src/System.Globalization.Calendars/tests/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Globalization.Calendars/tests/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard1.3;
|
||||
netstandard;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@@ -0,0 +1,35 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarAddMonths
|
||||
{
|
||||
private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
|
||||
|
||||
private const int MaxMonths = 120000;
|
||||
|
||||
public static IEnumerable<object[]> AddMonths_TestData()
|
||||
{
|
||||
yield return new object[] { DateTime.Now, 0 };
|
||||
yield return new object[] { DateTime.MinValue, s_randomDataGenerator.GetInt32(-55) % MaxMonths + 1 };
|
||||
yield return new object[] { DateTime.MaxValue, -1 * s_randomDataGenerator.GetInt32(-55) % MaxMonths - 1 };
|
||||
yield return new object[] { s_randomDataGenerator.GetDateTime(-55).AddMonths(1), -1 };
|
||||
yield return new object[] { new DateTime(2000, 2, 29, 10, 30, 24), 13 }; // February in a leap year
|
||||
yield return new object[] { new DateTime(1996, 2, 29, 10, 30, 24), 48 }; // February in a leap year
|
||||
yield return new object[] { new DateTime(1996, 3, 29, 10, 30, 24), 48 }; // Other month in a leap year
|
||||
yield return new object[] { new DateTime(1999, 2, 28, 10, 30, 24), 48 }; // February in a common year
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AddMonths_TestData))]
|
||||
public void AddMonths(DateTime time, int months)
|
||||
{
|
||||
Assert.Equal(time.AddMonths(months), new GregorianCalendar().AddMonths(time, months));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarAddYears
|
||||
{
|
||||
private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
|
||||
|
||||
public static IEnumerable<object[]> AddYears_TestData()
|
||||
{
|
||||
yield return new object[] { DateTime.Now, 0 };
|
||||
yield return new object[] { DateTime.MinValue, 100 };
|
||||
yield return new object[] { DateTime.MaxValue, -99 };
|
||||
yield return new object[] { s_randomDataGenerator.GetDateTime(-55), 1 };
|
||||
|
||||
// February in a leap year
|
||||
yield return new object[] { new DateTime(2000, 2, 29, 10, 30, 24), 13 };
|
||||
yield return new object[] { new DateTime(1996, 2, 29, 10, 30, 24), 4 };
|
||||
|
||||
// Month other than February in a leap year
|
||||
yield return new object[] { new DateTime(1996, 3, 29, 10, 30, 24), 48 };
|
||||
|
||||
// February in a common year
|
||||
yield return new object[] { new DateTime(1999, 2, 28, 10, 30, 24), 48 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AddYears_TestData))]
|
||||
public void AddYears(DateTime time, int years)
|
||||
{
|
||||
Assert.Equal(time.AddYears(years), new GregorianCalendar().AddYears(time, years));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarCtor
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Empty()
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
Assert.Equal(GregorianCalendarTypes.Localized, calendar.CalendarType);
|
||||
Assert.False(calendar.IsReadOnly);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GregorianCalendarTypes_TestData()
|
||||
{
|
||||
yield return new object[] { GregorianCalendarTypes.Arabic };
|
||||
yield return new object[] { GregorianCalendarTypes.Localized };
|
||||
yield return new object[] { GregorianCalendarTypes.MiddleEastFrench };
|
||||
yield return new object[] { GregorianCalendarTypes.TransliteratedEnglish };
|
||||
yield return new object[] { GregorianCalendarTypes.TransliteratedFrench };
|
||||
yield return new object[] { GregorianCalendarTypes.USEnglish };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GregorianCalendarTypes_TestData))]
|
||||
public void Ctor_GregorianCalendarType(GregorianCalendarTypes type)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar(type);
|
||||
Assert.Equal(type, calendar.CalendarType);
|
||||
Assert.False(calendar.IsReadOnly);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(GregorianCalendarTypes.Localized - 1)]
|
||||
[InlineData(GregorianCalendarTypes.TransliteratedFrench + 1)]
|
||||
public void Ctor_GregorianCalendarTypes_InvalidType_ThrowsArgumentOutOfRangeException(GregorianCalendarTypes type)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("type", () => new GregorianCalendar(type));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GregorianCalendarTypes_TestData))]
|
||||
public void CalendarType_Set(GregorianCalendarTypes type)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.CalendarType = type;
|
||||
Assert.Equal(type, calendar.CalendarType);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(GregorianCalendarTypes.Localized - 1)]
|
||||
[InlineData(GregorianCalendarTypes.TransliteratedFrench + 1)]
|
||||
public void CalendarType_Set_InvalidType_ThrowsArgumentOutOfRangeException(GregorianCalendarTypes type)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("m_type", () => calendar.CalendarType = type);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarEras
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(GregorianCalendarTypes.Arabic)]
|
||||
[InlineData(GregorianCalendarTypes.Localized)]
|
||||
[InlineData(GregorianCalendarTypes.MiddleEastFrench)]
|
||||
[InlineData(GregorianCalendarTypes.TransliteratedEnglish)]
|
||||
[InlineData(GregorianCalendarTypes.TransliteratedFrench)]
|
||||
[InlineData(GregorianCalendarTypes.USEnglish)]
|
||||
public void Eras(GregorianCalendarTypes calendarType)
|
||||
{
|
||||
Calendar calendar = new GregorianCalendar(calendarType);
|
||||
Assert.Equal(new int[] { 1 }, calendar.Eras);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetDayOfMonth
|
||||
{
|
||||
public static IEnumerable<object[]> GetDayOfMonth_TestData()
|
||||
{
|
||||
yield return new object[] { new DateTime(2006, 1, 1) };
|
||||
yield return new object[] { new DateTime(2006, 1, 17) };
|
||||
yield return new object[] { new DateTime(2006, 1, 31) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetDayOfMonth_TestData))]
|
||||
public void GetDayOfMonth(DateTime time)
|
||||
{
|
||||
Assert.Equal(time.Day, new GregorianCalendar().GetDayOfMonth(time));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetDayOfWeek
|
||||
{
|
||||
public static IEnumerable<object[]> GetDayOfWeek_TestData()
|
||||
{
|
||||
yield return new object[] { new DateTime(2007, 1, 1) };
|
||||
yield return new object[] { new DateTime(2006, 2, 28) };
|
||||
yield return new object[] { new DateTime(2006, 3, 1) };
|
||||
yield return new object[] { new DateTime(2006, 8, 31) };
|
||||
yield return new object[] { new DateTime(2008, 2, 29) };
|
||||
yield return new object[] { new DateTime(2006, 12, 30) };
|
||||
yield return new object[] { new DateTime(2006, 12, 31) };
|
||||
yield return new object[] { DateTime.MaxValue };
|
||||
yield return new object[] { DateTime.MinValue };
|
||||
yield return new object[] { new DateTime(2000, 2, 29) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetDayOfWeek_TestData))]
|
||||
public void GetDayOfWeek(DateTime time)
|
||||
{
|
||||
Assert.Equal(time.DayOfWeek, new GregorianCalendar().GetDayOfWeek(time));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetDayOfYear
|
||||
{
|
||||
public static IEnumerable<object[]> GetDayOfYear_TestData()
|
||||
{
|
||||
yield return new object[] { new DateTime(2006, 11, 29) };
|
||||
yield return new object[] { new DateTime(2006, 1, 1) };
|
||||
yield return new object[] { new DateTime(2007, 12, 31) };
|
||||
yield return new object[] { new DateTime(2000, 2, 29) };
|
||||
yield return new object[] { new DateTime(2001, 2, 28) };
|
||||
yield return new object[] { new DateTime(2000, 1, 1) };
|
||||
yield return new object[] { new DateTime(2000, 12, 31) };
|
||||
yield return new object[] { DateTime.MaxValue };
|
||||
yield return new object[] { DateTime.MinValue };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetDayOfYear_TestData))]
|
||||
public void GetDayOfYear(DateTime time)
|
||||
{
|
||||
Assert.Equal(time.DayOfYear, new GregorianCalendar().GetDayOfYear(time));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
using static System.Globalization.Tests.GregorianCalendarTestUtilities;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetDaysInMonth
|
||||
{
|
||||
private static readonly int[] s_daysInMonthInLeapYear = new int[] { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
private static readonly int[] s_daysInMonthInCommonYear = new int[] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
public static IEnumerable<object[]> GetDaysInMonth_TestData()
|
||||
{
|
||||
// Leap year, month that isn't February
|
||||
yield return new object[] { RandomLeapYear(), RandomMonthNotFebruary() };
|
||||
|
||||
// Leap year, February
|
||||
yield return new object[] { RandomLeapYear(), 2 };
|
||||
|
||||
// Common year, February
|
||||
yield return new object[] { RandomCommonYear(), 2 };
|
||||
|
||||
// Common year, month that isn't February
|
||||
yield return new object[] { RandomCommonYear(), RandomMonthNotFebruary() };
|
||||
|
||||
// Max supported year
|
||||
yield return new object[] { 9999, RandomMonth() };
|
||||
|
||||
// Min supported year
|
||||
yield return new object[] { 1, RandomMonth() };
|
||||
|
||||
// Random year, random month
|
||||
yield return new object[] { RandomYear(), RandomMonth() };
|
||||
|
||||
// Random year, minimum month
|
||||
yield return new object[] { RandomYear(), 1 };
|
||||
|
||||
// Random year, maximum month
|
||||
yield return new object[] { RandomYear(), 12 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetDaysInMonth_TestData))]
|
||||
public void GetDaysInMonth(int year, int month)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
int expected = IsLeapYear(year) ? s_daysInMonthInLeapYear[month] : s_daysInMonthInCommonYear[month];
|
||||
Assert.Equal(expected, calendar.GetDaysInMonth(year, month));
|
||||
Assert.Equal(expected, calendar.GetDaysInMonth(year, month, 0));
|
||||
Assert.Equal(expected, calendar.GetDaysInMonth(year, month, 1));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
using static System.Globalization.Tests.GregorianCalendarTestUtilities;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetDaysInYear
|
||||
{
|
||||
public static IEnumerable<object[]> GetDaysInYear_TestData()
|
||||
{
|
||||
// Random years
|
||||
yield return new object[] { RandomLeapYear() };
|
||||
yield return new object[] { RandomCommonYear() };
|
||||
yield return new object[] { RandomYear() };
|
||||
yield return new object[] { 100 };
|
||||
yield return new object[] { 400 };
|
||||
|
||||
// Boundary years
|
||||
yield return new object[] { 9999 };
|
||||
yield return new object[] { 1 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetDaysInYear_TestData))]
|
||||
public void GetDaysInYear(int year)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
int expected = IsLeapYear(year) ? 366 : 365;
|
||||
Assert.Equal(expected, calendar.GetDaysInYear(year));
|
||||
Assert.Equal(expected, calendar.GetDaysInYear(year, 0));
|
||||
Assert.Equal(expected, calendar.GetDaysInYear(year, 1));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
using static System.Globalization.Tests.GregorianCalendarTestUtilities;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetEra
|
||||
{
|
||||
public static IEnumerable<object[]> GetEra_TestData()
|
||||
{
|
||||
// February in a leap year
|
||||
yield return new object[] { new DateTime(RandomLeapYear(), 2, 29, 10, 30, 12) };
|
||||
|
||||
// Month other than February in a leap year
|
||||
yield return new object[] { new DateTime(RandomLeapYear(), RandomMonthNotFebruary(), 28, 10, 30, 20) };
|
||||
|
||||
// February in a common year
|
||||
yield return new object[] { new DateTime(RandomCommonYear(), 2, 28, 10, 20, 30) };
|
||||
|
||||
// Month other than February in a common year
|
||||
yield return new object[] { new DateTime(RandomCommonYear(), RandomMonthNotFebruary(), 28, 10, 20, 30) };
|
||||
|
||||
// Any month in the maximum supported year
|
||||
yield return new object[] { new DateTime(9999, RandomMonth(), 20, 8, 20, 30) };
|
||||
|
||||
// Any month in the minimum supported year
|
||||
yield return new object[] { new DateTime(1, RandomMonth(), 20, 8, 20, 30) };
|
||||
|
||||
// Maximum month in the maximum supported year
|
||||
yield return new object[] { new DateTime(9999, 12, 20, 8, 20, 30) };
|
||||
|
||||
// Minimum month in the minimum supported year
|
||||
yield return new object[] { new DateTime(1, 1, 20, 8, 20, 30) };
|
||||
|
||||
// Any month in any year
|
||||
yield return new object[] { new DateTime(RandomYear(), RandomMonth(), 20, 8, 20, 30) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetEra_TestData))]
|
||||
public void GetEra(DateTime time)
|
||||
{
|
||||
Assert.Equal(1, new GregorianCalendar().GetEra(time));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarGetLeapMonth
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2016)]
|
||||
[InlineData(9999)]
|
||||
public void GetLeapMonth(int year)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
Assert.Equal(0, calendar.GetLeapMonth(year, 0));
|
||||
Assert.Equal(0, calendar.GetLeapMonth(year, 1));
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user