+++ /dev/null
-// 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 System.IO;
-using System.Reflection;
-
-namespace System.Globalization.Tests
-{
- public static class CharUnicodeInfoTestData
- {
- private static readonly Lazy<List<CharUnicodeInfoTestCase>> s_testCases = new Lazy<List<CharUnicodeInfoTestCase>>(() =>
- {
- List<CharUnicodeInfoTestCase> testCases = new List<CharUnicodeInfoTestCase>();
- string fileName =
- CharUnicodeInfo.GetUnicodeCategory('\u10D0') == UnicodeCategory.LowercaseLetter ? "UnicodeData.11.0.txt" :
- CharUnicodeInfo.GetUnicodeCategory('\u037f') == UnicodeCategory.OtherNotAssigned ? "UnicodeData6.3.txt" : "UnicodeData.8.0.txt";
- Stream stream = typeof(CharUnicodeInfoGetUnicodeCategoryTests).GetTypeInfo().Assembly.GetManifestResourceStream(fileName);
- using (StreamReader reader = new StreamReader(stream))
- {
- while (!reader.EndOfStream)
- {
- Parse(testCases, reader.ReadLine());
- }
- }
- return testCases;
- });
-
- public static List<CharUnicodeInfoTestCase> TestCases => s_testCases.Value;
-
- private static int s_rangeMinCodePoint;
- private static void Parse(List<CharUnicodeInfoTestCase> testCases, string line)
- {
- // Data is in the format:
- // code-value;
- // character-name;
- // general-category;
- // canonical-combining-classes; (ignored)
- // bidirecional-category; (ignored)
- // character-decomposition-mapping; (ignored)
- // decimal-digit-value; (ignored)
- // digit-value; (ignoed)
- // number-value;
- string[] data = line.Split(';');
- string charValueString = data[0];
- string charName = data[1];
- string charCategoryString = data[2];
- string numericValueString = data[8];
-
- int codePoint = int.Parse(charValueString, NumberStyles.HexNumber);
- Parse(testCases, codePoint, charCategoryString, numericValueString);
-
- if (charName.EndsWith("First>"))
- {
- s_rangeMinCodePoint = codePoint;
- }
- else if (charName.EndsWith("Last>"))
- {
- // Assumes that we have already found a range start
- for (int rangeCodePoint = s_rangeMinCodePoint + 1; rangeCodePoint < codePoint; rangeCodePoint++)
- {
- // Assumes that all code points in the range have the same numeric value
- // and general category
- Parse(testCases, rangeCodePoint, charCategoryString, numericValueString);
- }
- }
- }
-
- private static Dictionary<string, UnicodeCategory> s_unicodeCategories = new Dictionary<string, UnicodeCategory>
- {
- ["Pe"] = UnicodeCategory.ClosePunctuation,
- ["Pc"] = UnicodeCategory.ConnectorPunctuation,
- ["Cc"] = UnicodeCategory.Control,
- ["Sc"] = UnicodeCategory.CurrencySymbol,
- ["Pd"] = UnicodeCategory.DashPunctuation,
- ["Nd"] = UnicodeCategory.DecimalDigitNumber,
- ["Me"] = UnicodeCategory.EnclosingMark,
- ["Pf"] = UnicodeCategory.FinalQuotePunctuation,
- ["Cf"] = UnicodeCategory.Format,
- ["Pi"] = UnicodeCategory.InitialQuotePunctuation,
- ["Nl"] = UnicodeCategory.LetterNumber,
- ["Zl"] = UnicodeCategory.LineSeparator,
- ["Ll"] = UnicodeCategory.LowercaseLetter,
- ["Sm"] = UnicodeCategory.MathSymbol,
- ["Lm"] = UnicodeCategory.ModifierLetter,
- ["Sk"] = UnicodeCategory.ModifierSymbol,
- ["Mn"] = UnicodeCategory.NonSpacingMark,
- ["Ps"] = UnicodeCategory.OpenPunctuation,
- ["Lo"] = UnicodeCategory.OtherLetter,
- ["Cn"] = UnicodeCategory.OtherNotAssigned,
- ["No"] = UnicodeCategory.OtherNumber,
- ["Po"] = UnicodeCategory.OtherPunctuation,
- ["So"] = UnicodeCategory.OtherSymbol,
- ["Po"] = UnicodeCategory.OtherPunctuation,
- ["Zp"] = UnicodeCategory.ParagraphSeparator,
- ["Co"] = UnicodeCategory.PrivateUse,
- ["Zs"] = UnicodeCategory.SpaceSeparator,
- ["Mc"] = UnicodeCategory.SpacingCombiningMark,
- ["Cs"] = UnicodeCategory.Surrogate,
- ["Lt"] = UnicodeCategory.TitlecaseLetter,
- ["Lu"] = UnicodeCategory.UppercaseLetter
- };
-
- private static void Parse(List<CharUnicodeInfoTestCase> testCases, int codePoint, string charCategoryString, string numericValueString)
- {
- string codeValueRepresentation = codePoint > char.MaxValue ? char.ConvertFromUtf32(codePoint) : ((char)codePoint).ToString();
- double numericValue = ParseNumericValueString(numericValueString);
- UnicodeCategory generalCategory = s_unicodeCategories[charCategoryString];
-
- testCases.Add(new CharUnicodeInfoTestCase()
- {
- Utf32CodeValue = codeValueRepresentation,
- GeneralCategory = generalCategory,
- NumericValue = numericValue,
- CodePoint = codePoint
- });
- }
-
- private static double ParseNumericValueString(string numericValueString)
- {
- if (numericValueString.Length == 0)
- {
- // Parsing empty string (no numeric value)
- return -1;
- }
-
- int fractionDelimeterIndex = numericValueString.IndexOf("/");
- if (fractionDelimeterIndex == -1)
- {
- // Parsing basic number
- return double.Parse(numericValueString);
- }
-
- // Unicode datasets display fractions not decimals (e.g. 1/4 instead of 0.25),
- // so we should parse them as such
- string numeratorString = numericValueString.Substring(0, fractionDelimeterIndex);
- double numerator = double.Parse(numeratorString);
-
- string denominatorString = numericValueString.Substring(fractionDelimeterIndex + 1);
- double denominator = double.Parse(denominatorString);
-
- return numerator / denominator;
- }
- }
-
- public class CharUnicodeInfoTestCase
- {
- public string Utf32CodeValue { get; set; }
- public int CodePoint { get; set; }
- public UnicodeCategory GeneralCategory { get; set; }
- public double NumericValue { get; set; }
- }
-}
+++ /dev/null
-// 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 CharUnicodeInfoGetUnicodeCategoryTests
- {
- [Fact]
- public void GetUnicodeCategory()
- {
- foreach (CharUnicodeInfoTestCase testCase in CharUnicodeInfoTestData.TestCases)
- {
- if (testCase.Utf32CodeValue.Length == 1)
- {
- // Test the char overload for a single char
- GetUnicodeCategory(testCase.Utf32CodeValue[0], testCase.GeneralCategory);
- }
- // Test the string overload for a surrogate pair or a single char
- GetUnicodeCategory(testCase.Utf32CodeValue, new UnicodeCategory[] { testCase.GeneralCategory });
-#if netcoreapp
- Assert.Equal(testCase.GeneralCategory, CharUnicodeInfo.GetUnicodeCategory(testCase.CodePoint));
-#endif // netcoreapp
- }
- }
-
- [Theory]
- [InlineData('\uFFFF', UnicodeCategory.OtherNotAssigned)]
- public void GetUnicodeCategory(char ch, UnicodeCategory expected)
- {
- UnicodeCategory actual = CharUnicodeInfo.GetUnicodeCategory(ch);
- Assert.True(actual == expected, ErrorMessage(ch, expected, actual));
- }
-
- [Theory]
- [InlineData("aA1!", new UnicodeCategory[] { UnicodeCategory.LowercaseLetter, UnicodeCategory.UppercaseLetter, UnicodeCategory.DecimalDigitNumber, UnicodeCategory.OtherPunctuation })]
- [InlineData("\uD808\uDF6C", new UnicodeCategory[] { UnicodeCategory.OtherLetter, UnicodeCategory.Surrogate })]
- [InlineData("a\uD808\uDF6Ca", new UnicodeCategory[] { UnicodeCategory.LowercaseLetter, UnicodeCategory.OtherLetter, UnicodeCategory.Surrogate, UnicodeCategory.LowercaseLetter })]
- public void GetUnicodeCategory(string s, UnicodeCategory[] expected)
- {
- for (int i = 0; i < expected.Length; i++)
- {
- Assert.Equal(expected[i], CharUnicodeInfo.GetUnicodeCategory(s, i));
- }
- }
-
- [Fact]
- public void GetUnicodeCategory_String_InvalidSurrogatePairs()
- {
- // High, high surrogate pair
- GetUnicodeCategory("\uD808\uD808", new UnicodeCategory[] { UnicodeCategory.Surrogate, UnicodeCategory.Surrogate });
-
- // Low, low surrogate pair
- GetUnicodeCategory("\uDF6C\uDF6C", new UnicodeCategory[] { UnicodeCategory.Surrogate, UnicodeCategory.Surrogate });
-
- // Low, high surrogate pair
- GetUnicodeCategory("\uDF6C\uD808", new UnicodeCategory[] { UnicodeCategory.Surrogate, UnicodeCategory.Surrogate });
- }
-
- [Fact]
- public void GetUnicodeCategory_Invalid()
- {
- AssertExtensions.Throws<ArgumentNullException>("s", () => CharUnicodeInfo.GetUnicodeCategory(null, 0));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetUnicodeCategory("abc", -1));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetUnicodeCategory("abc", 3));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetUnicodeCategory("", 0));
- }
-
- [Fact]
- public void GetNumericValue()
- {
- foreach (CharUnicodeInfoTestCase testCase in CharUnicodeInfoTestData.TestCases)
- {
- if (testCase.Utf32CodeValue.Length == 1)
- {
- // Test the char overload for a single char
- GetNumericValue(testCase.Utf32CodeValue[0], testCase.NumericValue);
- }
- // Test the string overload for a surrogate pair
- GetNumericValue(testCase.Utf32CodeValue, new double[] { testCase.NumericValue });
- }
- }
-
- [Theory]
- [InlineData('\uFFFF', -1)]
- public void GetNumericValue(char ch, double expected)
- {
- double actual = CharUnicodeInfo.GetNumericValue(ch);
- Assert.True(expected == actual, ErrorMessage(ch, expected, actual));
- }
-
- [Theory]
- [MemberData(nameof(s_GetNumericValueData))]
- public void GetNumericValue(string s, double[] expected)
- {
- for (int i = 0; i < expected.Length; i++)
- {
- Assert.Equal(expected[i], CharUnicodeInfo.GetNumericValue(s, i));
- }
- }
-
- public static readonly object[][] s_GetNumericValueData =
- {
- new object[] {"aA1!", new double[] { -1, -1, 1, -1 }},
- // Numeric surrogate (CUNEIFORM NUMERIC SIGN FIVE BAN2 VARIANT FORM)
- new object[] {"\uD809\uDC55", new double[] { 5, -1 }},
- new object[] {"a\uD809\uDC55a", new double[] { -1, 5, -1 , -1 }},
- // Numeric surrogate (CUNEIFORM NUMERIC SIGN FIVE BAN2 VARIANT FORM)
- new object[] {"\uD808\uDF6C", new double[] { -1, -1 }},
- new object[] {"a\uD808\uDF6Ca", new double[] { -1, -1, -1, -1 }},
- };
-
- [Fact]
- public void GetNumericValue_Invalid()
- {
- AssertExtensions.Throws<ArgumentNullException>("s", () => CharUnicodeInfo.GetNumericValue(null, 0));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("abc", -1));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("abc", 3));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("", 0));
- }
-
- private static string ErrorMessage(char ch, object expected, object actual)
- {
- return $"CodeValue: {((int)ch).ToString("X")}; Expected: {expected}; Actual: {actual}";
- }
-
- public static string s_numericsCodepoints =
- "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039" +
- "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669" +
- "\u06f0\u06f1\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9" +
- "\u07c0\u07c1\u07c2\u07c3\u07c4\u07c5\u07c6\u07c7\u07c8\u07c9" +
- "\u0966\u0967\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f" +
- "\u09e6\u09e7\u09e8\u09e9\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef" +
- "\u0a66\u0a67\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f" +
- "\u0ae6\u0ae7\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef" +
- "\u0b66\u0b67\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f" +
- "\u0be6\u0be7\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef" +
- "\u0c66\u0c67\u0c68\u0c69\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f" +
- "\u0ce6\u0ce7\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef" +
- "\u0d66\u0d67\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f" +
- "\u0e50\u0e51\u0e52\u0e53\u0e54\u0e55\u0e56\u0e57\u0e58\u0e59" +
- "\u0ed0\u0ed1\u0ed2\u0ed3\u0ed4\u0ed5\u0ed6\u0ed7\u0ed8\u0ed9" +
- "\u0f20\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\u0f29" +
- "\u1040\u1041\u1042\u1043\u1044\u1045\u1046\u1047\u1048\u1049" +
- "\u1090\u1091\u1092\u1093\u1094\u1095\u1096\u1097\u1098\u1099" +
- "\u17e0\u17e1\u17e2\u17e3\u17e4\u17e5\u17e6\u17e7\u17e8\u17e9" +
- "\u1810\u1811\u1812\u1813\u1814\u1815\u1816\u1817\u1818\u1819" +
- "\u1946\u1947\u1948\u1949\u194a\u194b\u194c\u194d\u194e\u194f" +
- "\u19d0\u19d1\u19d2\u19d3\u19d4\u19d5\u19d6\u19d7\u19d8\u19d9" +
- "\u1a80\u1a81\u1a82\u1a83\u1a84\u1a85\u1a86\u1a87\u1a88\u1a89" +
- "\u1a90\u1a91\u1a92\u1a93\u1a94\u1a95\u1a96\u1a97\u1a98\u1a99" +
- "\u1b50\u1b51\u1b52\u1b53\u1b54\u1b55\u1b56\u1b57\u1b58\u1b59" +
- "\u1bb0\u1bb1\u1bb2\u1bb3\u1bb4\u1bb5\u1bb6\u1bb7\u1bb8\u1bb9" +
- "\u1c40\u1c41\u1c42\u1c43\u1c44\u1c45\u1c46\u1c47\u1c48\u1c49" +
- "\u1c50\u1c51\u1c52\u1c53\u1c54\u1c55\u1c56\u1c57\u1c58\u1c59" +
- "\ua620\ua621\ua622\ua623\ua624\ua625\ua626\ua627\ua628\ua629" +
- "\ua8d0\ua8d1\ua8d2\ua8d3\ua8d4\ua8d5\ua8d6\ua8d7\ua8d8\ua8d9" +
- "\ua900\ua901\ua902\ua903\ua904\ua905\ua906\ua907\ua908\ua909" +
- "\ua9d0\ua9d1\ua9d2\ua9d3\ua9d4\ua9d5\ua9d6\ua9d7\ua9d8\ua9d9" +
- "\uaa50\uaa51\uaa52\uaa53\uaa54\uaa55\uaa56\uaa57\uaa58\uaa59" +
- "\uabf0\uabf1\uabf2\uabf3\uabf4\uabf5\uabf6\uabf7\uabf8\uabf9" +
- "\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19";
-
- public static string s_nonNumericsCodepoints =
- "abcdefghijklmnopqrstuvwxyz" +
- "\u1369\u136a\u136b\u136c\u136d\u136e\u136f\u1370\u1371\u1372\u1373" +
- "\u1374\u1375\u1376\u1377\u1378\u1379\u137a\u137b\u137c\u137d";
-
- public static string s_numericNonDecimalCodepoints =
- "\u00b2\u00b3\u00b9\u1369\u136a\u136b\u136c\u136d\u136e\u136f\u1370" +
- "\u1371\u19da\u2070\u2074\u2075\u2076\u2077\u2078\u2079\u2080\u2081" +
- "\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089\u2460\u2461\u2462" +
- "\u2463\u2464\u2465\u2466\u2467\u2468\u2474\u2475\u2476\u2477\u2478" +
- "\u2479\u247a\u247b\u247c\u2488\u2489\u248a\u248b\u248c\u248d\u248e" +
- "\u248f\u2490\u24ea\u24f5\u24f6\u24f7\u24f8\u24f9\u24fa\u24fb\u24fc" +
- "\u24fd\u24ff\u2776\u2777\u2778\u2779\u277a\u277b\u277c\u277d\u277e" +
- "\u2780\u2781\u2782\u2783\u2784\u2785\u2786\u2787\u2788\u278a\u278b" +
- "\u278c\u278d\u278e\u278f\u2790\u2791\u2792";
-
- public static int [] s_numericNonDecimalValues = new int []
- {
- 2, 3, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 4, 5, 6, 7, 8, 9, 0, 1, 2,
- 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
- 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6,
- 7, 8, 9
- };
-
- [Fact]
- public static void DigitsDecimalTest()
- {
- Assert.Equal(s_numericsCodepoints.Length % 10, 0);
- for (int i=0; i < s_numericsCodepoints.Length; i+= 10)
- {
- for (int j=0; j < 10; j++)
- {
- Assert.Equal(j, CharUnicodeInfo.GetDecimalDigitValue(s_numericsCodepoints[i + j]));
- Assert.Equal(j, CharUnicodeInfo.GetDecimalDigitValue(s_numericsCodepoints, i + j));
- }
- }
- }
-
- [Fact]
- public static void NegativeDigitsTest()
- {
- for (int i=0; i < s_nonNumericsCodepoints.Length; i++)
- {
- Assert.Equal(-1, CharUnicodeInfo.GetDecimalDigitValue(s_nonNumericsCodepoints[i]));
- Assert.Equal(-1, CharUnicodeInfo.GetDecimalDigitValue(s_nonNumericsCodepoints, i));
- }
- }
-
- [Fact]
- public static void DigitsTest()
- {
- Assert.Equal(s_numericNonDecimalCodepoints.Length, s_numericNonDecimalValues.Length);
- for (int i=0; i < s_numericNonDecimalCodepoints.Length; i++)
- {
- Assert.Equal(s_numericNonDecimalValues[i], CharUnicodeInfo.GetDigitValue(s_numericNonDecimalCodepoints[i]));
- Assert.Equal(s_numericNonDecimalValues[i], CharUnicodeInfo.GetDigitValue(s_numericNonDecimalCodepoints, i));
- }
- }
- }
-}
+++ /dev/null
-// 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 CultureNotFoundExceptionTests
- {
- [Fact]
- public void Ctor_String()
- {
- string message = "this is a test string";
- CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(message);
-
- Assert.Equal(message, cultureNotFoundException.Message);
- }
-
- [Fact]
- public void Ctor_String_Exception()
- {
- string message = "this is a test string";
- Exception innerException = new Exception("inner exception string");
- CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(message, innerException);
-
- Assert.Equal(message, cultureNotFoundException.Message);
- Assert.Same(innerException, cultureNotFoundException.InnerException);
- }
-
- [Fact]
- public void Ctor_String_String()
- {
- string paramName = "nameOfParam";
- string message = "this is a test string";
- CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(paramName, message);
-
- Assert.Equal(paramName, cultureNotFoundException.ParamName);
- Assert.NotEmpty(cultureNotFoundException.Message);
- }
-
- [Fact]
- public void Ctor_String_String_Exception()
- {
- string message = "this is a test string";
- string invalidCultureName = "abcd";
- Exception innerException = new Exception("inner exception string");
- CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(message, invalidCultureName, innerException);
-
- Assert.NotEmpty(cultureNotFoundException.Message);
- Assert.Equal(invalidCultureName, cultureNotFoundException.InvalidCultureName);
- Assert.Same(innerException, cultureNotFoundException.InnerException);
- }
-
- [Fact]
- public void Ctor_String_String_String()
- {
- string paramName = "nameOfParam";
- string invalidCultureName = "abcd";
- string message = "this is a test string";
- CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(paramName, invalidCultureName, message);
-
- Assert.Equal(paramName, cultureNotFoundException.ParamName);
- Assert.Equal(invalidCultureName, cultureNotFoundException.InvalidCultureName);
- Assert.NotEmpty(cultureNotFoundException.Message);
- }
- }
-}
public class DateTimeFormatInfoAMDesignator
{
[Fact]
- public void AMDesignator_InvariantInfo()
+ public void AMDesignator_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal("AM", DateTimeFormatInfo.InvariantInfo.AMDesignator);
}
- [Fact]
- public void AMDesignator_Set()
+ [Theory]
+ [InlineData("")]
+ [InlineData("AA")]
+ [InlineData("A.M")]
+ public void AMDesignator_Set_GetReturnsExpected(string value)
{
- string newAMDesignator = "AA";
var format = new DateTimeFormatInfo();
- format.AMDesignator = newAMDesignator;
- Assert.Equal(newAMDesignator, format.AMDesignator);
+ format.AMDesignator = value;
+ Assert.Equal(value, format.AMDesignator);
}
[Fact]
- public void AMDesignator_Set_Invalid()
+ public void AMDesignator_SetNullValue_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AMDesignator = null);
+ }
+
+ [Fact]
+ public void AMDesignator_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AMDesignator = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.AMDesignator = "AA"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.AMDesignator = "AA");
}
}
}
// 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 DateTimeFormatInfoAbbreviatedDayNames
{
[Fact]
- public void AbbreviatedDayNames_InvariantInfo()
+ public void AbbreviatedDayNames_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal(new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, DateTimeFormatInfo.InvariantInfo.AbbreviatedDayNames);
}
[Fact]
- public void AbbreviatedDayNames_Set()
+ public void AbbreviatedDayNames_Get_ReturnsClone()
{
- string[] newAbbreviatedDayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" };
var format = new DateTimeFormatInfo();
- format.AbbreviatedDayNames = newAbbreviatedDayNames;
- Assert.Equal(newAbbreviatedDayNames, format.AbbreviatedDayNames);
+ Assert.Equal(format.AbbreviatedDayNames, format.AbbreviatedDayNames);
+ Assert.NotSame(format.AbbreviatedDayNames, format.AbbreviatedDayNames);
+ }
+
+ public static IEnumerable<object[]> AbbreviatedDayNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(AbbreviatedDayNames_Set_TestData))]
+ public void AbbreviatedDayNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.AbbreviatedDayNames = value;
+ Assert.Equal(value, format.AbbreviatedDayNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.AbbreviatedDayNames);
+ Assert.Equal(value, format.AbbreviatedDayNames);
+ }
+
+ [Fact]
+ public void AbbreviatedDayNames_SetNulValue_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AbbreviatedDayNames = null);
}
[Fact]
- public void AbbreviatedDayNames_Set_Invalid()
+ public void AbbreviatedDayNames_SetNulValueInValue_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AbbreviatedDayNames = new string[] { "1", "2", "3", null, "5", "6", "7" });
+ }
+
+ public static IEnumerable<object[]> AbbreviatedDayNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Sun" } };
+ yield return new object[] { new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Additional" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(AbbreviatedDayNames_SetInvalidLength_TestData))]
+ public void AbbreviatedDayNames_SetInvalidLength_ThrowsArgumentException(string[] value)
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedDayNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedDayNames = new string[] { "1", "2", "3", null, "5", "6", "7" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", (() => new DateTimeFormatInfo().AbbreviatedDayNames = new string[] { "sun" })); // Value.Length is not 7
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", (() => format.AbbreviatedDayNames = value));
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ [Fact]
+ public void AbbreviatedDayNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.AbbreviatedDayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" });
}
}
// 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 DateTimeFormatInfoAbbreviatedMonthGenitiveNames
{
[Fact]
- public void AbbreviatedMonthNames_InvariantInfo()
+ public void AbbreviatedMonthGenitiveNames_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal(new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" }, DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthGenitiveNames);
}
[Fact]
- public void AbbreviatedMonthNames_Set()
+ public void AbbreviatedMonthGenitiveNames_Get_ReturnsClone()
{
- string[] newAbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" };
var format = new DateTimeFormatInfo();
- format.AbbreviatedMonthGenitiveNames = newAbbreviatedMonthGenitiveNames;
- Assert.Equal(newAbbreviatedMonthGenitiveNames, format.AbbreviatedMonthGenitiveNames);
+ Assert.Equal(format.AbbreviatedMonthGenitiveNames, format.AbbreviatedMonthGenitiveNames);
+ Assert.NotSame(format.AbbreviatedMonthGenitiveNames, format.AbbreviatedMonthGenitiveNames);
+ }
+
+ public static IEnumerable<object[]> AbbreviatedMonthGenitiveNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(AbbreviatedMonthGenitiveNames_Set_TestData))]
+ public void AbbreviatedMonthGenitiveNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.AbbreviatedMonthGenitiveNames = value;
+ Assert.Equal(value, format.AbbreviatedMonthGenitiveNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.AbbreviatedMonthGenitiveNames);
+ Assert.Equal(value, format.AbbreviatedMonthGenitiveNames);
}
[Fact]
- public void AbbreviatedMonths_Set_Invalid()
+ public void AbbreviatedMonthGenitiveNames_SetNullValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthGenitiveNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthGenitiveNames = new string[] { "Jan" }); // Value.Length is not 13
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AbbreviatedMonthGenitiveNames = null);
+ }
+
+ [Fact]
+ public void AbbreviatedMonthGenitiveNames_SetNullValueInValues_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" });
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ public static IEnumerable<object[]> AbbreviatedMonthGenitiveNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Jan" } };
+ yield return new object[] { new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "", "Additional" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(AbbreviatedMonthGenitiveNames_SetInvalidLength_TestData))]
+ public void AbbreviatedMonthGenitiveNames_SetNullValueInValues_ThrowsArgumentNullException(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", () => format.AbbreviatedMonthGenitiveNames = value);
+ }
+
+ [Fact]
+ public void AbbreviatedMonthGenitiveNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" });
}
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
- public void AbbreviatedMonthNames_Format()
+ public void AbbreviatedMonthGenitiveNames_Format_ReturnsExpected()
{
var format = new DateTimeFormatInfo();
format.AbbreviatedMonthGenitiveNames = new string[] { "GenJan", "GenFeb", "GenMar", "GenApr", "GenMay", "GenJun", "GenJul", "GenAug", "GenSep", "GenOct", "GenNov", "GenDec", "Gen" };
- Assert.Equal("19 GenJun 76", new DateTime(1976, 6, 19).ToString("d MMM yy", format));
+ var dateTime = new DateTime(1976, 6, 19);
+ Assert.Equal("19 GenJun 76", dateTime.ToString("d MMM yy", format));
+ }
+
+ [Fact]
+ public void AbbreviatedMonthGenitiveNames_FormatWithNull_ThrowsNullReferenceException()
+ {
+ var value = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" };
+ var format = new DateTimeFormatInfo
+ {
+ AbbreviatedMonthGenitiveNames = value
+ };
+ value[0] = null;
+
+ var dateTime = new DateTime(2014, 1, 28);
+ Assert.Throws<NullReferenceException>(() => dateTime.ToString("dd MMM yy", format));
}
}
}
// 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 DateTimeFormatInfoAbbreviatedMonthNames
{
[Fact]
- public void AbbreviatedMonthNames_InvariantInfo()
+ public void AbbreviatedMonthNames_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal(new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" }, DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthNames);
}
[Fact]
- public void AbbreviatedMonthNames_Set()
+ public void AbbreviatedMonthNames_Get_ReturnsClone()
{
- string[] newAbbreviatedMonthNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" };
var format = new DateTimeFormatInfo();
- format.AbbreviatedMonthNames = newAbbreviatedMonthNames;
- Assert.Equal(newAbbreviatedMonthNames, format.AbbreviatedMonthNames);
+ Assert.Equal(format.AbbreviatedMonthNames, format.AbbreviatedMonthNames);
+ Assert.NotSame(format.AbbreviatedMonthNames, format.AbbreviatedMonthNames);
+ }
+
+ public static IEnumerable<object[]> AbbreviatedMonthNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(AbbreviatedMonthNames_Set_TestData))]
+ public void AbbreviatedMonthNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.AbbreviatedMonthNames = value;
+ Assert.Equal(value, format.AbbreviatedMonthNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.AbbreviatedMonthNames);
+ Assert.Equal(value, format.AbbreviatedMonthNames);
}
[Fact]
- public void AbbreviatedMonths_Set_Invalid()
+ public void AbbreviatedMonthNames_SetNullValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthNames = new string[] { "Jan" }); // Value.Length is not 13
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AbbreviatedMonthNames = null);
+ }
+
+ [Fact]
+ public void AbbreviatedMonthNames_SetNullValueInValues_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.AbbreviatedMonthNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" });
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ public static IEnumerable<object[]> AbbreviatedMonthNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Jan" } };
+ yield return new object[] { new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "", "Additional" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(AbbreviatedMonthNames_SetInvalidLength_TestData))]
+ public void AbbreviatedMonthNames_SetNullValueInValues_ThrowsArgumentNullException(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", () => format.AbbreviatedMonthNames = value);
+ }
+
+ [Fact]
+ public void AbbreviatedMonthNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" });
}
+
+ [Fact]
+ public void AbbreviatedMonthNames_Format_ReturnsExpected()
+ {
+ var format = new DateTimeFormatInfo();
+ format.AbbreviatedMonthNames = new string[] { "Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.", "." };
+ Assert.Equal("Jun. 76", new DateTime(1976, 6, 19).ToString("MMM yy", format));
+ }
+
+ [Fact]
+ public void AbbreviatedMonthNames_FormatWithNull_ThrowsNullReferenceException()
+ {
+ var value = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" };
+ var format = new DateTimeFormatInfo
+ {
+ AbbreviatedMonthNames = value
+ };
+ value[0] = null;
+
+ var dateTime = new DateTime(2014, 1, 28);
+ Assert.Throws<NullReferenceException>(() => dateTime.ToString("MMM", format));
+ }
}
}
public class DateTimeFormatInfoCalendar
{
[Fact]
- public void Calendar_InvariantInfo()
+ public void Calendar_GetInvariantInfo_ReturnsExpected()
{
Calendar calendar = DateTimeFormatInfo.InvariantInfo.Calendar;
Assert.IsType<GregorianCalendar>(calendar);
}
[Fact]
- public void Calendar_Set()
+ public void Calendar_Set_GetReturnsExpected()
{
Calendar newCalendar = new GregorianCalendar(GregorianCalendarTypes.Localized);
var format = new DateTimeFormatInfo();
}
[Fact]
- public void Calendar_Set_Invalid()
+ public void Calendar_SetNullValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().Calendar = null); // Value is null
- AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => new DateTimeFormatInfo().Calendar = new ThaiBuddhistCalendar()); // Value is invalid
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.Calendar = new GregorianCalendar()); // DateTimeFormatInfo.InvariantInfo is read only
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.Calendar = null);
+ }
+
+ [Fact]
+ public void Calendar_SetInvalidValue_ThrowsArgumentOutOfRangeException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => format.Calendar = new ThaiBuddhistCalendar());
+ }
+
+ [Fact]
+ public void Calendar_SetReadOnly_ThrowsInvalidOperationException()
+ {
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.Calendar = new GregorianCalendar());
}
}
}
{
public class DateTimeFormatInfoCalendarWeekRule
{
- public static IEnumerable<object[]> CalendarWeekRule_TestData()
+ public static IEnumerable<object[]> CalendarWeekRule_Get_TestData()
{
yield return new object[] { DateTimeFormatInfo.InvariantInfo, CalendarWeekRule.FirstDay };
yield return new object[] { new CultureInfo("en-US").DateTimeFormat, CalendarWeekRule.FirstDay };
}
[Theory]
- [MemberData(nameof(CalendarWeekRule_TestData))]
+ [MemberData(nameof(CalendarWeekRule_Get_TestData))]
public void CalendarWeekRuleTest(DateTimeFormatInfo format, CalendarWeekRule expected)
{
Assert.Equal(expected, format.CalendarWeekRule);
[InlineData(CalendarWeekRule.FirstDay)]
[InlineData(CalendarWeekRule.FirstFourDayWeek)]
[InlineData(CalendarWeekRule.FirstFullWeek)]
- public void CalendarWeekRule_Set(CalendarWeekRule newCalendarWeekRule)
+ public void CalendarWeekRule_Set_GetReturnsExpected(CalendarWeekRule value)
{
var format = new DateTimeFormatInfo();
- format.CalendarWeekRule = newCalendarWeekRule;
- Assert.Equal(newCalendarWeekRule, format.CalendarWeekRule);
+ format.CalendarWeekRule = value;
+ Assert.Equal(value, format.CalendarWeekRule);
}
[Theory]
[InlineData(CalendarWeekRule.FirstDay - 1)]
[InlineData(CalendarWeekRule.FirstFourDayWeek + 1)]
- public void CalendarWeekRule_Set_Invalid_ThrowsArgumentOutOfRangeException(CalendarWeekRule value)
+ public void CalendarWeekRule_SetInvalidValue_ThrowsArgumentOutOfRangeException(CalendarWeekRule value)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => new DateTimeFormatInfo().CalendarWeekRule = value);
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => format.CalendarWeekRule = value);
}
[Fact]
- public void CalendarWeekRule_Set_ReadOnly_ThrowsInvalidOperationException()
+ public void CalendarWeekRule_SetReadOnly_ThrowsInvalidOperationException()
{
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.CalendarWeekRule = CalendarWeekRule.FirstDay); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.CalendarWeekRule = CalendarWeekRule.FirstDay);
}
}
}
[Theory]
[MemberData(nameof(Clone_TestData))]
- public void Clone(DateTimeFormatInfo format)
+ public void Clone_Invoke_ReturnsExpected(DateTimeFormatInfo format)
{
DateTimeFormatInfo clone = (DateTimeFormatInfo)format.Clone();
Assert.NotSame(format, clone);
// 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 DateTimeFormatInfoDayNames
{
[Fact]
- public void DayNames_InvariantInfo()
+ public void DayNames_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal(new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }, DateTimeFormatInfo.InvariantInfo.DayNames);
}
[Fact]
- public void DayNames_Set()
+ public void DayNames_Get_ReturnsClone()
{
- string[] newDayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" };
var format = new DateTimeFormatInfo();
- format.DayNames = newDayNames;
- Assert.Equal(newDayNames, format.DayNames);
+ Assert.Equal(format.DayNames, format.DayNames);
+ Assert.NotSame(format.DayNames, format.DayNames);
+ }
+
+ public static IEnumerable<object[]> DayNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(DayNames_Set_TestData))]
+ public void DayNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.DayNames = value;
+ Assert.Equal(value, format.DayNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.DayNames);
+ Assert.Equal(value, format.DayNames);
}
[Fact]
- public void DayNames_Set_Invalid()
+ public void DayNames_SetNulValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().DayNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().DayNames = new string[] { "1", "2", "3", null, "5", "6", "7" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().DayNames = new string[] { "sun" }); // Value.Length is not 7
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.DayNames = null);
+ }
+
+ [Fact]
+ public void DayNames_SetNulValueInValue_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.DayNames = new string[] { "1", "2", "3", null, "5", "6", "7" });
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ public static IEnumerable<object[]> DayNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Sun" } };
+ yield return new object[] { new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Additional" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(DayNames_SetInvalidLength_TestData))]
+ public void DayNames_SetInvalidLength_ThrowsArgumentException(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", (() => format.DayNames = value));
+ }
+
+ [Fact]
+ public void DayNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.DayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" });
}
+
+ [Fact]
+ public void DayNames_FormatWithNull_ThrowsNullReferenceException()
+ {
+ var value = new string[] { "1", "2", "3", "4", "5", "6", "7" };
+ var format = new DateTimeFormatInfo
+ {
+ DayNames = value
+ };
+ value[0] = null;
+
+ var dateTime = new DateTime(2014, 5, 28);
+ Assert.Throws<NullReferenceException>(() => dateTime.ToString("dddd MMM yy", format));
+ }
}
}
{
public class DateTimeFormatInfoFirstDayOfWeek
{
- public static IEnumerable<object[]> FirstDayOfWeek_TestData()
+ public static IEnumerable<object[]> FirstDayOfWeek_Get_TestData()
{
yield return new object[] { DateTimeFormatInfo.InvariantInfo, DayOfWeek.Sunday };
yield return new object[] { new CultureInfo("en-US", false).DateTimeFormat, DayOfWeek.Sunday };
}
[Theory]
- [MemberData(nameof(FirstDayOfWeek_TestData))]
+ [MemberData(nameof(FirstDayOfWeek_Get_TestData))]
public void FirstDayOfWeek(DateTimeFormatInfo format, DayOfWeek expected)
{
Assert.Equal(expected, format.FirstDayOfWeek);
[InlineData(DayOfWeek.Thursday)]
[InlineData(DayOfWeek.Friday)]
[InlineData(DayOfWeek.Saturday)]
- public void FirstDayOfWeek_Set(DayOfWeek newFirstDayOfWeek)
+ public void FirstDayOfWeek_Set_GetReturnsExpected(DayOfWeek value)
{
var format = new DateTimeFormatInfo();
- format.FirstDayOfWeek = newFirstDayOfWeek;
- Assert.Equal(newFirstDayOfWeek, format.FirstDayOfWeek);
+ format.FirstDayOfWeek = value;
+ Assert.Equal(value, format.FirstDayOfWeek);
}
[Theory]
[InlineData(DayOfWeek.Sunday - 1)]
[InlineData(DayOfWeek.Saturday + 1)]
- public void FirstDayOfWeek_Set_Invalid_ThrowsArgumentOutOfRangeException(DayOfWeek value)
+ public void FirstDayOfWeek_SetInvalid_ThrowsArgumentOutOfRangeException(DayOfWeek value)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => new DateTimeFormatInfo().FirstDayOfWeek = value);
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => format.FirstDayOfWeek = value);
}
[Fact]
- public void FirstDayOfWeek_Set_ReadOnly_ThrowsInvalidOperationException()
+ public void FirstDayOfWeek_SetReadOnly_ThrowsInvalidOperationException()
{
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.FirstDayOfWeek = DayOfWeek.Wednesday); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.FirstDayOfWeek = DayOfWeek.Wednesday);
}
}
}
{
public class DateTimeFormatInfoFullDateTimePattern
{
- private static readonly RandomDataGenerator s_generator = new RandomDataGenerator();
-
[Fact]
- public void FullDateTimePattern_InvariantInfo()
+ public void FullDateTimePattern_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal("dddd, dd MMMM yyyy HH:mm:ss", DateTimeFormatInfo.InvariantInfo.FullDateTimePattern);
}
- public static IEnumerable<object[]> FullDFullDateTimePattern_Set_TestData()
+ public static IEnumerable<object[]> FullDateTimePattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "dddd, dd MMMM yyyy HH:mm:ss" };
yield return new object[] { "dddd" };
yield return new object[] { "F" };
yield return new object[] { "HH:mm:ss dddd, dd MMMM yyyy" };
- yield return new object[] { s_generator.GetString(-55, false, 1, 256) };
}
[Theory]
- [MemberData(nameof(FullDFullDateTimePattern_Set_TestData))]
- public void FullDateTimePattern_Set(string newFullDateTimePattern)
+ [MemberData(nameof(FullDateTimePattern_Set_TestData))]
+ public void FullDateTimePattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.FullDateTimePattern = value;
+ Assert.Equal(value, format.FullDateTimePattern);
+ }
+
+ [Fact]
+ public void FullDateTimePattern_SetNullValue_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.FullDateTimePattern = newFullDateTimePattern;
- Assert.Equal(newFullDateTimePattern, format.FullDateTimePattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.FullDateTimePattern = null);
}
[Fact]
- public void FullDateTimePattern_Set_Invalid()
+ public void FullDateTimePattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().FullDateTimePattern = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.FullDateTimePattern = "dddd, dd MMMM yyyy HH:mm:ss"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.FullDateTimePattern = "dddd, dd MMMM yyyy HH:mm:ss");
}
}
}
[Theory]
[MemberData(nameof(GetAbbreviatedDayName_TestData))]
- public void GetAbbreviatedDayName(DateTimeFormatInfo info, string[] expected)
+ public void GetAbbreviatedDayName_Invoke_ReturnsExpected(DateTimeFormatInfo info, string[] expected)
{
DayOfWeek[] values = new DayOfWeek[]
{
[InlineData(DayOfWeek.Saturday + 1)]
public void GetAbbreviatedDayName_Invalid_ThrowsArgumentOutOfRangeException(DayOfWeek dayofweek)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("dayofweek", () => new DateTimeFormatInfo().GetAbbreviatedDayName(dayofweek));
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("dayofweek", () => format.GetAbbreviatedDayName(dayofweek));
}
}
}
[Theory]
[MemberData(nameof(GetAbbreviatedEraName_TestData))]
- public void GetAbbreviatedEraName(DateTimeFormatInfo format, int era, string expected)
+ public void GetAbbreviatedEraName_Invoke_ReturnsExpected(DateTimeFormatInfo format, int era, string expected)
{
Assert.Equal(expected, format.GetAbbreviatedEraName(era));
}
- [Fact]
- public void GetAbbreviatedEraName_Invalid()
+ [Theory]
+ [InlineData(-1)]
+ [InlineData(2)]
+ public void GetAbbreviatedEraName_Invalid(int era)
{
var format = new CultureInfo("en-US").DateTimeFormat;
- AssertExtensions.Throws<ArgumentOutOfRangeException>("era", () => format.GetAbbreviatedEraName(-1)); // Era < 0
-
- const int EnUSMaxEra = 1;
- AssertExtensions.Throws<ArgumentOutOfRangeException>("era", () => format.GetAbbreviatedEraName(EnUSMaxEra + 1)); // Era > max era for the culture
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("era", () => format.GetAbbreviatedEraName(era));
}
}
}
[Theory]
[MemberData(nameof(GetAbbreviatedMonthName_TestData))]
- public void GetAbbreviatedMonthName(DateTimeFormatInfo info, string[] expected)
+ public void GetAbbreviatedMonthName_Invoke_ReturnsExpected(DateTimeFormatInfo info, string[] expected)
{
for (int i = MinMonth; i <= MaxMonth; ++i)
{
}
}
- [Fact]
- public void GetAbbreviatedMonthName_Invalid()
+ [Theory]
+ [InlineData(MinMonth - 1)]
+ [InlineData(MaxMonth + 1)]
+ public void GetAbbreviatedMonthName_InvalidMonth_ThrowsArgumentOutOfRangeException(int month)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("month", () => new DateTimeFormatInfo().GetAbbreviatedMonthName(MinMonth - 1)); // Month is invalid
- AssertExtensions.Throws<ArgumentOutOfRangeException>("month", (() => new DateTimeFormatInfo().GetAbbreviatedMonthName(MaxMonth + 1))); // Month is invalid
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("month", () => format.GetAbbreviatedMonthName(month));
}
}
}
[Theory]
[MemberData(nameof(GetDayName_TestData))]
- public void GetDayName(DateTimeFormatInfo format, string[] expected)
+ public void GetDayName_Invoke_ReturnsExpected(DateTimeFormatInfo format, string[] expected)
{
DayOfWeek[] values = new DayOfWeek[]
{
[Theory]
[InlineData(DayOfWeek.Sunday - 1)]
[InlineData(DayOfWeek.Saturday + 1)]
- public void GetDayName_Invalid_ThrowsArgumentOutOfRangeException(DayOfWeek dayofweek)
+ public void GetDayName_InvalidDayOfWeek_ThrowsArgumentOutOfRangeException(DayOfWeek dayofweek)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("dayofweek", () => new DateTimeFormatInfo().GetDayName(dayofweek));
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("dayofweek", () => format.GetDayName(dayofweek));
}
}
}
[Theory]
[MemberData(nameof(GetEra_TestData))]
- public void GetEra(DateTimeFormatInfo format, string eraName, int expected)
+ public void GetEra_Invoke_RetrunsExpected(DateTimeFormatInfo format, string eraName, int expected)
{
Assert.Equal(expected, format.GetEra(eraName));
}
[Fact]
- public void GetEra_Null_ThrowsArgumentNullException()
+ public void GetEra_NullEraName_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("eraName", () => new DateTimeFormatInfo().GetEra(null)); // Era name is null
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("eraName", () => format.GetEra(null));
}
}
}
[Theory]
[MemberData(nameof(GetEraName_TestData))]
- public void GetEraName(DateTimeFormatInfo format, int era, string expected)
+ public void GetEraName_Invoke_ReturnsExpected(DateTimeFormatInfo format, int era, string expected)
{
Assert.Equal(expected, format.GetEraName(era));
}
- [Fact]
- public void GetEraName_Invalid()
+ [Theory]
+ [InlineData(-1)]
+ [InlineData(2)]
+ public void GetEraName_InvalidEra_ThrowsArgumentOutOfRangeException(int era)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("era", () => new DateTimeFormatInfo().GetEraName(-1)); // Era < 0
-
- const int EnUSMaxEra = 1;
- AssertExtensions.Throws<ArgumentOutOfRangeException>("era", () => new CultureInfo("en-US").DateTimeFormat.GetAbbreviatedEraName(EnUSMaxEra + 1)); // Era > max era for the culture
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("era", () => format.GetEraName(era));
}
}
}
public class DateTimeFormatInfoGetFormat
{
[Fact]
- public void GetFormat()
+ public void GetFormat_Invoke_ReturnsExpected()
{
DateTimeFormatInfo expected = new DateTimeFormatInfo();
DateTimeFormatInfo format = (DateTimeFormatInfo)expected.GetFormat(typeof(DateTimeFormatInfo));
[Theory]
[MemberData(nameof(GetInstance_NotNull_TestData))]
- public void GetInstance_NotNull(IFormatProvider provider)
+ public void GetInstance_ValidNonNullProvider_ReturnsExpected(IFormatProvider provider)
{
Assert.NotNull(DateTimeFormatInfo.GetInstance(provider));
}
}
[Fact]
- public void GetInstance_ExpectedCurrent()
+ public void GetInstance_ExpectedCurrent_ReturnsExpected()
{
AssertSameValues(DateTimeFormatInfo.CurrentInfo, DateTimeFormatInfo.GetInstance(null));
AssertSameValues(DateTimeFormatInfo.CurrentInfo, DateTimeFormatInfo.GetInstance(new TestIFormatProviderClass()));
[Theory]
[MemberData(nameof(GetMonthName_TestData))]
- public void GetMonthName(DateTimeFormatInfo format, string[] expected)
+ public void GetMonthName_Invoke_ReturnsExpected(DateTimeFormatInfo format, string[] expected)
{
for (int i = MinMonth; i <= MaxMonth; ++i)
{
}
}
- [Fact]
- public void GetMonthName_Invalid()
+ [Theory]
+ [InlineData(MinMonth - 1)]
+ [InlineData(MaxMonth + 1)]
+ public void GetMonthName_InvalidMonth_ThrowsArgumentOutOfRangeException(int month)
{
- AssertExtensions.Throws<ArgumentOutOfRangeException>("month", () => new DateTimeFormatInfo().GetMonthName(MinMonth - 1));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("month", () => new DateTimeFormatInfo().GetMonthName(MaxMonth + 1));
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("month", () => format.GetMonthName(month));
}
}
}
{
public class DateTimeFormatInfoLongDatePattern
{
- private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
- public void LongDatePattern_InvariantInfo()
+ [Fact]
+ public void LongDatePattern_InvariantInfo_ReturnsExpected()
{
Assert.Equal("dddd, dd MMMM yyyy", DateTimeFormatInfo.InvariantInfo.LongDatePattern);
}
- public static IEnumerable<object[]> LongDatePattern_TestData()
+ public static IEnumerable<object[]> LongDatePattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "dddd, dd MMMM yyyy HH:mm:ss" };
yield return new object[] { "dddd" };
yield return new object[] { "D" };
yield return new object[] { "HH:mm:ss dddd, dd MMMM yyyy" };
- yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
yield return new object[] { "dddd, dd MMMM yyyy" };
}
[Theory]
- [MemberData(nameof(LongDatePattern_TestData))]
- public void LongDatePattern_Set(string newLongDatePattern)
+ [MemberData(nameof(LongDatePattern_Set_TestData))]
+ public void LongDatePattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.LongDatePattern = value;
+ Assert.Equal(value, format.LongDatePattern);
+ }
+
+ [Fact]
+ public void LongDatePattern_SetNullValue_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.LongDatePattern = newLongDatePattern;
- Assert.Equal(newLongDatePattern, format.LongDatePattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.LongDatePattern = null);
}
[Fact]
- public void LongDatePattern_Set_Invalid()
+ public void LongDatePattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().LongDatePattern = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.LongDatePattern = "dddd, dd MMMM yyyy"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.LongDatePattern = "dddd, dd MMMM yyyy");
}
}
}
{
public class DateTimeFormatInfoLongTimePattern
{
- private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
-
- public void LongTimePattern_InvariantInfo()
+ public void LongTimePattern_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal("HH:mm:ss", DateTimeFormatInfo.InvariantInfo.LongTimePattern);
}
- public static IEnumerable<object[]> LongTimePattern_TestData()
+ public static IEnumerable<object[]> LongTimePattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "dddd, dd MMMM yyyy HH:mm:ss" };
yield return new object[] { "HH" };
yield return new object[] { "T" };
yield return new object[] { "HH:mm:ss dddd, dd MMMM yyyy" };
- yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
yield return new object[] { "HH:mm:ss" };
}
[Theory]
- [MemberData(nameof(LongTimePattern_TestData))]
- public void LongTimePattern_Set(string newLongTimePattern)
+ [MemberData(nameof(LongTimePattern_Set_TestData))]
+ public void LongTimePattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.LongTimePattern = value;
+ Assert.Equal(value, format.LongTimePattern);
+ }
+
+ [Fact]
+ public void LongTimePattern_SetNullValue_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.LongTimePattern = newLongTimePattern;
- Assert.Equal(newLongTimePattern, format.LongTimePattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.LongTimePattern = null);
}
[Fact]
- public void LongTimePattern_Set_Invalid()
+ public void LongTimePattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().LongTimePattern = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.LongTimePattern = "HH:mm:ss"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.LongTimePattern = "HH:mm:ss");
}
}
}
{
public class DateTimeFormatInfoMonthDayPattern
{
- private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
-
- public void LongDayPattern_InvariantInfo()
+ public void LongDayPattern_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal("MMMM dd", DateTimeFormatInfo.InvariantInfo.MonthDayPattern);
}
- public static IEnumerable<object[]> MonthDayPattern_TestData()
+ public static IEnumerable<object[]> MonthDayPattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "MMMM" };
yield return new object[] { "MMM dd" };
yield return new object[] { "M" };
yield return new object[] { "dd MMMM" };
- yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
yield return new object[] { "MMMM dd" };
yield return new object[] { "m" };
}
[Theory]
- [MemberData(nameof(MonthDayPattern_TestData))]
- public void MonthDayPattern_Set(string newMonthDayPattern)
+ [MemberData(nameof(MonthDayPattern_Set_TestData))]
+ public void MonthDayPattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.MonthDayPattern = value;
+ Assert.Equal(value, format.MonthDayPattern);
+ }
+
+ [Fact]
+ public void MonthDayPattern_SetNull_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.MonthDayPattern = newMonthDayPattern;
- Assert.Equal(newMonthDayPattern, format.MonthDayPattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.MonthDayPattern = null);
}
[Fact]
- public void MonthDayPattern_Set_Invalid()
+ public void MonthDayPattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().MonthDayPattern = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.MonthDayPattern = "MMMM dd"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.MonthDayPattern = "MMMM dd");
}
}
}
{
public class DateTimeFormatInfoMonthGenitiveNames
{
- public static IEnumerable<object[]> MonthGenitiveNames_TestData()
+ public static IEnumerable<object[]> MonthGenitiveNames_Get_TestData()
{
yield return new object[] { DateTimeFormatInfo.InvariantInfo, new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "" } };
yield return new object[]
}
[Theory]
- [MemberData(nameof(MonthGenitiveNames_TestData))]
- public void MonthGenitiveNames(DateTimeFormatInfo format, string[] expected)
+ [MemberData(nameof(MonthGenitiveNames_Get_TestData))]
+ public void MonthGenitiveNames_Get_ReturnsExpected(DateTimeFormatInfo format, string[] expected)
{
Assert.Equal(expected, format.MonthGenitiveNames);
}
[Fact]
- public void MonthGenitiveNames_Set()
+ public void MonthGenitiveNames_Get_ReturnsClone()
{
- string[] newMonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" };
var format = new DateTimeFormatInfo();
- format.MonthGenitiveNames = newMonthGenitiveNames;
- Assert.Equal(newMonthGenitiveNames, format.MonthGenitiveNames);
+ Assert.Equal(format.MonthGenitiveNames, format.MonthGenitiveNames);
+ Assert.NotSame(format.MonthGenitiveNames, format.MonthGenitiveNames);
+ }
+
+ public static IEnumerable<object[]> MonthGenitiveNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(MonthGenitiveNames_Set_TestData))]
+ public void MonthGenitiveNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.MonthGenitiveNames = value;
+ Assert.Equal(value, format.MonthGenitiveNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.MonthGenitiveNames);
+ Assert.Equal(value, format.MonthGenitiveNames);
}
[Fact]
- public void MonthGenitiveNames_Set_Invalid()
+ public void MonthGenitiveNames_SetNullValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().MonthGenitiveNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().MonthGenitiveNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().MonthGenitiveNames = new string[] { "Jan" }); // Value.Length is not 13
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.MonthGenitiveNames = null);
+ }
+
+ [Fact]
+ public void MonthGenitiveNames_SetNullValueInValues_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.MonthGenitiveNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" });
+ }
+
+ public static IEnumerable<object[]> MonthGenitiveNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Jan" } };
+ yield return new object[] { new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "", "Additional" } };
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ [Theory]
+ [MemberData(nameof(MonthGenitiveNames_SetInvalidLength_TestData))]
+ public void MonthGenitiveNames_SetNullValueInValues_ThrowsArgumentNullException(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", () => format.MonthGenitiveNames = value);
+ }
+
+ [Fact]
+ public void MonthGenitiveNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.MonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" });
}
+
+ [Fact]
+ public void MonthGenitiveNames_Format_ReturnsExpected()
+ {
+ var format = new DateTimeFormatInfo();
+ format.MonthGenitiveNames = new string[] { "Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.", "." };
+ Assert.Equal("19 Jun. 76", new DateTime(1976, 6, 19).ToString("dd MMMM yy", format));
+ }
+
+ [Fact]
+ public void MonthGenitiveNames_FormatWithNull_ThrowsNullReferenceException()
+ {
+ var value = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" };
+ var format = new DateTimeFormatInfo
+ {
+ MonthGenitiveNames = value
+ };
+ value[0] = null;
+
+ var dateTime = new DateTime(2014, 1, 28);
+ Assert.Throws<NullReferenceException>(() => dateTime.ToString("dd MMMM", format));
+ }
}
}
// 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 DateTimeFormatInfoMonthNames
{
[Fact]
- public void MonthGenitiveNames_InvariantInfo()
+ public void MonthNames_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal(new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "" }, DateTimeFormatInfo.InvariantInfo.MonthNames);
}
[Fact]
- public void MonthNames_Set()
+ public void MonthNames_Get_ReturnsClone()
{
- string[] newMonthNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" };
var format = new DateTimeFormatInfo();
- format.MonthNames = newMonthNames;
- Assert.Equal(newMonthNames, format.MonthNames);
+ Assert.Equal(format.MonthNames, format.MonthNames);
+ Assert.NotSame(format.MonthNames, format.MonthNames);
+ }
+
+ public static IEnumerable<object[]> MonthNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(MonthNames_Set_TestData))]
+ public void MonthNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.MonthNames = value;
+ Assert.Equal(value, format.MonthNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.MonthNames);
+ Assert.Equal(value, format.MonthNames);
}
[Fact]
- public void MonthNames_Set_Invalid()
+ public void MonthNames_SetNullValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().MonthNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().MonthNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().MonthNames = new string[] { "Jan" }); // Value.Length is not 13
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.MonthNames = null);
+ }
+
+ [Fact]
+ public void MonthNames_SetNullValueInValues_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.MonthNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" });
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ public static IEnumerable<object[]> MonthNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Jan" } };
+ yield return new object[] { new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "", "Additional" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(MonthNames_SetInvalidLength_TestData))]
+ public void MonthNames_SetNullValueInValues_ThrowsArgumentNullException(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", () => format.MonthNames = value);
+ }
+
+ [Fact]
+ public void MonthNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.MonthNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" });
}
+
+ [Fact]
+ public void MonthNames_Format_ReturnsExpected()
+ {
+ var format = new DateTimeFormatInfo();
+ format.MonthNames = new string[] { "Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.", "." };
+ Assert.Equal("Jun. 76", new DateTime(1976, 6, 19).ToString("MMMM yy", format));
+ }
+
+ [Fact]
+ public void MonthNames_FormatWithNull_ThrowsNullReferenceException()
+ {
+ var value = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" };
+ var format = new DateTimeFormatInfo
+ {
+ MonthNames = value
+ };
+ value[0] = null;
+
+ var dateTime = new DateTime(2014, 1, 28);
+ Assert.Throws<NullReferenceException>(() => dateTime.ToString("MMMM", format));
+ }
}
}
public class DateTimeFormatInfoPMDesignator
{
[Fact]
- public void PMDesignator_InvariantInfo()
+ public void PMDesignator_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal("PM", DateTimeFormatInfo.InvariantInfo.PMDesignator);
}
[Theory]
- [InlineData("AA")]
- [InlineData("P.M.")]
- public void PMDesignator_Set(string newPMDesignator)
+ [InlineData("")]
+ [InlineData("PP")]
+ [InlineData("P.M")]
+ public void PMDesignator_Set_GetReturnsExpected(string value)
{
var format = new DateTimeFormatInfo();
- format.PMDesignator = newPMDesignator;
- Assert.Equal(newPMDesignator, format.PMDesignator);
+ format.PMDesignator = value;
+ Assert.Equal(value, format.PMDesignator);
}
[Fact]
- public void PMDesignator_Set_Invalid()
+ public void PMDesignator_SetNullValue_ThrowsArgumentNullException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().PMDesignator = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.PMDesignator = "AA"); // DateTimeFormatInfo.InvariantInfo is read only
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.PMDesignator = null);
+ }
+
+ [Fact]
+ public void PMDesignator_SetReadOnly_ThrowsInvalidOperationException()
+ {
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.PMDesignator = "PP");
}
}
}
[Theory]
[MemberData(nameof(RFC1123Pattern_TestData))]
- public void RFC1123Pattern(DateTimeFormatInfo format, string expected)
+ public void RFC1123Pattern_Get_ReturnsExpected(DateTimeFormatInfo format, string expected)
{
Assert.Equal(expected, format.RFC1123Pattern);
}
[Theory]
[MemberData(nameof(ReadOnly_TestData))]
- public void ReadOnly(DateTimeFormatInfo format, bool originalFormatIsReadOnly)
+ public void ReadOnly_Invoke_ReturnsExpected(DateTimeFormatInfo format, bool originalFormatIsReadOnly)
{
Assert.Equal(originalFormatIsReadOnly, format.IsReadOnly);
}
[Fact]
- public void ReadOnly_Null_ThrowsArgumentNullException()
+ public void ReadOnly_NullDtfi_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("dtfi", () => DateTimeFormatInfo.ReadOnly(null)); // Dtfi is null
}
{
public class DateTimeFormatInfoShortDatePattern
{
- private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
-
public void ShortDatePattern_InvariantInfo()
{
Assert.Equal("MM/dd/yyyy", DateTimeFormatInfo.InvariantInfo.ShortDatePattern);
}
- public static IEnumerable<object[]> ShortDatePattern_TestData()
+ public static IEnumerable<object[]> ShortDatePattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "MM/dd/yyyy" };
yield return new object[] { "MM-DD-yyyy" };
yield return new object[] { "d" };
- yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
}
[Theory]
- [MemberData(nameof(ShortDatePattern_TestData))]
- public void ShortDatePattern_Set(string newShortDatePattern)
+ [MemberData(nameof(ShortDatePattern_Set_TestData))]
+ public void ShortDatePattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.ShortDatePattern = value;
+ Assert.Equal(value, format.ShortDatePattern);
+ }
+
+ [Fact]
+ public void ShortDatePattern_SetNullValue_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.ShortDatePattern = newShortDatePattern;
- Assert.Equal(newShortDatePattern, format.ShortDatePattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.ShortDatePattern = null);
}
[Fact]
- public void ShortDatePattern_Set_Invalid()
+ public void ShortDatePattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().ShortDatePattern = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.ShortDatePattern = "MM/dd/yyyy"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.ShortDatePattern = "MM/dd/yyyy");
}
}
}
{
public class DateTimeFormatInfoShortTimePattern
{
- private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
-
- public void ShortTimePattern_InvariantInfo()
+ public void ShortTimePattern_GetInvariantInfo_ReturnsExpected()
{
Assert.Equal("HH:mm", DateTimeFormatInfo.InvariantInfo.ShortTimePattern);
}
- public static IEnumerable<object[]> ShortTimePattern_TestData()
+ public static IEnumerable<object[]> ShortTimePattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "dddd, dd MMMM yyyy HH:mm:ss" };
yield return new object[] { "HH:mm" };
yield return new object[] { "t" };
- yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
}
[Theory]
- [MemberData(nameof(ShortTimePattern_TestData))]
- public void ShortTimePattern_Set(string newShortTimePattern)
+ [MemberData(nameof(ShortTimePattern_Set_TestData))]
+ public void ShortTimePattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.ShortTimePattern = value;
+ Assert.Equal(value, format.ShortTimePattern);
+ }
+
+ [Fact]
+ public void ShortTimePattern_SetNull_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.ShortTimePattern = newShortTimePattern;
- Assert.Equal(newShortTimePattern, format.ShortTimePattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.ShortTimePattern = null);
}
[Fact]
- public void ShortTimePattern_Set_Invalid()
+ public void ShortTimePattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().ShortTimePattern = null); // Value is null
- Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.ShortTimePattern = "HH:mm"); // DateTimeFormatInfo.InvariantInfo is read only
+ Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.ShortTimePattern = "HH:mm");
}
}
}
// 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
}
[Fact]
- public void ShortestDayNames_Set()
+ public void ShortestDayNames_Get_ReturnsClone()
{
- string[] newShortestDayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" };
var format = new DateTimeFormatInfo();
- format.ShortestDayNames = newShortestDayNames;
- Assert.Equal(newShortestDayNames, format.ShortestDayNames);
+ Assert.Equal(format.ShortestDayNames, format.ShortestDayNames);
+ Assert.NotSame(format.ShortestDayNames, format.ShortestDayNames);
+ }
+
+ public static IEnumerable<object[]> ShortestDayNames_Set_TestData()
+ {
+ yield return new object[] { new string[] { "1", "2", "3", "4", "5", "6", "7" } };
+ yield return new object[] { new string[] { "", "", "", "", "", "", "" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(ShortestDayNames_Set_TestData))]
+ public void ShortestDayNames_Set_GetReturnsExpected(string[] value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.ShortestDayNames = value;
+ Assert.Equal(value, format.ShortestDayNames);
+
+ // Does not clone in setter, only in getter.
+ value[0] = null;
+ Assert.NotSame(value, format.ShortestDayNames);
+ Assert.Equal(value, format.ShortestDayNames);
+ }
+
+ [Fact]
+ public void ShortestDayNames_SetNulValue_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.ShortestDayNames = null);
}
[Fact]
- public void ShortestDayNames_Set_Invalid()
+ public void ShortestDayNames_SetNulValueInValue_ThrowsArgumentNullException()
+ {
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.ShortestDayNames = new string[] { "1", "2", "3", null, "5", "6", "7" });
+ }
+
+ public static IEnumerable<object[]> ShortestDayNames_SetInvalidLength_TestData()
+ {
+ yield return new object[] { new string[] { "Sun" } };
+ yield return new object[] { new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Additional" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(ShortestDayNames_SetInvalidLength_TestData))]
+ public void ShortestDayNames_SetInvalidLength_ThrowsArgumentException(string[] value)
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().ShortestDayNames = null); // Value is null
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().ShortestDayNames = new string[] { "1", "2", "3", null, "5", "6", "7" }); // Value has null
- AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().ShortestDayNames = new string[] { "su" }); // Value.Length is not 7
+ var format = new DateTimeFormatInfo();
+ AssertExtensions.Throws<ArgumentException>("value", (() => format.ShortestDayNames = value));
+ }
- // DateTimeFormatInfo.InvariantInfo is read only
+ [Fact]
+ public void ShortestDayNames_SetReadOnly_ThrowsInvalidOperationException()
+ {
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.ShortestDayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" });
}
}
[Theory]
[MemberData(nameof(SortableDateTimePattern_TestData))]
- public void SortableDateTimePattern(DateTimeFormatInfo format)
+ public void SortableDateTimePattern_Get_ReturnsExpected(DateTimeFormatInfo format)
{
Assert.Equal("yyyy'-'MM'-'dd'T'HH':'mm':'ss", format.SortableDateTimePattern);
}
{
public static IEnumerable<object[]> DateTimeFormatInfo_TestData()
{
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("en-US").DateTimeFormat.Clone(), new GregorianCalendar(), "Gregorian Calendar" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("ar-SA").DateTimeFormat.Clone(), new HijriCalendar(), "\u0627\u0644\u062a\u0642\u0648\u064a\u0645\u00a0\u0627\u0644\u0647\u062c\u0631\u064a" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("ar-SA").DateTimeFormat.Clone(), new UmAlQuraCalendar(), "\u062a\u0642\u0648\u064a\u0645\u0020\u0627\u0645\u0020\u0627\u0644\u0642\u0631\u0649" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("ja-JP").DateTimeFormat.Clone(), new JapaneseCalendar(), "\u548c\u66a6" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("th-TH").DateTimeFormat.Clone(), new ThaiBuddhistCalendar(), "\u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("he-IL").DateTimeFormat.Clone(), new HebrewCalendar(), "\u05dc\u05d5\u05d7\u00a0\u05e9\u05e0\u05d4\u00a0\u05e2\u05d1\u05e8\u05d9" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("ko-KR").DateTimeFormat.Clone(), new KoreanCalendar(), "\ub2e8\uae30" };
- yield return new object[] { (DateTimeFormatInfo) new CultureInfo("fa-IR").DateTimeFormat.Clone(), new PersianCalendar(), "\u062a\u0642\u0648\u06cc\u0645\u0020\u0647\u062c\u0631\u06cc\u0020\u0634\u0645\u0633\u06cc" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("en-US").DateTimeFormat.Clone(), new GregorianCalendar(), "Gregorian Calendar" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("ar-SA").DateTimeFormat.Clone(), new HijriCalendar(), "\u0627\u0644\u062a\u0642\u0648\u064a\u0645\u00a0\u0627\u0644\u0647\u062c\u0631\u064a" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("ar-SA").DateTimeFormat.Clone(), new UmAlQuraCalendar(), "\u062a\u0642\u0648\u064a\u0645\u0020\u0627\u0645\u0020\u0627\u0644\u0642\u0631\u0649" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("ja-JP").DateTimeFormat.Clone(), new JapaneseCalendar(), "\u548c\u66a6" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("th-TH").DateTimeFormat.Clone(), new ThaiBuddhistCalendar(), "\u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("he-IL").DateTimeFormat.Clone(), new HebrewCalendar(), "\u05dc\u05d5\u05d7\u00a0\u05e9\u05e0\u05d4\u00a0\u05e2\u05d1\u05e8\u05d9" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("ko-KR").DateTimeFormat.Clone(), new KoreanCalendar(), "\ub2e8\uae30" };
+ yield return new object[] { (DateTimeFormatInfo)new CultureInfo("fa-IR").DateTimeFormat.Clone(), new PersianCalendar(), "\u062a\u0642\u0648\u06cc\u0645\u0020\u0647\u062c\u0631\u06cc\u0020\u0634\u0645\u0633\u06cc" };
}
public static IEnumerable<object[]> CultureNames_TestData()
}
[Fact]
- public void SeparatorsTest()
+ public void DateSeparatorTimeSeparator_Get_ReturnsExpected()
{
DateTimeFormatInfo dtfi = (DateTimeFormatInfo) CultureInfo.InvariantCulture.DateTimeFormat.Clone();
Assert.False(dtfi.IsReadOnly, "IsReadOnly expected to be false");
[Theory]
[MemberData(nameof(DateTimeFormatInfo_TestData))]
- public void NativeCalendarNameTest(DateTimeFormatInfo dtfi, Calendar calendar, string nativeCalendarName)
+ public void NativeCalendarName_Get_ReturnsExpected(DateTimeFormatInfo dtfi, Calendar calendar, string nativeCalendarName)
{
try
{
[Theory]
[MemberData(nameof(CultureNames_TestData))]
- public void AllDateTimePatternsTest(string cultureName)
+ public void GetAllDateTimePatterns_Invoke_ReturnsExpected(string cultureName)
{
char[] formats = { 'd', 'D', 'f', 'F', 'g', 'G', 'm', 'o', 'r', 's', 't', 'T', 'u', 'U', 'y' };
- DateTimeFormatInfo dtfi = (DateTimeFormatInfo) new CultureInfo(cultureName).DateTimeFormat.Clone();
+ DateTimeFormatInfo dtfi = (DateTimeFormatInfo)new CultureInfo(cultureName).DateTimeFormat.Clone();
var allPatterns = dtfi.GetAllDateTimePatterns();
Dictionary<string, string> dic = new Dictionary<string, string>();
[Theory]
[MemberData(nameof(CultureNames_TestData))]
- public void ShortestDayNamesTest(string cultureName)
+ public void GetShortestDayName_Invoke_ReturnsExpected(string cultureName)
{
DateTimeFormatInfo dtfi = new CultureInfo(cultureName).DateTimeFormat;
string [] shortestDayNames = dtfi.ShortestDayNames;
- for (DayOfWeek day=DayOfWeek.Sunday; day <= DayOfWeek.Saturday; day++)
+ for (DayOfWeek day = DayOfWeek.Sunday; day <= DayOfWeek.Saturday; day++)
{
Assert.Equal(shortestDayNames[(int) day], dtfi.GetShortestDayName(day));
}
}
[Fact]
- public void TestHebrewMonths()
+ public void Months_GetHebrew_ReturnsExpected()
{
CultureInfo ci = new CultureInfo("he-IL");
ci.DateTimeFormat.Calendar = new HebrewCalendar();
Assert.True(formattedDate.IndexOf("\u5143" /* å…ƒ */, StringComparison.Ordinal) >= 0 ==
DateTime.TryParseExact(formattedDateWithGannen, pattern, jpnFormat, DateTimeStyles.None, out parsedDate),
$"Parsing '{formattedDateWithGannen}' result should match if '{formattedDate}' has Gan-nen symbol"
- );
+ );
}
}
}
[Theory]
[MemberData(nameof(UniversalSortableDateTimePattern_TestData))]
- public void UniversalSortableDateTimePattern(DateTimeFormatInfo format)
+ public void UniversalSortableDateTimePattern_Get_ReturnsExpected(DateTimeFormatInfo format)
{
Assert.Equal("yyyy'-'MM'-'dd HH':'mm':'ss'Z'", format.UniversalSortableDateTimePattern);
}
{
public class DateTimeFormatInfoYearMonthPattern
{
- private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
-
- public static IEnumerable<object[]> YearMonthPattern_TestData()
+ public static IEnumerable<object[]> YearMonthPattern_Get_TestData()
{
yield return new object[] { DateTimeFormatInfo.InvariantInfo, "yyyy MMMM" };
yield return new object[] { new CultureInfo("fr-FR").DateTimeFormat, "MMMM yyyy" };
}
[Theory]
- [MemberData(nameof(YearMonthPattern_TestData))]
+ [MemberData(nameof(YearMonthPattern_Get_TestData))]
public void YearMonthPattern(DateTimeFormatInfo format, string expected)
{
Assert.Equal(expected, format.YearMonthPattern);
public static IEnumerable<object[]> YearMonthPattern_Set_TestData()
{
+ yield return new object[] { string.Empty };
+ yield return new object[] { "garbage" };
yield return new object[] { "yyyy MMMM" };
yield return new object[] { "y" };
yield return new object[] { "Y" };
- yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
}
[Theory]
[MemberData(nameof(YearMonthPattern_Set_TestData))]
- public void YearMonthPattern_Set(string newYearMonthPattern)
+ public void YearMonthPattern_Set_GetReturnsExpected(string value)
+ {
+ var format = new DateTimeFormatInfo();
+ format.YearMonthPattern = value;
+ Assert.Equal(value, format.YearMonthPattern);
+ }
+
+ [Fact]
+ public void YearMonthPattern_SetNull_ThrowsArgumentNullException()
{
var format = new DateTimeFormatInfo();
- format.YearMonthPattern = newYearMonthPattern;
- Assert.Equal(newYearMonthPattern, format.YearMonthPattern);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => format.YearMonthPattern = null);
}
[Fact]
- public void YearMonthPattern_Set_Invalid()
+ public void YearMonthPattern_SetReadOnly_ThrowsInvalidOperationException()
{
- AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().YearMonthPattern = null); // Value is null
Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.YearMonthPattern = "yyyy MMMM"); // DateTimeFormatInfo.InvariantInfo is read only
}
}
+++ /dev/null
-// 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 DateTimeStylesTests
- {
- [Theory]
- [InlineData(DateTimeStyles.AllowInnerWhite, 0x00000004)]
- [InlineData(DateTimeStyles.AssumeLocal, 0x00000020)]
- [InlineData(DateTimeStyles.AllowWhiteSpaces, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite | DateTimeStyles.AllowInnerWhite)]
- [InlineData(DateTimeStyles.AllowTrailingWhite, 0x00000002)]
- [InlineData(DateTimeStyles.AdjustToUniversal, 0x00000010)]
- [InlineData(DateTimeStyles.AllowLeadingWhite, 0x00000001)]
- [InlineData(DateTimeStyles.None, 0x00000000)]
- [InlineData(DateTimeStyles.AssumeUniversal, 0x00000040)]
- [InlineData(DateTimeStyles.NoCurrentDateDefault, 0x00000008)]
- [InlineData(DateTimeStyles.RoundtripKind, 0x00000080)]
- public void EnumNames_MatchExpectedValues(DateTimeStyles style, ulong expected)
- {
- Assert.Equal(expected, (ulong)style);
- }
- }
-}
+++ /dev/null
-// 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 NumberStylesTests
- {
- [Theory]
- [InlineData(NumberStyles.AllowCurrencySymbol, 0x00000100)]
- [InlineData(NumberStyles.AllowDecimalPoint, 0x00000020)]
- [InlineData(NumberStyles.AllowExponent, 0x00000080)]
- [InlineData(NumberStyles.AllowHexSpecifier, 0x00000200)]
- [InlineData(NumberStyles.AllowLeadingSign, 0x00000004)]
- [InlineData(NumberStyles.AllowLeadingWhite, 0x00000001)]
- [InlineData(NumberStyles.AllowParentheses, 0x00000010)]
- [InlineData(NumberStyles.AllowThousands, 0x00000040)]
- [InlineData(NumberStyles.AllowTrailingSign, 0x00000008)]
- [InlineData(NumberStyles.AllowTrailingWhite, 0x00000002)]
- [InlineData(NumberStyles.Any, NumberStyles.AllowExponent | NumberStyles.Currency)]
- [InlineData(NumberStyles.Currency, NumberStyles.AllowParentheses | NumberStyles.Number | NumberStyles.AllowCurrencySymbol)]
- [InlineData(NumberStyles.Float, NumberStyles.Integer | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent)]
- [InlineData(NumberStyles.HexNumber, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowHexSpecifier)]
- [InlineData(NumberStyles.Integer, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign)]
- [InlineData(NumberStyles.None, 0x00000000)]
- [InlineData(NumberStyles.Number, NumberStyles.Integer | NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands)]
- public void EnumNames_MatchExpectedValues(NumberStyles style, int expected)
- {
- Assert.Equal(expected, (int)style);
- }
- }
-}
+++ /dev/null
-// 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 RegionInfoMethodTests
- {
- [Theory]
- [InlineData("US", "US", "US")]
- [InlineData("IT", "IT", "IT")]
- [InlineData("IE", "IE", "IE")]
- [InlineData("SA", "SA", "SA")]
- [InlineData("JP", "JP", "JP")]
- [InlineData("CN", "CN", "CN")]
- [InlineData("TW", "TW", "TW")]
- [InlineData("en-GB", "GB", "en-GB")]
- [InlineData("en-IE", "IE", "en-IE")]
- [InlineData("en-US", "US", "en-US")]
- [InlineData("zh-CN", "CN", "zh-CN")]
- public void Ctor(string name, string expectedName, string windowsDesktopName)
- {
- var regionInfo = new RegionInfo(name);
- Assert.True(windowsDesktopName.Equals(regionInfo.Name) || expectedName.Equals(regionInfo.Name));
- Assert.Equal(regionInfo.Name, regionInfo.ToString());
- }
-
- [Fact]
- public void Ctor_NullName_ThrowsArgumentNullException()
- {
- AssertExtensions.Throws<ArgumentNullException>("name", () => new RegionInfo(null));
- }
-
- [Fact]
- public void Ctor_EmptyName_ThrowsArgumentException()
- {
- AssertExtensions.Throws<ArgumentException>("name", null, () => new RegionInfo(""));
- }
-
- [Theory]
- [InlineData("no-such-culture")]
- [InlineData("en")]
- public void Ctor_InvalidName_ThrowsArgumentException(string name)
- {
- AssertExtensions.Throws<ArgumentException>("name", () => new RegionInfo(name));
- }
-
- public static IEnumerable<object[]> Equals_TestData()
- {
- yield return new object[] { new RegionInfo("en-US"), new RegionInfo("en-US"), true };
- yield return new object[] { new RegionInfo("en-US"), new RegionInfo("en-GB"), false };
- yield return new object[] { new RegionInfo("en-US"), new RegionInfo("zh-CN"), false };
- yield return new object[] { new RegionInfo("en-US"), new object(), false };
- yield return new object[] { new RegionInfo("en-US"), null, false };
- }
-
- [Theory]
- [MemberData(nameof(Equals_TestData))]
- public void Equals(RegionInfo regionInfo1, object obj, bool expected)
- {
- Assert.Equal(expected, regionInfo1.Equals(obj));
- Assert.Equal(regionInfo1.GetHashCode(), regionInfo1.GetHashCode());
- if (obj is RegionInfo)
- {
- Assert.Equal(expected, regionInfo1.GetHashCode().Equals(obj.GetHashCode()));
- }
- }
- }
-}
+++ /dev/null
-// 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 System.Diagnostics;
-using System.Linq;
-using Xunit;
-
-namespace System.Globalization.Tests
-{
- public class RegionInfoPropertyTests : RemoteExecutorTestBase
- {
- [Fact]
- public void CurrentRegion()
- {
- RemoteInvoke(() =>
- {
- CultureInfo.CurrentCulture = new CultureInfo("en-US");
-
- RegionInfo ri = new RegionInfo(new RegionInfo(CultureInfo.CurrentCulture.Name).TwoLetterISORegionName);
- Assert.True(RegionInfo.CurrentRegion.Equals(ri) || RegionInfo.CurrentRegion.Equals(new RegionInfo(CultureInfo.CurrentCulture.Name)));
- Assert.Same(RegionInfo.CurrentRegion, RegionInfo.CurrentRegion);
-
- return SuccessExitCode;
- }).Dispose();
- }
-
- [Theory]
- [InlineData("en-US", "United States")]
- public void DisplayName(string name, string expected)
- {
- RemoteInvoke((string _name, string _expected) =>
- {
- CultureInfo.CurrentUICulture = new CultureInfo(_name);
- Assert.Equal(_expected, new RegionInfo(_name).DisplayName);
-
- return SuccessExitCode;
- }, name, expected).Dispose();
- }
-
- [Theory]
- [InlineData("GB", "United Kingdom")]
- [InlineData("SE", "Sverige")]
- [InlineData("FR", "France")]
- public void NativeName(string name, string expected)
- {
- Assert.Equal(expected, new RegionInfo(name).NativeName);
- }
-
- [Theory]
- [InlineData("en-US", new string[] { "United States" })]
- [InlineData("US", new string[] { "United States" })]
- [InlineData("zh-CN", new string[] { "China", "People's Republic of China" })]
- [InlineData("CN", new string[] { "China", "People's Republic of China" })]
- public void EnglishName(string name, string[] expected)
- {
- string result = new RegionInfo(name).EnglishName;
- Assert.True(expected.Contains(result));
- }
-
- [Theory]
- [InlineData("en-US", false)]
- [InlineData("zh-CN", true)]
- public void IsMetric(string name, bool expected)
- {
- Assert.Equal(expected, new RegionInfo(name).IsMetric);
- }
-
- [Theory]
- [InlineData("en-US", "USD")]
- [InlineData("zh-CN", "CNY")]
- [InlineData("de-DE", "EUR")]
- [InlineData("it-IT", "EUR")]
- public void ISOCurrencySymbol(string name, string expected)
- {
- Assert.Equal(expected, new RegionInfo(name).ISOCurrencySymbol);
- }
-
- [Theory]
- [InlineData("en-US", new string[] { "$" })]
- [InlineData("zh-CN", new string[] { "\u00A5", "\uffe5" })] // \u00A5 is Latin-1 Supplement(Windows), \uffe5 is Halfwidth and Fullwidth Forms(ICU)
- public void CurrencySymbol(string name, string[] expected)
- {
- string result = new RegionInfo(name).CurrencySymbol;
- Assert.True(expected.Contains(result));
- }
-
- [Theory]
- [InlineData("en-US", "US")]
- [InlineData("zh-CN", "CN")]
- [InlineData("de-DE", "DE")]
- [InlineData("it-IT", "IT")]
- public void TwoLetterISORegionName(string name, string expected)
- {
- Assert.Equal(expected, new RegionInfo(name).TwoLetterISORegionName);
- }
-
- public static IEnumerable<object[]> RegionInfo_TestData()
- {
- yield return new object[] { 0x409, 244, "US Dollar", "US Dollar", "\u0055\u0053\u0020\u0044\u006f\u006c\u006c\u0061\u0072", "USA", "USA" };
- yield return new object[] { 0x411, 122, "Japanese Yen", "Japanese Yen", PlatformDetection.IsWindows ? "\u5186" : "\u65e5\u672c\u5186", "JPN", "JPN" };
- yield return new object[] { 0x804, 45, "Chinese Yuan", "PRC Yuan Renminbi", "\u4eba\u6c11\u5e01", "CHN", "CHN" };
- yield return new object[] { 0x401, 205, "Saudi Riyal", "Saudi Riyal", PlatformDetection.IsWindows ?
- "\u0631\u064a\u0627\u0644\u00a0\u0633\u0639\u0648\u062f\u064a" :
- "\u0631\u064a\u0627\u0644\u0020\u0633\u0639\u0648\u062f\u064a",
- "SAU", "SAU" };
- yield return new object[] { 0x412, 134, "South Korean Won", "Korean Won", PlatformDetection.IsWindows ? "\uc6d0" : "\ub300\ud55c\ubbfc\uad6d\u0020\uc6d0", "KOR", "KOR" };
- yield return new object[] { 0x40d, 117, "Israeli New Shekel", "Israeli New Sheqel",
- PlatformDetection.IsWindows || PlatformDetection.ICUVersion.Major >= 58 ? "\u05e9\u05e7\u05dc\u0020\u05d7\u05d3\u05e9" : "\u05e9\u05f4\u05d7", "ISR", "ISR" };
- }
-
- [Theory]
- [MemberData(nameof(RegionInfo_TestData))]
- public void MiscTest(int lcid, int geoId, string currencyEnglishName, string alternativeCurrencyEnglishName, string currencyNativeName, string threeLetterISORegionName, string threeLetterWindowsRegionName)
- {
- RegionInfo ri = new RegionInfo(lcid); // create it with lcid
- Assert.Equal(geoId, ri.GeoId);
- Assert.True(currencyEnglishName.Equals(ri.CurrencyEnglishName) ||
- alternativeCurrencyEnglishName.Equals(ri.CurrencyEnglishName), "Wrong currency English Name");
- Assert.Equal(currencyNativeName, ri.CurrencyNativeName);
- Assert.Equal(threeLetterISORegionName, ri.ThreeLetterISORegionName);
- Assert.Equal(threeLetterWindowsRegionName, ri.ThreeLetterWindowsRegionName);
- }
- }
-}
+++ /dev/null
-// 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 SortVersionMiscTests
- {
- [Fact]
- public void ConstructionsTest()
- {
- string guidString = "00000001-57ee-1e5c-00b4-d0000bb1e11e";
- SortVersion version = new SortVersion(393742, new Guid(guidString));
- Assert.Equal(393742, version.FullVersion);
- Assert.Equal(new Guid(guidString), version.SortId);
- }
-
- [Fact]
- public void EquaityTest()
- {
- SortVersion version1 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));
- SortVersion version2 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));
-
- Assert.Equal(version2, version1);
- }
- }
-}
+++ /dev/null
-// 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 StringInfoCtorTests
- {
- [Fact]
- public void Ctor_Default()
- {
- StringInfo stringInfo = new StringInfo();
- Assert.Equal(string.Empty, stringInfo.String);
- Assert.Equal(0, stringInfo.LengthInTextElements);
- }
-
- public static IEnumerable<object[]> Ctor_String_TestData()
- {
- yield return new object[] { new string('a', 256), 256 };
- yield return new object[] { "\u4f00\u302a\ud800\udc00\u4f01", 3 };
- yield return new object[] { "abcdefgh", 8 };
- yield return new object[] { "zj\uDBFF\uDFFFlk", 5 };
- yield return new object[] { "!@#$%^&", 7 };
- yield return new object[] { "!\u20D1bo\uFE22\u20D1\u20EB|", 4 };
- yield return new object[] { "1\uDBFF\uDFFF@\uFE22\u20D1\u20EB9", 4 };
- yield return new object[] { "a\u0300", 1 };
- yield return new object[] { " ", 3 };
- yield return new object[] { "", 0 };
- }
-
- [Theory]
- [MemberData(nameof(Ctor_String_TestData))]
- public void Ctor_String(string value, int lengthInTextElements)
- {
- var stringInfo = new StringInfo(value);
- Assert.Same(value, stringInfo.String);
- Assert.Equal(lengthInTextElements, stringInfo.LengthInTextElements);
- }
-
- [Fact]
- public void Ctor_NullValue_ThrowsArgumentNullException()
- {
- AssertExtensions.Throws<ArgumentNullException>("value", "String", () => new StringInfo(null));
- }
- }
-}
+++ /dev/null
-// 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 StringInfoEquals
- {
- public static IEnumerable<object[]> Equals_TestData()
- {
- yield return new object[] { new StringInfo(), new StringInfo(), true };
- yield return new object[] { new StringInfo("stringinfo1"), new StringInfo("stringinfo1"), true };
- yield return new object[] { new StringInfo("stringinfo1"), new StringInfo("stringinfo2"), false };
- yield return new object[] { new StringInfo("stringinfo1"), "stringinfo1", false };
- yield return new object[] { new StringInfo("stringinfo1"), 123, false };
- yield return new object[] { new StringInfo("stringinfo1"), null, false };
- }
-
- [Theory]
- [MemberData(nameof(Equals_TestData))]
- public void Equals(StringInfo stringInfo, object value, bool expected)
- {
- Assert.Equal(expected, stringInfo.Equals(value));
- if (value is StringInfo)
- {
- Assert.Equal(expected, stringInfo.GetHashCode().Equals(value.GetHashCode()));
- }
- }
- }
-}
+++ /dev/null
-// 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 StringInfoGetNextTextElement
- {
- public static IEnumerable<object[]> GetNextTextElement_TestData()
- {
- yield return new object[] { "", 0, "" }; // Empty string
- yield return new object[] { "Hello", 5, "" }; // Index = string.Length
-
- // Surrogate pair
- yield return new object[] { "\uDBFF\uDFFFabcde", 0, "\uDBFF\uDFFF" };
- yield return new object[] { "ef45-;\uDBFF\uDFFFabcde", 6, "\uDBFF\uDFFF" };
-
- yield return new object[] { "a\u20D1abcde", 0, "a\u20D1" }; // Combining character or non spacing mark
-
- // Base character with several combining characters
- yield return new object[] { "z\uFE22\u20D1\u20EBabcde", 0, "z\uFE22\u20D1\u20EB" };
- yield return new object[] { "az\uFE22\u20D1\u20EBabcde", 1, "z\uFE22\u20D1\u20EB" };
-
- yield return new object[] { "13229^a\u20D1abcde", 6, "a\u20D1" }; // Combining characters
-
- // Single base and combining character
- yield return new object[] { "a\u0300", 0, "a\u0300" };
- yield return new object[] { "a\u0300", 1, "\u0300" };
-
- // Lone combining character
- yield return new object[] { "\u0300\u0300", 0, "\u0300" };
- yield return new object[] { "\u0300\u0300", 1, "\u0300" };
- }
-
- [Theory]
- [MemberData(nameof(GetNextTextElement_TestData))]
- public void GetNextTextElement(string str, int index, string expected)
- {
- if (index == 0)
- {
- Assert.Equal(expected, StringInfo.GetNextTextElement(str));
- }
- Assert.Equal(expected, StringInfo.GetNextTextElement(str, index));
- }
-
- [Fact]
- public void GetNextTextElement_Invalid()
- {
- AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetNextTextElement(null)); // Str is null
- AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetNextTextElement(null, 0)); // Str is null
-
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetNextTextElement("abc", -1)); // Index < 0
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetNextTextElement("abc", 4)); // Index > str.Length
- }
- }
-}
+++ /dev/null
-// 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 StringInfoGetTextElementEnumerator
- {
- public static IEnumerable<object[]> GetTextElementEnumerator_TestData()
- {
- yield return new object[] { "", 0, new string[0] }; // Empty string
- yield return new object[] { "Hello", 5, new string[0] }; // Index = string.Length
-
- // Surrogate pair
- yield return new object[] { "s\uDBFF\uDFFF$", 0, new string[] { "s", "\uDBFF\uDFFF", "$" } };
- yield return new object[] { "s\uDBFF\uDFFF$", 1, new string[] { "\uDBFF\uDFFF", "$" } };
-
- // Combining characters
- yield return new object[] { "13229^a\u20D1a", 6, new string[] { "a\u20D1", "a" } };
- yield return new object[] { "13229^a\u20D1a", 0, new string[] { "1", "3", "2", "2", "9", "^", "a\u20D1", "a" } };
-
- // Single base and combining character
- yield return new object[] { "a\u0300", 0, new string[] { "a\u0300" } };
- yield return new object[] { "a\u0300", 1, new string[] { "\u0300" } };
-
- // Lone combining character
- yield return new object[] { "\u0300\u0300", 0, new string[] { "\u0300", "\u0300" } };
- }
-
- [Theory]
- [MemberData(nameof(GetTextElementEnumerator_TestData))]
- public void GetTextElementEnumerator(string str, int index, string[] expected)
- {
- if (index == 0)
- {
- TextElementEnumerator basicEnumerator = StringInfo.GetTextElementEnumerator(str);
- int basicCounter = 0;
- while (basicEnumerator.MoveNext())
- {
- Assert.Equal(expected[basicCounter], basicEnumerator.Current.ToString());
- basicCounter++;
- }
- Assert.Equal(expected.Length, basicCounter);
- }
- TextElementEnumerator indexedEnumerator = StringInfo.GetTextElementEnumerator(str, index);
- int indexedCounter = 0;
- while (indexedEnumerator.MoveNext())
- {
- Assert.Equal(expected[indexedCounter], indexedEnumerator.Current.ToString());
- indexedCounter++;
- }
- Assert.Equal(expected.Length, indexedCounter);
- }
-
- [Fact]
- public void GetTextElementEnumerator_Invalid()
- {
- AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetTextElementEnumerator(null)); // Str is null
- AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetTextElementEnumerator(null, 0)); // Str is null
-
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetTextElementEnumerator("abc", -1)); // Index < 0
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetTextElementEnumerator("abc", 4)); // Index > str.Length
- }
- }
-}
+++ /dev/null
-// 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 StringInfoParseCombiningCharacters
- {
- public static IEnumerable<object[]> ParseCombiningCharacters_TestData()
- {
- yield return new object[] { "\u4f00\u302a\ud800\udc00\u4f01", new int[] { 0, 2, 4 } };
- yield return new object[] { "abcdefgh", new int[] { 0, 1, 2, 3, 4, 5, 6, 7 } };
- yield return new object[] { "!@#$%^&", new int[] { 0, 1, 2, 3, 4, 5, 6 } };
- yield return new object[] { "!\u20D1bo\uFE22\u20D1\u20EB|", new int[] { 0, 2, 3, 7 } };
- yield return new object[] { "1\uDBFF\uDFFF@\uFE22\u20D1\u20EB9", new int[] { 0, 1, 3, 7 } };
- yield return new object[] { "a\u0300", new int[] { 0 } };
- yield return new object[] { "\u0300\u0300", new int[] { 0, 1 } };
- yield return new object[] { " ", new int[] { 0, 1, 2 } };
- yield return new object[] { "", new int[0] };
-
- // Invalid Unicode
- yield return new object[] { "\u0000\uFFFFa", new int[] { 0, 1, 2 } }; // Control chars
- yield return new object[] { "\uD800a", new int[] { 0, 1 } }; // Unmatched high surrogate
- yield return new object[] { "\uDC00a", new int[] { 0, 1 } }; // Unmatched low surrogate
- yield return new object[] { "\u00ADa", new int[] { 0, 1 } }; // Format character
-
- yield return new object[] { "\u0000\u0300\uFFFF\u0300", new int[] { 0, 1, 2, 3 } }; // Control chars + combining char
- yield return new object[] { "\uD800\u0300", new int[] { 0, 1 } }; // Unmatched high surrogate + combining char
- yield return new object[] { "\uDC00\u0300", new int[] { 0, 1 } }; // Unmatched low surrogate + combing char
- yield return new object[] { "\u00AD\u0300", new int[] { 0, 1 } }; // Format character + combining char
-
- yield return new object[] { "\u0300\u0300", new int[] { 0, 1 } }; // Two combining chars
- }
-
- [Theory]
- [MemberData(nameof(ParseCombiningCharacters_TestData))]
- public void ParseCombiningCharacters(string str, int[] expected)
- {
- Assert.Equal(expected, StringInfo.ParseCombiningCharacters(str));
- }
-
- [Fact]
- public void ParseCombiningCharacters_Null_ThrowsArgumentNullException()
- {
- AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.ParseCombiningCharacters(null)); // Str is null
- }
- }
-}
+++ /dev/null
-// 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 StringInfoString
- {
- [Theory]
- [InlineData("")]
- [InlineData("abc")]
- [InlineData("\uD800\uDC00")]
- public void String_Set_GetReturnsExpected(string value)
- {
- StringInfo stringInfo = new StringInfo();
- stringInfo.String = value;
- Assert.Same(value, stringInfo.String);
- }
-
- [Fact]
- public void String_SetNull_ThrowsArgumentNullException()
- {
- var stringInfo = new StringInfo();
- AssertExtensions.Throws<ArgumentNullException>("value", "String", () => stringInfo.String = null);
- }
- }
-}
+++ /dev/null
-// 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 System.Reflection;
-using Xunit;
-
-namespace System.Globalization.Tests
-{
- public class StringInfoMiscTests
- {
- public static IEnumerable<object[]> StringInfo_TestData()
- {
- yield return new object[] { "Simple Text", 7, "Text", 4, "Text" };
- yield return new object[] { "Simple Text", 0, "Simple Text", 6, "Simple" };
- yield return new object[] { "\uD800\uDC00\uD801\uDC01Left", 2, "Left", 2, "Le" };
- yield return new object[] { "\uD800\uDC00\uD801\uDC01Left", 1, "\uD801\uDC01Left", 2, "\uD801\uDC01L" };
- yield return new object[] { "Start\uD800\uDC00\uD801\uDC01Left", 5, "\uD800\uDC00\uD801\uDC01Left", 1, "\uD800\uDC00" };
- }
-
- [Theory]
- [MemberData(nameof(StringInfo_TestData))]
- public void SubstringTest(string source, int index, string expected, int length, string expectedWithLength)
- {
- StringInfo si = new StringInfo(source);
- Assert.Equal(expected, si.SubstringByTextElements(index));
- Assert.Equal(expectedWithLength, si.SubstringByTextElements(index, length));
- }
-
- [Fact]
- public void NegativeTest()
- {
- string s = "Some String";
- StringInfo si = new StringInfo(s);
- StringInfo siEmpty = new StringInfo("");
-
- Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(-1));
- Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(s.Length + 1));
- Assert.Throws<ArgumentOutOfRangeException>(() => siEmpty.SubstringByTextElements(0));
-
- Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(-1, 1));
- Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(s.Length + 1, 1));
- Assert.Throws<ArgumentOutOfRangeException>(() => siEmpty.SubstringByTextElements(0, 0));
- Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(0, s.Length + 1));
- }
- }
-}
<TestRuntime>true</TestRuntime>
</PropertyGroup>
<ItemGroup>
- <Compile Include="CharUnicodeInfo\CharUnicodeInfoTestData.cs" />
- <Compile Include="CharUnicodeInfo\CharUnicodeInfoTests.cs" />
<Compile Include="CompareInfo\CompareInfoTests.cs" />
<Compile Include="CompareInfo\CompareInfoTests.IndexOf.cs" />
<Compile Include="CompareInfo\CompareInfoTests.IsPrefix.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoPercentNegativePattern.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoPercentGroupSizes.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoPercentPositivePattern.cs" />
- <Compile Include="RegionInfo\RegionInfoTests.Methods.cs" />
- <Compile Include="RegionInfo\RegionInfoTests.Properties.cs" />
<Compile Include="CultureInfo\CultureInfoAll.cs" />
<Compile Include="CultureInfo\CultureInfoAsync.cs" />
<Compile Include="CultureInfo\CultureInfoCalendar.cs" />
<Compile Include="CultureInfo\CultureInfoReadOnly.cs" />
<Compile Include="CultureInfo\CultureInfoTwoLetterISOLanguageName.cs" />
<Compile Include="CultureInfo\CultureInfoCurrentCulture.cs" />
- <Compile Include="CultureNotFoundException\CultureNotFoundExceptionTests.cs" />
<Compile Include="DateTimeFormatInfo\DateTimeFormatInfoAbbreviatedDayNames.cs" />
<Compile Include="DateTimeFormatInfo\DateTimeFormatInfoAbbreviatedMonthGenitiveNames.cs" />
<Compile Include="DateTimeFormatInfo\DateTimeFormatInfoAbbreviatedMonthNames.cs" />
<Compile Include="DateTimeFormatInfo\DateTimeFormatInfoTests.cs" />
<Compile Include="DateTimeFormatInfo\DateTimeFormatInfoUniversalSortableDateTimePattern.cs" />
<Compile Include="DateTimeFormatInfo\DateTimeFormatInfoYearMonthPattern.cs" />
- <Compile Include="DateTimeStyles\DateTimeStylesTests.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoClone.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoCurrencyDecimalDigits.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoCurrencyDecimalSeparator.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoGetInstance.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoReadOnly.cs" />
<Compile Include="NumberFormatInfo\NumberFormatInfoTests.cs" />
- <Compile Include="NumberStyles\NumberStylesTests.cs" />
- <Compile Include="SortVersion\SortVersionTests.cs" />
- <Compile Include="StringInfo\StringInfoCtor.cs" />
- <Compile Include="StringInfo\StringInfoEquals.cs" />
- <Compile Include="StringInfo\StringInfoGetNextTextElement.cs" />
- <Compile Include="StringInfo\StringInfoGetTextElementEnumerator.cs" />
- <Compile Include="StringInfo\StringInfoParseCombiningCharacters.cs" />
- <Compile Include="StringInfo\StringInfoString.cs" />
- <Compile Include="StringInfo\StringInfoTests.cs" />
- <Compile Include="TextElementEnumerator\TextElementEnumeratorTests.cs" />
- <Compile Include="TextInfo\TextInfoCultureName.cs" />
- <Compile Include="TextInfo\TextInfoEquals.cs" />
- <Compile Include="TextInfo\TextInfoIsRightToLeft.cs" />
- <Compile Include="TextInfo\TextInfoIsReadOnly.cs" />
- <Compile Include="TextInfo\TextInfoListSeparator.cs" />
- <Compile Include="TextInfo\TextInfoTests.cs" />
- <Compile Include="TextInfo\TextInfoToLower.cs" />
- <Compile Include="TextInfo\TextInfoToString.cs" />
- <Compile Include="TextInfo\TextInfoToUpper.cs" />
- <Compile Include="UnicodeCategory\UnicodeCategoryTests.cs" />
+ <Compile Include="System\Globalization\CharUnicodeInfoTestData.cs" />
+ <Compile Include="System\Globalization\CharUnicodeInfoTests.cs" />
+ <Compile Include="System\Globalization\CultureNotFoundExceptionTests.cs" />
+ <Compile Include="System\Globalization\RegionInfoTests.cs" />
+ <Compile Include="System\Globalization\StringInfoTests.cs" />
+ <Compile Include="System\Globalization\SortVersionTests.cs" />
+ <Compile Include="System\Globalization\TextInfoTests.cs" />
+ <Compile Include="System\Globalization\TextElementEnumeratorTests.cs" />
+ <Compile Include="System\Globalization\UnicodeCategoryTests.cs" />
<!-- Helpers -->
<Compile Include="$(CommonTestPath)\System\RandomDataGenerator.cs">
<Link>Common\System\RandomDataGenerator.cs</Link>
--- /dev/null
+// 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 System.IO;
+using System.Reflection;
+
+namespace System.Globalization.Tests
+{
+ public static class CharUnicodeInfoTestData
+ {
+ private static readonly Lazy<List<CharUnicodeInfoTestCase>> s_testCases = new Lazy<List<CharUnicodeInfoTestCase>>(() =>
+ {
+ List<CharUnicodeInfoTestCase> testCases = new List<CharUnicodeInfoTestCase>();
+ string fileName =
+ CharUnicodeInfo.GetUnicodeCategory('\u10D0') == UnicodeCategory.LowercaseLetter ? "UnicodeData.11.0.txt" :
+ CharUnicodeInfo.GetUnicodeCategory('\u037f') == UnicodeCategory.OtherNotAssigned ? "UnicodeData6.3.txt" : "UnicodeData.8.0.txt";
+ Stream stream = typeof(CharUnicodeInfoGetUnicodeCategoryTests).GetTypeInfo().Assembly.GetManifestResourceStream(fileName);
+ using (StreamReader reader = new StreamReader(stream))
+ {
+ while (!reader.EndOfStream)
+ {
+ Parse(testCases, reader.ReadLine());
+ }
+ }
+ return testCases;
+ });
+
+ public static List<CharUnicodeInfoTestCase> TestCases => s_testCases.Value;
+
+ private static int s_rangeMinCodePoint;
+ private static void Parse(List<CharUnicodeInfoTestCase> testCases, string line)
+ {
+ // Data is in the format:
+ // code-value;
+ // character-name;
+ // general-category;
+ // canonical-combining-classes; (ignored)
+ // bidirecional-category; (ignored)
+ // character-decomposition-mapping; (ignored)
+ // decimal-digit-value; (ignored)
+ // digit-value; (ignoed)
+ // number-value;
+ string[] data = line.Split(';');
+ string charValueString = data[0];
+ string charName = data[1];
+ string charCategoryString = data[2];
+ string numericValueString = data[8];
+
+ int codePoint = int.Parse(charValueString, NumberStyles.HexNumber);
+ Parse(testCases, codePoint, charCategoryString, numericValueString);
+
+ if (charName.EndsWith("First>"))
+ {
+ s_rangeMinCodePoint = codePoint;
+ }
+ else if (charName.EndsWith("Last>"))
+ {
+ // Assumes that we have already found a range start
+ for (int rangeCodePoint = s_rangeMinCodePoint + 1; rangeCodePoint < codePoint; rangeCodePoint++)
+ {
+ // Assumes that all code points in the range have the same numeric value
+ // and general category
+ Parse(testCases, rangeCodePoint, charCategoryString, numericValueString);
+ }
+ }
+ }
+
+ private static Dictionary<string, UnicodeCategory> s_unicodeCategories = new Dictionary<string, UnicodeCategory>
+ {
+ ["Pe"] = UnicodeCategory.ClosePunctuation,
+ ["Pc"] = UnicodeCategory.ConnectorPunctuation,
+ ["Cc"] = UnicodeCategory.Control,
+ ["Sc"] = UnicodeCategory.CurrencySymbol,
+ ["Pd"] = UnicodeCategory.DashPunctuation,
+ ["Nd"] = UnicodeCategory.DecimalDigitNumber,
+ ["Me"] = UnicodeCategory.EnclosingMark,
+ ["Pf"] = UnicodeCategory.FinalQuotePunctuation,
+ ["Cf"] = UnicodeCategory.Format,
+ ["Pi"] = UnicodeCategory.InitialQuotePunctuation,
+ ["Nl"] = UnicodeCategory.LetterNumber,
+ ["Zl"] = UnicodeCategory.LineSeparator,
+ ["Ll"] = UnicodeCategory.LowercaseLetter,
+ ["Sm"] = UnicodeCategory.MathSymbol,
+ ["Lm"] = UnicodeCategory.ModifierLetter,
+ ["Sk"] = UnicodeCategory.ModifierSymbol,
+ ["Mn"] = UnicodeCategory.NonSpacingMark,
+ ["Ps"] = UnicodeCategory.OpenPunctuation,
+ ["Lo"] = UnicodeCategory.OtherLetter,
+ ["Cn"] = UnicodeCategory.OtherNotAssigned,
+ ["No"] = UnicodeCategory.OtherNumber,
+ ["Po"] = UnicodeCategory.OtherPunctuation,
+ ["So"] = UnicodeCategory.OtherSymbol,
+ ["Po"] = UnicodeCategory.OtherPunctuation,
+ ["Zp"] = UnicodeCategory.ParagraphSeparator,
+ ["Co"] = UnicodeCategory.PrivateUse,
+ ["Zs"] = UnicodeCategory.SpaceSeparator,
+ ["Mc"] = UnicodeCategory.SpacingCombiningMark,
+ ["Cs"] = UnicodeCategory.Surrogate,
+ ["Lt"] = UnicodeCategory.TitlecaseLetter,
+ ["Lu"] = UnicodeCategory.UppercaseLetter
+ };
+
+ private static void Parse(List<CharUnicodeInfoTestCase> testCases, int codePoint, string charCategoryString, string numericValueString)
+ {
+ string codeValueRepresentation = codePoint > char.MaxValue ? char.ConvertFromUtf32(codePoint) : ((char)codePoint).ToString();
+ double numericValue = ParseNumericValueString(numericValueString);
+ UnicodeCategory generalCategory = s_unicodeCategories[charCategoryString];
+
+ testCases.Add(new CharUnicodeInfoTestCase()
+ {
+ Utf32CodeValue = codeValueRepresentation,
+ GeneralCategory = generalCategory,
+ NumericValue = numericValue,
+ CodePoint = codePoint
+ });
+ }
+
+ private static double ParseNumericValueString(string numericValueString)
+ {
+ if (numericValueString.Length == 0)
+ {
+ // Parsing empty string (no numeric value)
+ return -1;
+ }
+
+ int fractionDelimeterIndex = numericValueString.IndexOf("/");
+ if (fractionDelimeterIndex == -1)
+ {
+ // Parsing basic number
+ return double.Parse(numericValueString);
+ }
+
+ // Unicode datasets display fractions not decimals (e.g. 1/4 instead of 0.25),
+ // so we should parse them as such
+ string numeratorString = numericValueString.Substring(0, fractionDelimeterIndex);
+ double numerator = double.Parse(numeratorString);
+
+ string denominatorString = numericValueString.Substring(fractionDelimeterIndex + 1);
+ double denominator = double.Parse(denominatorString);
+
+ return numerator / denominator;
+ }
+ }
+
+ public class CharUnicodeInfoTestCase
+ {
+ public string Utf32CodeValue { get; set; }
+ public int CodePoint { get; set; }
+ public UnicodeCategory GeneralCategory { get; set; }
+ public double NumericValue { get; set; }
+ }
+}
--- /dev/null
+// 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 CharUnicodeInfoGetUnicodeCategoryTests
+ {
+ [Fact]
+ public void GetUnicodeCategory()
+ {
+ foreach (CharUnicodeInfoTestCase testCase in CharUnicodeInfoTestData.TestCases)
+ {
+ if (testCase.Utf32CodeValue.Length == 1)
+ {
+ // Test the char overload for a single char
+ GetUnicodeCategory(testCase.Utf32CodeValue[0], testCase.GeneralCategory);
+ }
+ // Test the string overload for a surrogate pair or a single char
+ GetUnicodeCategory(testCase.Utf32CodeValue, new UnicodeCategory[] { testCase.GeneralCategory });
+#if netcoreapp
+ Assert.Equal(testCase.GeneralCategory, CharUnicodeInfo.GetUnicodeCategory(testCase.CodePoint));
+#endif // netcoreapp
+ }
+ }
+
+ [Theory]
+ [InlineData('\uFFFF', UnicodeCategory.OtherNotAssigned)]
+ public void GetUnicodeCategory(char ch, UnicodeCategory expected)
+ {
+ UnicodeCategory actual = CharUnicodeInfo.GetUnicodeCategory(ch);
+ Assert.True(actual == expected, ErrorMessage(ch, expected, actual));
+ }
+
+ [Theory]
+ [InlineData("aA1!", new UnicodeCategory[] { UnicodeCategory.LowercaseLetter, UnicodeCategory.UppercaseLetter, UnicodeCategory.DecimalDigitNumber, UnicodeCategory.OtherPunctuation })]
+ [InlineData("\uD808\uDF6C", new UnicodeCategory[] { UnicodeCategory.OtherLetter, UnicodeCategory.Surrogate })]
+ [InlineData("a\uD808\uDF6Ca", new UnicodeCategory[] { UnicodeCategory.LowercaseLetter, UnicodeCategory.OtherLetter, UnicodeCategory.Surrogate, UnicodeCategory.LowercaseLetter })]
+ public void GetUnicodeCategory(string s, UnicodeCategory[] expected)
+ {
+ for (int i = 0; i < expected.Length; i++)
+ {
+ Assert.Equal(expected[i], CharUnicodeInfo.GetUnicodeCategory(s, i));
+ }
+ }
+
+ [Fact]
+ public void GetUnicodeCategory_String_InvalidSurrogatePairs()
+ {
+ // High, high surrogate pair
+ GetUnicodeCategory("\uD808\uD808", new UnicodeCategory[] { UnicodeCategory.Surrogate, UnicodeCategory.Surrogate });
+
+ // Low, low surrogate pair
+ GetUnicodeCategory("\uDF6C\uDF6C", new UnicodeCategory[] { UnicodeCategory.Surrogate, UnicodeCategory.Surrogate });
+
+ // Low, high surrogate pair
+ GetUnicodeCategory("\uDF6C\uD808", new UnicodeCategory[] { UnicodeCategory.Surrogate, UnicodeCategory.Surrogate });
+ }
+
+ [Fact]
+ public void GetUnicodeCategory_Invalid()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("s", () => CharUnicodeInfo.GetUnicodeCategory(null, 0));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetUnicodeCategory("abc", -1));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetUnicodeCategory("abc", 3));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetUnicodeCategory("", 0));
+ }
+
+ [Fact]
+ public void GetNumericValue()
+ {
+ foreach (CharUnicodeInfoTestCase testCase in CharUnicodeInfoTestData.TestCases)
+ {
+ if (testCase.Utf32CodeValue.Length == 1)
+ {
+ // Test the char overload for a single char
+ GetNumericValue(testCase.Utf32CodeValue[0], testCase.NumericValue);
+ }
+ // Test the string overload for a surrogate pair
+ GetNumericValue(testCase.Utf32CodeValue, new double[] { testCase.NumericValue });
+ }
+ }
+
+ [Theory]
+ [InlineData('\uFFFF', -1)]
+ public void GetNumericValue(char ch, double expected)
+ {
+ double actual = CharUnicodeInfo.GetNumericValue(ch);
+ Assert.True(expected == actual, ErrorMessage(ch, expected, actual));
+ }
+
+ [Theory]
+ [MemberData(nameof(s_GetNumericValueData))]
+ public void GetNumericValue(string s, double[] expected)
+ {
+ for (int i = 0; i < expected.Length; i++)
+ {
+ Assert.Equal(expected[i], CharUnicodeInfo.GetNumericValue(s, i));
+ }
+ }
+
+ public static readonly object[][] s_GetNumericValueData =
+ {
+ new object[] {"aA1!", new double[] { -1, -1, 1, -1 }},
+ // Numeric surrogate (CUNEIFORM NUMERIC SIGN FIVE BAN2 VARIANT FORM)
+ new object[] {"\uD809\uDC55", new double[] { 5, -1 }},
+ new object[] {"a\uD809\uDC55a", new double[] { -1, 5, -1 , -1 }},
+ // Numeric surrogate (CUNEIFORM NUMERIC SIGN FIVE BAN2 VARIANT FORM)
+ new object[] {"\uD808\uDF6C", new double[] { -1, -1 }},
+ new object[] {"a\uD808\uDF6Ca", new double[] { -1, -1, -1, -1 }},
+ };
+
+ [Fact]
+ public void GetNumericValue_Invalid()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("s", () => CharUnicodeInfo.GetNumericValue(null, 0));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("abc", -1));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("abc", 3));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => CharUnicodeInfo.GetNumericValue("", 0));
+ }
+
+ private static string ErrorMessage(char ch, object expected, object actual)
+ {
+ return $"CodeValue: {((int)ch).ToString("X")}; Expected: {expected}; Actual: {actual}";
+ }
+
+ public static string s_numericsCodepoints =
+ "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039" +
+ "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669" +
+ "\u06f0\u06f1\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9" +
+ "\u07c0\u07c1\u07c2\u07c3\u07c4\u07c5\u07c6\u07c7\u07c8\u07c9" +
+ "\u0966\u0967\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f" +
+ "\u09e6\u09e7\u09e8\u09e9\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef" +
+ "\u0a66\u0a67\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f" +
+ "\u0ae6\u0ae7\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef" +
+ "\u0b66\u0b67\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f" +
+ "\u0be6\u0be7\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef" +
+ "\u0c66\u0c67\u0c68\u0c69\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f" +
+ "\u0ce6\u0ce7\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef" +
+ "\u0d66\u0d67\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f" +
+ "\u0e50\u0e51\u0e52\u0e53\u0e54\u0e55\u0e56\u0e57\u0e58\u0e59" +
+ "\u0ed0\u0ed1\u0ed2\u0ed3\u0ed4\u0ed5\u0ed6\u0ed7\u0ed8\u0ed9" +
+ "\u0f20\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28\u0f29" +
+ "\u1040\u1041\u1042\u1043\u1044\u1045\u1046\u1047\u1048\u1049" +
+ "\u1090\u1091\u1092\u1093\u1094\u1095\u1096\u1097\u1098\u1099" +
+ "\u17e0\u17e1\u17e2\u17e3\u17e4\u17e5\u17e6\u17e7\u17e8\u17e9" +
+ "\u1810\u1811\u1812\u1813\u1814\u1815\u1816\u1817\u1818\u1819" +
+ "\u1946\u1947\u1948\u1949\u194a\u194b\u194c\u194d\u194e\u194f" +
+ "\u19d0\u19d1\u19d2\u19d3\u19d4\u19d5\u19d6\u19d7\u19d8\u19d9" +
+ "\u1a80\u1a81\u1a82\u1a83\u1a84\u1a85\u1a86\u1a87\u1a88\u1a89" +
+ "\u1a90\u1a91\u1a92\u1a93\u1a94\u1a95\u1a96\u1a97\u1a98\u1a99" +
+ "\u1b50\u1b51\u1b52\u1b53\u1b54\u1b55\u1b56\u1b57\u1b58\u1b59" +
+ "\u1bb0\u1bb1\u1bb2\u1bb3\u1bb4\u1bb5\u1bb6\u1bb7\u1bb8\u1bb9" +
+ "\u1c40\u1c41\u1c42\u1c43\u1c44\u1c45\u1c46\u1c47\u1c48\u1c49" +
+ "\u1c50\u1c51\u1c52\u1c53\u1c54\u1c55\u1c56\u1c57\u1c58\u1c59" +
+ "\ua620\ua621\ua622\ua623\ua624\ua625\ua626\ua627\ua628\ua629" +
+ "\ua8d0\ua8d1\ua8d2\ua8d3\ua8d4\ua8d5\ua8d6\ua8d7\ua8d8\ua8d9" +
+ "\ua900\ua901\ua902\ua903\ua904\ua905\ua906\ua907\ua908\ua909" +
+ "\ua9d0\ua9d1\ua9d2\ua9d3\ua9d4\ua9d5\ua9d6\ua9d7\ua9d8\ua9d9" +
+ "\uaa50\uaa51\uaa52\uaa53\uaa54\uaa55\uaa56\uaa57\uaa58\uaa59" +
+ "\uabf0\uabf1\uabf2\uabf3\uabf4\uabf5\uabf6\uabf7\uabf8\uabf9" +
+ "\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19";
+
+ public static string s_nonNumericsCodepoints =
+ "abcdefghijklmnopqrstuvwxyz" +
+ "\u1369\u136a\u136b\u136c\u136d\u136e\u136f\u1370\u1371\u1372\u1373" +
+ "\u1374\u1375\u1376\u1377\u1378\u1379\u137a\u137b\u137c\u137d";
+
+ public static string s_numericNonDecimalCodepoints =
+ "\u00b2\u00b3\u00b9\u1369\u136a\u136b\u136c\u136d\u136e\u136f\u1370" +
+ "\u1371\u19da\u2070\u2074\u2075\u2076\u2077\u2078\u2079\u2080\u2081" +
+ "\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089\u2460\u2461\u2462" +
+ "\u2463\u2464\u2465\u2466\u2467\u2468\u2474\u2475\u2476\u2477\u2478" +
+ "\u2479\u247a\u247b\u247c\u2488\u2489\u248a\u248b\u248c\u248d\u248e" +
+ "\u248f\u2490\u24ea\u24f5\u24f6\u24f7\u24f8\u24f9\u24fa\u24fb\u24fc" +
+ "\u24fd\u24ff\u2776\u2777\u2778\u2779\u277a\u277b\u277c\u277d\u277e" +
+ "\u2780\u2781\u2782\u2783\u2784\u2785\u2786\u2787\u2788\u278a\u278b" +
+ "\u278c\u278d\u278e\u278f\u2790\u2791\u2792";
+
+ public static int [] s_numericNonDecimalValues = new int []
+ {
+ 2, 3, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 4, 5, 6, 7, 8, 9, 0, 1, 2,
+ 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
+ 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9
+ };
+
+ [Fact]
+ public static void DigitsDecimalTest()
+ {
+ Assert.Equal(s_numericsCodepoints.Length % 10, 0);
+ for (int i=0; i < s_numericsCodepoints.Length; i+= 10)
+ {
+ for (int j=0; j < 10; j++)
+ {
+ Assert.Equal(j, CharUnicodeInfo.GetDecimalDigitValue(s_numericsCodepoints[i + j]));
+ Assert.Equal(j, CharUnicodeInfo.GetDecimalDigitValue(s_numericsCodepoints, i + j));
+ }
+ }
+ }
+
+ [Fact]
+ public static void NegativeDigitsTest()
+ {
+ for (int i=0; i < s_nonNumericsCodepoints.Length; i++)
+ {
+ Assert.Equal(-1, CharUnicodeInfo.GetDecimalDigitValue(s_nonNumericsCodepoints[i]));
+ Assert.Equal(-1, CharUnicodeInfo.GetDecimalDigitValue(s_nonNumericsCodepoints, i));
+ }
+ }
+
+ [Fact]
+ public static void DigitsTest()
+ {
+ Assert.Equal(s_numericNonDecimalCodepoints.Length, s_numericNonDecimalValues.Length);
+ for (int i=0; i < s_numericNonDecimalCodepoints.Length; i++)
+ {
+ Assert.Equal(s_numericNonDecimalValues[i], CharUnicodeInfo.GetDigitValue(s_numericNonDecimalCodepoints[i]));
+ Assert.Equal(s_numericNonDecimalValues[i], CharUnicodeInfo.GetDigitValue(s_numericNonDecimalCodepoints, i));
+ }
+ }
+ }
+}
--- /dev/null
+// 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 CultureNotFoundExceptionTests
+ {
+ [Fact]
+ public void Ctor_String()
+ {
+ string message = "this is a test string";
+ CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(message);
+
+ Assert.Equal(message, cultureNotFoundException.Message);
+ }
+
+ [Fact]
+ public void Ctor_String_Exception()
+ {
+ string message = "this is a test string";
+ Exception innerException = new Exception("inner exception string");
+ CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(message, innerException);
+
+ Assert.Equal(message, cultureNotFoundException.Message);
+ Assert.Same(innerException, cultureNotFoundException.InnerException);
+ }
+
+ [Fact]
+ public void Ctor_String_String()
+ {
+ string paramName = "nameOfParam";
+ string message = "this is a test string";
+ CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(paramName, message);
+
+ Assert.Equal(paramName, cultureNotFoundException.ParamName);
+ Assert.NotEmpty(cultureNotFoundException.Message);
+ }
+
+ [Fact]
+ public void Ctor_String_String_Exception()
+ {
+ string message = "this is a test string";
+ string invalidCultureName = "abcd";
+ Exception innerException = new Exception("inner exception string");
+ CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(message, invalidCultureName, innerException);
+
+ Assert.NotEmpty(cultureNotFoundException.Message);
+ Assert.Equal(invalidCultureName, cultureNotFoundException.InvalidCultureName);
+ Assert.Same(innerException, cultureNotFoundException.InnerException);
+ }
+
+ [Fact]
+ public void Ctor_String_String_String()
+ {
+ string paramName = "nameOfParam";
+ string invalidCultureName = "abcd";
+ string message = "this is a test string";
+ CultureNotFoundException cultureNotFoundException = new CultureNotFoundException(paramName, invalidCultureName, message);
+
+ Assert.Equal(paramName, cultureNotFoundException.ParamName);
+ Assert.Equal(invalidCultureName, cultureNotFoundException.InvalidCultureName);
+ Assert.NotEmpty(cultureNotFoundException.Message);
+ }
+ }
+}
--- /dev/null
+// 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 System.Diagnostics;
+using System.Linq;
+using Xunit;
+
+namespace System.Globalization.Tests
+{
+ public class RegionInfoPropertyTests : RemoteExecutorTestBase
+ {
+ [Theory]
+ [InlineData("US", "US", "US")]
+ [InlineData("IT", "IT", "IT")]
+ [InlineData("IE", "IE", "IE")]
+ [InlineData("SA", "SA", "SA")]
+ [InlineData("JP", "JP", "JP")]
+ [InlineData("CN", "CN", "CN")]
+ [InlineData("TW", "TW", "TW")]
+ [InlineData("en-GB", "GB", "en-GB")]
+ [InlineData("en-IE", "IE", "en-IE")]
+ [InlineData("en-US", "US", "en-US")]
+ [InlineData("zh-CN", "CN", "zh-CN")]
+ public void Ctor(string name, string expectedName, string windowsDesktopName)
+ {
+ var regionInfo = new RegionInfo(name);
+ Assert.True(windowsDesktopName.Equals(regionInfo.Name) || expectedName.Equals(regionInfo.Name));
+ Assert.Equal(regionInfo.Name, regionInfo.ToString());
+ }
+
+ [Fact]
+ public void Ctor_NullName_ThrowsArgumentNullException()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("name", () => new RegionInfo(null));
+ }
+
+ [Fact]
+ public void Ctor_EmptyName_ThrowsArgumentException()
+ {
+ AssertExtensions.Throws<ArgumentException>("name", null, () => new RegionInfo(""));
+ }
+
+ [Theory]
+ [InlineData("no-such-culture")]
+ [InlineData("en")]
+ public void Ctor_InvalidName_ThrowsArgumentException(string name)
+ {
+ AssertExtensions.Throws<ArgumentException>("name", () => new RegionInfo(name));
+ }
+
+ [Fact]
+ public void CurrentRegion()
+ {
+ RemoteInvoke(() =>
+ {
+ CultureInfo.CurrentCulture = new CultureInfo("en-US");
+
+ RegionInfo ri = new RegionInfo(new RegionInfo(CultureInfo.CurrentCulture.Name).TwoLetterISORegionName);
+ Assert.True(RegionInfo.CurrentRegion.Equals(ri) || RegionInfo.CurrentRegion.Equals(new RegionInfo(CultureInfo.CurrentCulture.Name)));
+ Assert.Same(RegionInfo.CurrentRegion, RegionInfo.CurrentRegion);
+
+ return SuccessExitCode;
+ }).Dispose();
+ }
+
+ [Theory]
+ [InlineData("en-US", "United States")]
+ public void DisplayName(string name, string expected)
+ {
+ RemoteInvoke((string _name, string _expected) =>
+ {
+ CultureInfo.CurrentUICulture = new CultureInfo(_name);
+ Assert.Equal(_expected, new RegionInfo(_name).DisplayName);
+
+ return SuccessExitCode;
+ }, name, expected).Dispose();
+ }
+
+ [Theory]
+ [InlineData("GB", "United Kingdom")]
+ [InlineData("SE", "Sverige")]
+ [InlineData("FR", "France")]
+ public void NativeName(string name, string expected)
+ {
+ Assert.Equal(expected, new RegionInfo(name).NativeName);
+ }
+
+ [Theory]
+ [InlineData("en-US", new string[] { "United States" })]
+ [InlineData("US", new string[] { "United States" })]
+ [InlineData("zh-CN", new string[] { "China", "People's Republic of China" })]
+ [InlineData("CN", new string[] { "China", "People's Republic of China" })]
+ public void EnglishName(string name, string[] expected)
+ {
+ string result = new RegionInfo(name).EnglishName;
+ Assert.True(expected.Contains(result));
+ }
+
+ [Theory]
+ [InlineData("en-US", false)]
+ [InlineData("zh-CN", true)]
+ public void IsMetric(string name, bool expected)
+ {
+ Assert.Equal(expected, new RegionInfo(name).IsMetric);
+ }
+
+ [Theory]
+ [InlineData("en-US", "USD")]
+ [InlineData("zh-CN", "CNY")]
+ [InlineData("de-DE", "EUR")]
+ [InlineData("it-IT", "EUR")]
+ public void ISOCurrencySymbol(string name, string expected)
+ {
+ Assert.Equal(expected, new RegionInfo(name).ISOCurrencySymbol);
+ }
+
+ [Theory]
+ [InlineData("en-US", new string[] { "$" })]
+ [InlineData("zh-CN", new string[] { "\u00A5", "\uffe5" })] // \u00A5 is Latin-1 Supplement(Windows), \uffe5 is Halfwidth and Fullwidth Forms(ICU)
+ public void CurrencySymbol(string name, string[] expected)
+ {
+ string result = new RegionInfo(name).CurrencySymbol;
+ Assert.True(expected.Contains(result));
+ }
+
+ [Theory]
+ [InlineData("en-US", "US")]
+ [InlineData("zh-CN", "CN")]
+ [InlineData("de-DE", "DE")]
+ [InlineData("it-IT", "IT")]
+ public void TwoLetterISORegionName(string name, string expected)
+ {
+ Assert.Equal(expected, new RegionInfo(name).TwoLetterISORegionName);
+ }
+
+ public static IEnumerable<object[]> RegionInfo_TestData()
+ {
+ yield return new object[] { 0x409, 244, "US Dollar", "US Dollar", "\u0055\u0053\u0020\u0044\u006f\u006c\u006c\u0061\u0072", "USA", "USA" };
+ yield return new object[] { 0x411, 122, "Japanese Yen", "Japanese Yen", PlatformDetection.IsWindows ? "\u5186" : "\u65e5\u672c\u5186", "JPN", "JPN" };
+ yield return new object[] { 0x804, 45, "Chinese Yuan", "PRC Yuan Renminbi", "\u4eba\u6c11\u5e01", "CHN", "CHN" };
+ yield return new object[] { 0x401, 205, "Saudi Riyal", "Saudi Riyal", PlatformDetection.IsWindows ?
+ "\u0631\u064a\u0627\u0644\u00a0\u0633\u0639\u0648\u062f\u064a" :
+ "\u0631\u064a\u0627\u0644\u0020\u0633\u0639\u0648\u062f\u064a",
+ "SAU", "SAU" };
+ yield return new object[] { 0x412, 134, "South Korean Won", "Korean Won", PlatformDetection.IsWindows ? "\uc6d0" : "\ub300\ud55c\ubbfc\uad6d\u0020\uc6d0", "KOR", "KOR" };
+ yield return new object[] { 0x40d, 117, "Israeli New Shekel", "Israeli New Sheqel",
+ PlatformDetection.IsWindows || PlatformDetection.ICUVersion.Major >= 58 ? "\u05e9\u05e7\u05dc\u0020\u05d7\u05d3\u05e9" : "\u05e9\u05f4\u05d7", "ISR", "ISR" };
+ }
+
+ [Theory]
+ [MemberData(nameof(RegionInfo_TestData))]
+ public void MiscTest(int lcid, int geoId, string currencyEnglishName, string alternativeCurrencyEnglishName, string currencyNativeName, string threeLetterISORegionName, string threeLetterWindowsRegionName)
+ {
+ RegionInfo ri = new RegionInfo(lcid); // create it with lcid
+ Assert.Equal(geoId, ri.GeoId);
+ Assert.True(currencyEnglishName.Equals(ri.CurrencyEnglishName) ||
+ alternativeCurrencyEnglishName.Equals(ri.CurrencyEnglishName), "Wrong currency English Name");
+ Assert.Equal(currencyNativeName, ri.CurrencyNativeName);
+ Assert.Equal(threeLetterISORegionName, ri.ThreeLetterISORegionName);
+ Assert.Equal(threeLetterWindowsRegionName, ri.ThreeLetterWindowsRegionName);
+ }
+
+ public static IEnumerable<object[]> Equals_TestData()
+ {
+ yield return new object[] { new RegionInfo("en-US"), new RegionInfo("en-US"), true };
+ yield return new object[] { new RegionInfo("en-US"), new RegionInfo("en-GB"), false };
+ yield return new object[] { new RegionInfo("en-US"), new RegionInfo("zh-CN"), false };
+ yield return new object[] { new RegionInfo("en-US"), new object(), false };
+ yield return new object[] { new RegionInfo("en-US"), null, false };
+ }
+
+ [Theory]
+ [MemberData(nameof(Equals_TestData))]
+ public void Equals(RegionInfo regionInfo1, object obj, bool expected)
+ {
+ Assert.Equal(expected, regionInfo1.Equals(obj));
+ Assert.Equal(regionInfo1.GetHashCode(), regionInfo1.GetHashCode());
+ if (obj is RegionInfo)
+ {
+ Assert.Equal(expected, regionInfo1.GetHashCode().Equals(obj.GetHashCode()));
+ }
+ }
+ }
+}
--- /dev/null
+// 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 SortVersionMiscTests
+ {
+ [Fact]
+ public void ConstructionsTest()
+ {
+ string guidString = "00000001-57ee-1e5c-00b4-d0000bb1e11e";
+ SortVersion version = new SortVersion(393742, new Guid(guidString));
+ Assert.Equal(393742, version.FullVersion);
+ Assert.Equal(new Guid(guidString), version.SortId);
+ }
+
+ [Fact]
+ public void EquaityTest()
+ {
+ SortVersion version1 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));
+ SortVersion version2 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));
+
+ Assert.Equal(version2, version1);
+ }
+ }
+}
--- /dev/null
+// 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 System.Reflection;
+using Xunit;
+
+namespace System.Globalization.Tests
+{
+ public class StringInfoMiscTests
+ {
+ [Fact]
+ public void Ctor_Default()
+ {
+ StringInfo stringInfo = new StringInfo();
+ Assert.Equal(string.Empty, stringInfo.String);
+ Assert.Equal(0, stringInfo.LengthInTextElements);
+ }
+
+ public static IEnumerable<object[]> Ctor_String_TestData()
+ {
+ yield return new object[] { new string('a', 256), 256 };
+ yield return new object[] { "\u4f00\u302a\ud800\udc00\u4f01", 3 };
+ yield return new object[] { "abcdefgh", 8 };
+ yield return new object[] { "zj\uDBFF\uDFFFlk", 5 };
+ yield return new object[] { "!@#$%^&", 7 };
+ yield return new object[] { "!\u20D1bo\uFE22\u20D1\u20EB|", 4 };
+ yield return new object[] { "1\uDBFF\uDFFF@\uFE22\u20D1\u20EB9", 4 };
+ yield return new object[] { "a\u0300", 1 };
+ yield return new object[] { " ", 3 };
+ yield return new object[] { "", 0 };
+ }
+
+ [Theory]
+ [MemberData(nameof(Ctor_String_TestData))]
+ public void Ctor_String(string value, int lengthInTextElements)
+ {
+ var stringInfo = new StringInfo(value);
+ Assert.Same(value, stringInfo.String);
+ Assert.Equal(lengthInTextElements, stringInfo.LengthInTextElements);
+ }
+
+ [Fact]
+ public void Ctor_NullValue_ThrowsArgumentNullException()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("value", "String", () => new StringInfo(null));
+ }
+
+ [Theory]
+ [InlineData("")]
+ [InlineData("abc")]
+ [InlineData("\uD800\uDC00")]
+ public void String_Set_GetReturnsExpected(string value)
+ {
+ StringInfo stringInfo = new StringInfo();
+ stringInfo.String = value;
+ Assert.Same(value, stringInfo.String);
+ }
+
+ [Fact]
+ public void String_SetNull_ThrowsArgumentNullException()
+ {
+ var stringInfo = new StringInfo();
+ AssertExtensions.Throws<ArgumentNullException>("value", "String", () => stringInfo.String = null);
+ }
+
+ public static IEnumerable<object[]> StringInfo_TestData()
+ {
+ yield return new object[] { "Simple Text", 7, "Text", 4, "Text" };
+ yield return new object[] { "Simple Text", 0, "Simple Text", 6, "Simple" };
+ yield return new object[] { "\uD800\uDC00\uD801\uDC01Left", 2, "Left", 2, "Le" };
+ yield return new object[] { "\uD800\uDC00\uD801\uDC01Left", 1, "\uD801\uDC01Left", 2, "\uD801\uDC01L" };
+ yield return new object[] { "Start\uD800\uDC00\uD801\uDC01Left", 5, "\uD800\uDC00\uD801\uDC01Left", 1, "\uD800\uDC00" };
+ }
+
+ [Theory]
+ [MemberData(nameof(StringInfo_TestData))]
+ public void SubstringTest(string source, int index, string expected, int length, string expectedWithLength)
+ {
+ StringInfo si = new StringInfo(source);
+ Assert.Equal(expected, si.SubstringByTextElements(index));
+ Assert.Equal(expectedWithLength, si.SubstringByTextElements(index, length));
+ }
+
+ [Fact]
+ public void NegativeTest()
+ {
+ string s = "Some String";
+ StringInfo si = new StringInfo(s);
+ StringInfo siEmpty = new StringInfo("");
+
+ Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(-1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(s.Length + 1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => siEmpty.SubstringByTextElements(0));
+
+ Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(-1, 1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(s.Length + 1, 1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => siEmpty.SubstringByTextElements(0, 0));
+ Assert.Throws<ArgumentOutOfRangeException>(() => si.SubstringByTextElements(0, s.Length + 1));
+ }
+
+ public static IEnumerable<object[]> Equals_TestData()
+ {
+ yield return new object[] { new StringInfo(), new StringInfo(), true };
+ yield return new object[] { new StringInfo("stringinfo1"), new StringInfo("stringinfo1"), true };
+ yield return new object[] { new StringInfo("stringinfo1"), new StringInfo("stringinfo2"), false };
+ yield return new object[] { new StringInfo("stringinfo1"), "stringinfo1", false };
+ yield return new object[] { new StringInfo("stringinfo1"), 123, false };
+ yield return new object[] { new StringInfo("stringinfo1"), null, false };
+ }
+
+ [Theory]
+ [MemberData(nameof(Equals_TestData))]
+ public void Equals(StringInfo stringInfo, object value, bool expected)
+ {
+ Assert.Equal(expected, stringInfo.Equals(value));
+ if (value is StringInfo)
+ {
+ Assert.Equal(expected, stringInfo.GetHashCode().Equals(value.GetHashCode()));
+ }
+ }
+
+ public static IEnumerable<object[]> GetNextTextElement_TestData()
+ {
+ yield return new object[] { "", 0, "" }; // Empty string
+ yield return new object[] { "Hello", 5, "" }; // Index = string.Length
+
+ // Surrogate pair
+ yield return new object[] { "\uDBFF\uDFFFabcde", 0, "\uDBFF\uDFFF" };
+ yield return new object[] { "ef45-;\uDBFF\uDFFFabcde", 6, "\uDBFF\uDFFF" };
+
+ yield return new object[] { "a\u20D1abcde", 0, "a\u20D1" }; // Combining character or non spacing mark
+
+ // Base character with several combining characters
+ yield return new object[] { "z\uFE22\u20D1\u20EBabcde", 0, "z\uFE22\u20D1\u20EB" };
+ yield return new object[] { "az\uFE22\u20D1\u20EBabcde", 1, "z\uFE22\u20D1\u20EB" };
+
+ yield return new object[] { "13229^a\u20D1abcde", 6, "a\u20D1" }; // Combining characters
+
+ // Single base and combining character
+ yield return new object[] { "a\u0300", 0, "a\u0300" };
+ yield return new object[] { "a\u0300", 1, "\u0300" };
+
+ // Lone combining character
+ yield return new object[] { "\u0300\u0300", 0, "\u0300" };
+ yield return new object[] { "\u0300\u0300", 1, "\u0300" };
+ }
+
+ [Theory]
+ [MemberData(nameof(GetNextTextElement_TestData))]
+ public void GetNextTextElement(string str, int index, string expected)
+ {
+ if (index == 0)
+ {
+ Assert.Equal(expected, StringInfo.GetNextTextElement(str));
+ }
+ Assert.Equal(expected, StringInfo.GetNextTextElement(str, index));
+ }
+
+ [Fact]
+ public void GetNextTextElement_Invalid()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetNextTextElement(null)); // Str is null
+ AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetNextTextElement(null, 0)); // Str is null
+
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetNextTextElement("abc", -1)); // Index < 0
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetNextTextElement("abc", 4)); // Index > str.Length
+ }
+
+ public static IEnumerable<object[]> GetTextElementEnumerator_TestData()
+ {
+ yield return new object[] { "", 0, new string[0] }; // Empty string
+ yield return new object[] { "Hello", 5, new string[0] }; // Index = string.Length
+
+ // Surrogate pair
+ yield return new object[] { "s\uDBFF\uDFFF$", 0, new string[] { "s", "\uDBFF\uDFFF", "$" } };
+ yield return new object[] { "s\uDBFF\uDFFF$", 1, new string[] { "\uDBFF\uDFFF", "$" } };
+
+ // Combining characters
+ yield return new object[] { "13229^a\u20D1a", 6, new string[] { "a\u20D1", "a" } };
+ yield return new object[] { "13229^a\u20D1a", 0, new string[] { "1", "3", "2", "2", "9", "^", "a\u20D1", "a" } };
+
+ // Single base and combining character
+ yield return new object[] { "a\u0300", 0, new string[] { "a\u0300" } };
+ yield return new object[] { "a\u0300", 1, new string[] { "\u0300" } };
+
+ // Lone combining character
+ yield return new object[] { "\u0300\u0300", 0, new string[] { "\u0300", "\u0300" } };
+ }
+
+ [Theory]
+ [MemberData(nameof(GetTextElementEnumerator_TestData))]
+ public void GetTextElementEnumerator(string str, int index, string[] expected)
+ {
+ if (index == 0)
+ {
+ TextElementEnumerator basicEnumerator = StringInfo.GetTextElementEnumerator(str);
+ int basicCounter = 0;
+ while (basicEnumerator.MoveNext())
+ {
+ Assert.Equal(expected[basicCounter], basicEnumerator.Current.ToString());
+ basicCounter++;
+ }
+ Assert.Equal(expected.Length, basicCounter);
+ }
+ TextElementEnumerator indexedEnumerator = StringInfo.GetTextElementEnumerator(str, index);
+ int indexedCounter = 0;
+ while (indexedEnumerator.MoveNext())
+ {
+ Assert.Equal(expected[indexedCounter], indexedEnumerator.Current.ToString());
+ indexedCounter++;
+ }
+ Assert.Equal(expected.Length, indexedCounter);
+ }
+
+ [Fact]
+ public void GetTextElementEnumerator_Invalid()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetTextElementEnumerator(null)); // Str is null
+ AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.GetTextElementEnumerator(null, 0)); // Str is null
+
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetTextElementEnumerator("abc", -1)); // Index < 0
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => StringInfo.GetTextElementEnumerator("abc", 4)); // Index > str.Length
+ }
+
+ public static IEnumerable<object[]> ParseCombiningCharacters_TestData()
+ {
+ yield return new object[] { "\u4f00\u302a\ud800\udc00\u4f01", new int[] { 0, 2, 4 } };
+ yield return new object[] { "abcdefgh", new int[] { 0, 1, 2, 3, 4, 5, 6, 7 } };
+ yield return new object[] { "!@#$%^&", new int[] { 0, 1, 2, 3, 4, 5, 6 } };
+ yield return new object[] { "!\u20D1bo\uFE22\u20D1\u20EB|", new int[] { 0, 2, 3, 7 } };
+ yield return new object[] { "1\uDBFF\uDFFF@\uFE22\u20D1\u20EB9", new int[] { 0, 1, 3, 7 } };
+ yield return new object[] { "a\u0300", new int[] { 0 } };
+ yield return new object[] { "\u0300\u0300", new int[] { 0, 1 } };
+ yield return new object[] { " ", new int[] { 0, 1, 2 } };
+ yield return new object[] { "", new int[0] };
+
+ // Invalid Unicode
+ yield return new object[] { "\u0000\uFFFFa", new int[] { 0, 1, 2 } }; // Control chars
+ yield return new object[] { "\uD800a", new int[] { 0, 1 } }; // Unmatched high surrogate
+ yield return new object[] { "\uDC00a", new int[] { 0, 1 } }; // Unmatched low surrogate
+ yield return new object[] { "\u00ADa", new int[] { 0, 1 } }; // Format character
+
+ yield return new object[] { "\u0000\u0300\uFFFF\u0300", new int[] { 0, 1, 2, 3 } }; // Control chars + combining char
+ yield return new object[] { "\uD800\u0300", new int[] { 0, 1 } }; // Unmatched high surrogate + combining char
+ yield return new object[] { "\uDC00\u0300", new int[] { 0, 1 } }; // Unmatched low surrogate + combing char
+ yield return new object[] { "\u00AD\u0300", new int[] { 0, 1 } }; // Format character + combining char
+
+ yield return new object[] { "\u0300\u0300", new int[] { 0, 1 } }; // Two combining chars
+ }
+
+ [Theory]
+ [MemberData(nameof(ParseCombiningCharacters_TestData))]
+ public void ParseCombiningCharacters(string str, int[] expected)
+ {
+ Assert.Equal(expected, StringInfo.ParseCombiningCharacters(str));
+ }
+
+ [Fact]
+ public void ParseCombiningCharacters_Null_ThrowsArgumentNullException()
+ {
+ AssertExtensions.Throws<ArgumentNullException>("str", () => StringInfo.ParseCombiningCharacters(null)); // Str is null
+ }
+ }
+}
--- /dev/null
+// 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 TextElementEnumeratorTests
+ {
+ public static IEnumerable<object[]> Enumerate_TestData()
+ {
+ yield return new object[] { "", new string[] { "" }, new int[0] };
+ yield return new object[] { "Hello", new string[] { "H", "e", "l", "l", "o" }, new int[] { 0, 1, 2, 3, 4 } };
+
+ // Creates and initializes a string containing the following:
+ // - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
+ // - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
+ // - a base character (the ligature "")
+ yield return new object[] { "\uD800\uDC00\u0061\u0300\u00C6", new string[] { "\uD800\uDC00", "\uD800\uDC00", "\u0061\u0300", "\u0061\u0300", "\u00C6" }, new int[] { 0, 2, 4 } };
+ }
+
+ [Theory]
+ [MemberData(nameof(Enumerate_TestData))]
+ public void Enumerate(string str, string[] expectedElements, int[] expectedElementIndices)
+ {
+ TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(str);
+ for (int i = 0; i < 2; i++)
+ {
+ int counter = 0;
+ while (enumerator.MoveNext())
+ {
+ string currentTextElement = enumerator.GetTextElement();
+ Assert.Equal(expectedElements[enumerator.ElementIndex], currentTextElement);
+ Assert.Equal(currentTextElement, enumerator.Current);
+
+ Assert.Equal(expectedElementIndices[counter], enumerator.ElementIndex);
+ counter++;
+ }
+ Assert.Equal(expectedElementIndices.Length, counter);
+
+ enumerator.Reset();
+ }
+ }
+
+ [Fact]
+ public void AccessingMembersBeforeEnumeration_ThrowsInvalidOperationException()
+ {
+ TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");
+
+ // Cannot access Current, ElementIndex or GetTextElement() before the enumerator has started
+ Assert.Throws<InvalidOperationException>(() => enumerator.Current);
+ Assert.Throws<InvalidOperationException>(() => enumerator.ElementIndex);
+ Assert.Throws<InvalidOperationException>(() => enumerator.GetTextElement());
+ }
+
+ [Fact]
+ public void AccessingMembersAfterEnumeration_ThrowsInvalidOperationException()
+ {
+ TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");
+
+ // Cannot access Current or GetTextElement() after the enumerator has finished
+ // enumerating, but ElementIndex does not
+ while (enumerator.MoveNext()) ;
+ Assert.Throws<InvalidOperationException>(() => enumerator.Current);
+ Assert.Equal(3, enumerator.ElementIndex);
+ Assert.Throws<InvalidOperationException>(() => enumerator.GetTextElement());
+ }
+
+ [Fact]
+ public void AccessingMembersAfterReset_ThrowsInvalidOperationException()
+ {
+ TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");
+ enumerator.MoveNext();
+
+ // Cannot access Current, ElementIndex or GetTextElement() after the enumerator has been reset
+ enumerator.Reset();
+ Assert.Throws<InvalidOperationException>(() => enumerator.Current);
+ Assert.Throws<InvalidOperationException>(() => enumerator.ElementIndex);
+ Assert.Throws<InvalidOperationException>(() => enumerator.GetTextElement());
+ }
+ }
+}
--- /dev/null
+// 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 System.Reflection;
+using Xunit;
+
+namespace System.Globalization.Tests
+{
+ public class TextInfoMiscTests
+ {
+ public static IEnumerable<object[]> TextInfo_TestData()
+ {
+ yield return new object[] { "", 0x7f, 0x4e4, 0x25, 0x2710, 0x1b5, false };
+ yield return new object[] { "en-US", 0x409, 0x4e4, 0x25, 0x2710, 0x1b5, false };
+ yield return new object[] { "ja-JP", 0x411, 0x3a4, 0x4f42, 0x2711, 0x3a4, false };
+ yield return new object[] { "zh-CN", 0x804, 0x3a8, 0x1f4, 0x2718, 0x3a8, false };
+ yield return new object[] { "ar-SA", 0x401, 0x4e8, 0x4fc4, 0x2714, 0x2d0, true };
+ yield return new object[] { "ko-KR", 0x412, 0x3b5, 0x5161, 0x2713, 0x3b5, false };
+ yield return new object[] { "he-IL", 0x40d, 0x4e7, 0x1f4, 0x2715, 0x35e, true };
+ }
+
+ [Theory]
+ [MemberData(nameof(TextInfo_TestData))]
+ public void MiscTest(string cultureName, int lcid, int ansiCodePage, int ebcdiCCodePage, int macCodePage, int oemCodePage, bool isRightToLeft)
+ {
+ TextInfo ti = CultureInfo.GetCultureInfo(cultureName).TextInfo;
+ Assert.Equal(lcid, ti.LCID);
+ Assert.Equal(ansiCodePage, ti.ANSICodePage);
+ Assert.Equal(ebcdiCCodePage, ti.EBCDICCodePage);
+ Assert.Equal(macCodePage, ti.MacCodePage);
+ Assert.Equal(oemCodePage, ti.OEMCodePage);
+ Assert.Equal(isRightToLeft, ti.IsRightToLeft);
+ }
+
+ [Fact]
+ public void ReadOnlyTest()
+ {
+ TextInfo ti = CultureInfo.GetCultureInfo("en-US").TextInfo;
+ Assert.True(ti.IsReadOnly, "IsReadOnly should be true with cached TextInfo object");
+
+ ti = (TextInfo) ti.Clone();
+ Assert.False(ti.IsReadOnly, "IsReadOnly should be false with cloned TextInfo object");
+
+ ti = TextInfo.ReadOnly(ti);
+ Assert.True(ti.IsReadOnly, "IsReadOnly should be true with created read-nly TextInfo object");
+ }
+
+ [Fact]
+ public void ToTitleCaseTest()
+ {
+ TextInfo ti = CultureInfo.GetCultureInfo("en-US").TextInfo;
+ Assert.Equal("A Tale Of Two Cities", ti.ToTitleCase("a tale of two cities"));
+ Assert.Equal("Growl To The Rescue", ti.ToTitleCase("gROWL to the rescue"));
+ Assert.Equal("Inside The US Government", ti.ToTitleCase("inside the US government"));
+ Assert.Equal("Sports And MLB Baseball", ti.ToTitleCase("sports and MLB baseball"));
+ Assert.Equal("The Return Of Sherlock Holmes", ti.ToTitleCase("The Return of Sherlock Holmes"));
+ Assert.Equal("UNICEF And Children", ti.ToTitleCase("UNICEF and children"));
+
+ AssertExtensions.Throws<ArgumentNullException>("str", () => ti.ToTitleCase(null));
+ }
+
+ public static IEnumerable<object[]> DutchTitleCaseInfo_TestData()
+ {
+ yield return new object[] { "nl-NL", "IJ IJ IJ IJ", "ij iJ Ij IJ" };
+ yield return new object[] { "nl-be", "IJzeren Eigenschappen", "ijzeren eigenschappen" };
+ yield return new object[] { "NL-NL", "Lake IJssel", "lake iJssel" };
+ yield return new object[] { "NL-BE", "Boba N' IJango Fett PEW PEW", "Boba n' Ijango fett PEW PEW" };
+ yield return new object[] { "en-us", "Ijill And Ijack", "ijill and ijack" };
+ yield return new object[] { "de-DE", "Ij Ij IJ Ij", "ij ij IJ ij" };
+ yield return new object[] { "he-il", "Ijon't Know What Will Happen.", "Ijon't know what Will happen." };
+ }
+
+ [Theory]
+ [MemberData(nameof(DutchTitleCaseInfo_TestData))]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Desktop Framework hasn't received the fix for dotnet/corefx#16770 yet.")]
+ public void ToTitleCaseDutchTest(string cultureName, string expected, string actual)
+ {
+ TextInfo ti = CultureInfo.GetCultureInfo(cultureName).TextInfo;
+ Assert.Equal(expected, ti.ToTitleCase(actual));
+ }
+
+ [Theory]
+ public static IEnumerable<object[]> CultureName_TestData()
+ {
+ yield return new object[] { CultureInfo.InvariantCulture.TextInfo, "" };
+ yield return new object[] { new CultureInfo("").TextInfo, "" };
+ yield return new object[] { new CultureInfo("en-US").TextInfo, "en-US" };
+ yield return new object[] { new CultureInfo("fr-FR").TextInfo, "fr-FR" };
+ yield return new object[] { new CultureInfo("EN-us").TextInfo, "en-US" };
+ yield return new object[] { new CultureInfo("FR-fr").TextInfo, "fr-FR" };
+ }
+
+ [Theory]
+ [MemberData(nameof(CultureName_TestData))]
+ public void CultureName(TextInfo textInfo, string expected)
+ {
+ Assert.Equal(expected, textInfo.CultureName);
+ }
+
+ public static IEnumerable<object[]> IsReadOnly_TestData()
+ {
+ yield return new object[] { CultureInfo.ReadOnly(new CultureInfo("en-US")).TextInfo, true };
+ yield return new object[] { CultureInfo.InvariantCulture.TextInfo, true };
+ yield return new object[] { new CultureInfo("").TextInfo, false };
+ yield return new object[] { new CultureInfo("en-US").TextInfo, false };
+ yield return new object[] { new CultureInfo("fr-FR").TextInfo, false };
+ }
+
+ [Theory]
+ [MemberData(nameof(IsReadOnly_TestData))]
+ public void IsReadOnly(TextInfo textInfo, bool expected)
+ {
+ Assert.Equal(expected, textInfo.IsReadOnly);
+ }
+
+ [Theory]
+ [InlineData("en-US", false)]
+ [InlineData("ar", true)]
+ public void IsRightToLeft(string name, bool expected)
+ {
+ Assert.Equal(expected, new CultureInfo(name).TextInfo.IsRightToLeft);
+ }
+
+ [Fact]
+ public void ListSeparator_EnUS()
+ {
+ Assert.NotEqual(string.Empty, new CultureInfo("en-US").TextInfo.ListSeparator);
+ }
+
+ [Theory]
+ [InlineData("")]
+ [InlineData(" ")]
+ [InlineData("abcdef")]
+ public void ListSeparator_Set(string newListSeparator)
+ {
+ TextInfo textInfo = new CultureInfo("en-US").TextInfo;
+ textInfo.ListSeparator = newListSeparator;
+ Assert.Equal(newListSeparator, textInfo.ListSeparator);
+ }
+
+ [Fact]
+ public void ListSeparator_Set_Invalid()
+ {
+ Assert.Throws<InvalidOperationException>(() => CultureInfo.InvariantCulture.TextInfo.ListSeparator = "");
+ AssertExtensions.Throws<ArgumentNullException>("value", () => new CultureInfo("en-US").TextInfo.ListSeparator = null);
+ }
+
+ public static IEnumerable<object[]> Equals_TestData()
+ {
+ yield return new object[] { CultureInfo.InvariantCulture.TextInfo, CultureInfo.InvariantCulture.TextInfo, true };
+ yield return new object[] { CultureInfo.InvariantCulture.TextInfo, new CultureInfo("").TextInfo, true };
+ yield return new object[] { CultureInfo.InvariantCulture.TextInfo, new CultureInfo("en-US"), false };
+
+ yield return new object[] { new CultureInfo("en-US").TextInfo, new CultureInfo("en-US").TextInfo, true };
+ yield return new object[] { new CultureInfo("en-US").TextInfo, new CultureInfo("fr-FR").TextInfo, false };
+
+ yield return new object[] { new CultureInfo("en-US").TextInfo, null, false };
+ yield return new object[] { new CultureInfo("en-US").TextInfo, new object(), false };
+ yield return new object[] { new CultureInfo("en-US").TextInfo, 123, false };
+ yield return new object[] { new CultureInfo("en-US").TextInfo, "en-US", false };
+
+ }
+
+ [Theory]
+ [MemberData(nameof(Equals_TestData))]
+ public void Equals(TextInfo textInfo, object obj, bool expected)
+ {
+ Assert.Equal(expected, textInfo.Equals(obj));
+ if (obj is TextInfo)
+ {
+ Assert.Equal(expected, textInfo.GetHashCode().Equals(obj.GetHashCode()));
+ }
+ }
+
+ private static readonly string [] s_cultureNames = new string[] { "", "en-US", "fr", "fr-FR" };
+
+ // ToLower_TestData_netcore has the data which is specific to netcore framework
+ public static IEnumerable<object[]> ToLower_TestData_netcore()
+ {
+ foreach (string cultureName in s_cultureNames)
+ {
+ // DESERT CAPITAL LETTER LONG I has a lower case variant (but not on Windows 7).
+ yield return new object[] { cultureName, "\U00010400", PlatformDetection.IsWindows7 ? "\U00010400" : "\U00010428" };
+ }
+ }
+
+ public static IEnumerable<object[]> ToLower_TestData()
+ {
+ foreach (string cultureName in s_cultureNames)
+ {
+ yield return new object[] { cultureName, "", "" };
+
+ yield return new object[] { cultureName, "A", "a" };
+ yield return new object[] { cultureName, "a", "a" };
+ yield return new object[] { cultureName, "ABC", "abc" };
+ yield return new object[] { cultureName, "abc", "abc" };
+
+ yield return new object[] { cultureName, "1", "1" };
+ yield return new object[] { cultureName, "123", "123" };
+ yield return new object[] { cultureName, "!", "!" };
+
+ yield return new object[] { cultureName, "HELLOWOR!LD123", "hellowor!ld123" };
+ yield return new object[] { cultureName, "HelloWor!ld123", "hellowor!ld123" };
+ yield return new object[] { cultureName, "Hello\n\0World\u0009!", "hello\n\0world\t!" };
+
+ yield return new object[] { cultureName, "THIS IS A LONGER TEST CASE", "this is a longer test case" };
+ yield return new object[] { cultureName, "this Is A LONGER mIXEd casE test case", "this is a longer mixed case test case" };
+
+ yield return new object[] { cultureName, "THIS \t hAs \t SOMe \t tabs", "this \t has \t some \t tabs" };
+ yield return new object[] { cultureName, "EMBEDDED\0NuLL\0Byte\0", "embedded\0null\0byte\0" };
+
+ // LATIN CAPITAL LETTER O WITH ACUTE, which has a lower case variant.
+ yield return new object[] { cultureName, "\u00D3", "\u00F3" };
+
+ // SNOWMAN, which does not have a lower case variant.
+ yield return new object[] { cultureName, "\u2603", "\u2603" };
+
+ // RAINBOW (outside the BMP and does not case)
+ yield return new object[] { cultureName, "\U0001F308", "\U0001F308" };
+
+ // Unicode defines some codepoints which expand into multiple codepoints
+ // when cased (see SpecialCasing.txt from UNIDATA for some examples). We have never done
+ // these sorts of expansions, since it would cause string lengths to change when cased,
+ // which is non-intuitive. In addition, there are some context sensitive mappings which
+ // we also don't preform.
+ // Greek Capital Letter Sigma (does not to case to U+03C2 with "final sigma" rule).
+ yield return new object[] { cultureName, "\u03A3", "\u03C3" };
+ }
+
+ foreach (string cultureName in new string[] { "tr", "tr-TR", "az", "az-Latn-AZ" })
+ {
+ yield return new object[] { cultureName, "\u0130", "i" };
+ yield return new object[] { cultureName, "i", "i" };
+ yield return new object[] { cultureName, "I", "\u0131" };
+ yield return new object[] { cultureName, "HI!", "h\u0131!" };
+ yield return new object[] { cultureName, "HI\n\0H\u0130\t!", "h\u0131\n\0hi\u0009!" };
+ }
+
+ // ICU has special tailoring for the en-US-POSIX locale which treats "i" and "I" as different letters
+ // instead of two letters with a case difference during collation. Make sure this doesn't confuse our
+ // casing implementation, which uses collation to understand if we need to do Turkish casing or not.
+ if (!PlatformDetection.IsWindows)
+ {
+ yield return new object[] { "en-US-POSIX", "I", "i" };
+ }
+ }
+
+ public void TestToLower(string name, string str, string expected)
+ {
+ Assert.Equal(expected, new CultureInfo(name).TextInfo.ToLower(str));
+ if (str.Length == 1)
+ {
+ Assert.Equal(expected[0], new CultureInfo(name).TextInfo.ToLower(str[0]));
+ }
+ }
+
+ [Theory]
+ [MemberData(nameof(ToLower_TestData))]
+ public void ToLower(string name, string str, string expected)
+ {
+ TestToLower(name, str, expected);
+ }
+
+ [Theory]
+ [MemberData(nameof(ToLower_TestData_netcore))]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
+ public void ToLower_Netcore(string name, string str, string expected)
+ {
+ TestToLower(name, str, expected);
+ }
+
+ [Fact]
+ public void ToLower_InvalidSurrogates()
+ {
+ // Invalid UTF-16 in a string (mismatched surrogate pairs) should be unchanged.
+ foreach (string cultureName in new string[] { "", "en-US", "fr" })
+ {
+ ToLower(cultureName, "BE CAREFUL, \uD83C\uD83C, THIS ONE IS TRICKY", "be careful, \uD83C\uD83C, this one is tricky");
+ ToLower(cultureName, "BE CAREFUL, \uDF08\uD83C, THIS ONE IS TRICKY", "be careful, \uDF08\uD83C, this one is tricky");
+ ToLower(cultureName, "BE CAREFUL, \uDF08\uDF08, THIS ONE IS TRICKY", "be careful, \uDF08\uDF08, this one is tricky");
+ }
+ }
+
+ [Theory]
+ [InlineData("")]
+ [InlineData("en-US")]
+ [InlineData("fr")]
+ public void ToLower_Null_ThrowsArgumentNullException(string cultureName)
+ {
+ AssertExtensions.Throws<ArgumentNullException>("str", () => new CultureInfo(cultureName).TextInfo.ToLower(null));
+ }
+
+ // ToUpper_TestData_netcore has the data which is specific to netcore framework
+ public static IEnumerable<object[]> ToUpper_TestData_netcore()
+ {
+ foreach (string cultureName in s_cultureNames)
+ {
+ // DESERT SMALL LETTER LONG I has an upper case variant (but not on Windows 7).
+ yield return new object[] { cultureName, "\U00010428", PlatformDetection.IsWindows7 ? "\U00010428" : "\U00010400" };
+ }
+ }
+
+ public static IEnumerable<object[]> ToUpper_TestData()
+ {
+ foreach (string cultureName in s_cultureNames)
+ {
+ yield return new object[] { cultureName, "", "" };
+
+ yield return new object[] { cultureName, "a", "A" };
+ yield return new object[] { cultureName, "abc", "ABC" };
+ yield return new object[] { cultureName, "A", "A" };
+ yield return new object[] { cultureName, "ABC", "ABC" };
+
+ yield return new object[] { cultureName, "1", "1" };
+ yield return new object[] { cultureName, "123", "123" };
+ yield return new object[] { cultureName, "!", "!" };
+
+ yield return new object[] { cultureName, "HelloWor!ld123", "HELLOWOR!LD123" };
+ yield return new object[] { cultureName, "HELLOWOR!LD123", "HELLOWOR!LD123" };
+ yield return new object[] { cultureName, "Hello\n\0World\u0009!", "HELLO\n\0WORLD\t!" };
+
+ yield return new object[] { cultureName, "this is a longer test case", "THIS IS A LONGER TEST CASE" };
+ yield return new object[] { cultureName, "this Is A LONGER mIXEd casE test case", "THIS IS A LONGER MIXED CASE TEST CASE" };
+ yield return new object[] { cultureName, "this \t HaS \t somE \t TABS", "THIS \t HAS \t SOME \t TABS" };
+
+ yield return new object[] { cultureName, "embedded\0NuLL\0Byte\0", "EMBEDDED\0NULL\0BYTE\0" };
+
+ // LATIN SMALL LETTER O WITH ACUTE, which has an upper case variant.
+ yield return new object[] { cultureName, "\u00F3", "\u00D3" };
+
+ // SNOWMAN, which does not have an upper case variant.
+ yield return new object[] { cultureName, "\u2603", "\u2603" };
+
+ // RAINBOW (outside the BMP and does not case)
+ yield return new object[] { cultureName, "\U0001F308", "\U0001F308" };
+
+ // Unicode defines some codepoints which expand into multiple codepoints
+ // when cased (see SpecialCasing.txt from UNIDATA for some examples). We have never done
+ // these sorts of expansions, since it would cause string lengths to change when cased,
+ // which is non-intuitive. In addition, there are some context sensitive mappings which
+ // we also don't preform.
+ // es-zed does not case to SS when uppercased.
+ yield return new object[] { cultureName, "\u00DF", "\u00DF" };
+
+ // Ligatures do not expand when cased.
+ yield return new object[] { cultureName, "\uFB00", "\uFB00" };
+
+ // Precomposed character with no uppercase variant, we don't want to "decompose" this
+ // as part of casing.
+ yield return new object[] { cultureName, "\u0149", "\u0149" };
+ }
+
+ // Turkish i
+ foreach (string cultureName in new string[] { "tr", "tr-TR", "az", "az-Latn-AZ" })
+ {
+ yield return new object[] { cultureName, "i", "\u0130" };
+ yield return new object[] { cultureName, "\u0130", "\u0130" };
+ yield return new object[] { cultureName, "\u0131", "I" };
+ yield return new object[] { cultureName, "I", "I" };
+ yield return new object[] { cultureName, "H\u0131\n\0Hi\u0009!", "HI\n\0H\u0130\t!" };
+ }
+
+ // ICU has special tailoring for the en-US-POSIX locale which treats "i" and "I" as different letters
+ // instead of two letters with a case difference during collation. Make sure this doesn't confuse our
+ // casing implementation, which uses collation to understand if we need to do Turkish casing or not.
+ if (!PlatformDetection.IsWindows)
+ {
+ yield return new object[] { "en-US-POSIX", "i", "I" };
+ }
+ }
+
+ public void TestToUpper(string name, string str, string expected)
+ {
+ Assert.Equal(expected, new CultureInfo(name).TextInfo.ToUpper(str));
+ if (str.Length == 1)
+ {
+ Assert.Equal(expected[0], new CultureInfo(name).TextInfo.ToUpper(str[0]));
+ }
+ }
+
+ [Theory]
+ [MemberData(nameof(ToUpper_TestData))]
+ public void ToUpper(string name, string str, string expected)
+ {
+ TestToUpper(name, str, expected);
+ }
+
+ [Theory]
+ [MemberData(nameof(ToUpper_TestData_netcore))]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
+ public void ToUpper_netcore(string name, string str, string expected)
+ {
+ TestToUpper(name, str, expected);
+ }
+
+ [Fact]
+ public void ToUpper_InvalidSurrogates()
+ {
+ // Invalid UTF-16 in a string (mismatched surrogate pairs) should be unchanged.
+ foreach (string cultureName in new string[] { "", "en-US", "fr"})
+ {
+ ToUpper(cultureName, "be careful, \uD83C\uD83C, this one is tricky", "BE CAREFUL, \uD83C\uD83C, THIS ONE IS TRICKY");
+ ToUpper(cultureName, "be careful, \uDF08\uD83C, this one is tricky", "BE CAREFUL, \uDF08\uD83C, THIS ONE IS TRICKY");
+ ToUpper(cultureName, "be careful, \uDF08\uDF08, this one is tricky", "BE CAREFUL, \uDF08\uDF08, THIS ONE IS TRICKY");
+ }
+ }
+
+ [Theory]
+ [InlineData("")]
+ [InlineData("en-US")]
+ [InlineData("fr")]
+ public void ToUpper_Null_ThrowsArgumentNullException(string cultureName)
+ {
+ AssertExtensions.Throws<ArgumentNullException>("str", () => new CultureInfo(cultureName).TextInfo.ToUpper(null));
+ }
+
+ [Theory]
+ [InlineData("en-US", "TextInfo - en-US")]
+ [InlineData("fr-FR", "TextInfo - fr-FR")]
+ [InlineData("", "TextInfo - ")]
+ public void ToString(string name, string expected)
+ {
+ Assert.Equal(expected, new CultureInfo(name).TextInfo.ToString());
+ }
+ }
+}
--- /dev/null
+// 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.Globalization;
+using Xunit;
+
+namespace System.Globalization.Tests
+{
+ public class UnicodeCategoryTests
+ {
+ [Theory]
+ [InlineData(UnicodeCategory.UppercaseLetter, 0)]
+ [InlineData(UnicodeCategory.LowercaseLetter, 1)]
+ [InlineData(UnicodeCategory.TitlecaseLetter, 2)]
+ [InlineData(UnicodeCategory.ModifierLetter, 3)]
+ [InlineData(UnicodeCategory.OtherLetter, 4)]
+ [InlineData(UnicodeCategory.NonSpacingMark, 5)]
+ [InlineData(UnicodeCategory.SpacingCombiningMark, 6)]
+ [InlineData(UnicodeCategory.EnclosingMark, 7)]
+ [InlineData(UnicodeCategory.DecimalDigitNumber, 8)]
+ [InlineData(UnicodeCategory.LetterNumber, 9)]
+ [InlineData(UnicodeCategory.OtherNumber, 10)]
+ [InlineData(UnicodeCategory.SpaceSeparator, 11)]
+ [InlineData(UnicodeCategory.LineSeparator, 12)]
+ [InlineData(UnicodeCategory.ParagraphSeparator, 13)]
+ [InlineData(UnicodeCategory.Control, 14)]
+ [InlineData(UnicodeCategory.Format, 15)]
+ [InlineData(UnicodeCategory.Surrogate, 16)]
+ [InlineData(UnicodeCategory.PrivateUse, 17)]
+ [InlineData(UnicodeCategory.ConnectorPunctuation, 18)]
+ [InlineData(UnicodeCategory.DashPunctuation, 19)]
+ [InlineData(UnicodeCategory.OpenPunctuation, 20)]
+ [InlineData(UnicodeCategory.ClosePunctuation, 21)]
+ [InlineData(UnicodeCategory.InitialQuotePunctuation, 22)]
+ [InlineData(UnicodeCategory.FinalQuotePunctuation, 23)]
+ [InlineData(UnicodeCategory.OtherPunctuation, 24)]
+ [InlineData(UnicodeCategory.MathSymbol, 25)]
+ [InlineData(UnicodeCategory.CurrencySymbol, 26)]
+ [InlineData(UnicodeCategory.ModifierSymbol, 27)]
+ [InlineData(UnicodeCategory.OtherSymbol, 28)]
+ [InlineData(UnicodeCategory.OtherNotAssigned, 29)]
+ public void Cases(UnicodeCategory category, int expected)
+ {
+ Assert.Equal(expected, (int)category);
+ }
+ }
+}
+++ /dev/null
-// 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 TextElementEnumeratorTests
- {
- public static IEnumerable<object[]> Enumerate_TestData()
- {
- yield return new object[] { "", new string[] { "" }, new int[0] };
- yield return new object[] { "Hello", new string[] { "H", "e", "l", "l", "o" }, new int[] { 0, 1, 2, 3, 4 } };
-
- // Creates and initializes a string containing the following:
- // - a surrogate pair (high surrogate U+D800 and low surrogate U+DC00)
- // - a combining character sequence (the Latin small letter "a" followed by the combining grave accent)
- // - a base character (the ligature "")
- yield return new object[] { "\uD800\uDC00\u0061\u0300\u00C6", new string[] { "\uD800\uDC00", "\uD800\uDC00", "\u0061\u0300", "\u0061\u0300", "\u00C6" }, new int[] { 0, 2, 4 } };
- }
-
- [Theory]
- [MemberData(nameof(Enumerate_TestData))]
- public void Enumerate(string str, string[] expectedElements, int[] expectedElementIndices)
- {
- TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(str);
- for (int i = 0; i < 2; i++)
- {
- int counter = 0;
- while (enumerator.MoveNext())
- {
- string currentTextElement = enumerator.GetTextElement();
- Assert.Equal(expectedElements[enumerator.ElementIndex], currentTextElement);
- Assert.Equal(currentTextElement, enumerator.Current);
-
- Assert.Equal(expectedElementIndices[counter], enumerator.ElementIndex);
- counter++;
- }
- Assert.Equal(expectedElementIndices.Length, counter);
-
- enumerator.Reset();
- }
- }
-
- [Fact]
- public void AccessingMembersBeforeEnumeration_ThrowsInvalidOperationException()
- {
- TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");
-
- // Cannot access Current, ElementIndex or GetTextElement() before the enumerator has started
- Assert.Throws<InvalidOperationException>(() => enumerator.Current);
- Assert.Throws<InvalidOperationException>(() => enumerator.ElementIndex);
- Assert.Throws<InvalidOperationException>(() => enumerator.GetTextElement());
- }
-
- [Fact]
- public void AccessingMembersAfterEnumeration_ThrowsInvalidOperationException()
- {
- TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");
-
- // Cannot access Current or GetTextElement() after the enumerator has finished
- // enumerating, but ElementIndex does not
- while (enumerator.MoveNext()) ;
- Assert.Throws<InvalidOperationException>(() => enumerator.Current);
- Assert.Equal(3, enumerator.ElementIndex);
- Assert.Throws<InvalidOperationException>(() => enumerator.GetTextElement());
- }
-
- [Fact]
- public void AccessingMembersAfterReset_ThrowsInvalidOperationException()
- {
- TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator("abc");
- enumerator.MoveNext();
-
- // Cannot access Current, ElementIndex or GetTextElement() after the enumerator has been reset
- enumerator.Reset();
- Assert.Throws<InvalidOperationException>(() => enumerator.Current);
- Assert.Throws<InvalidOperationException>(() => enumerator.ElementIndex);
- Assert.Throws<InvalidOperationException>(() => enumerator.GetTextElement());
- }
- }
-}
+++ /dev/null
-// 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 TextInfoCultureName
- {
- [Theory]
- public static IEnumerable<object[]> CultureName_TestData()
- {
- yield return new object[] { CultureInfo.InvariantCulture.TextInfo, "" };
- yield return new object[] { new CultureInfo("").TextInfo, "" };
- yield return new object[] { new CultureInfo("en-US").TextInfo, "en-US" };
- yield return new object[] { new CultureInfo("fr-FR").TextInfo, "fr-FR" };
- yield return new object[] { new CultureInfo("EN-us").TextInfo, "en-US" };
- yield return new object[] { new CultureInfo("FR-fr").TextInfo, "fr-FR" };
- }
-
- [Theory]
- [MemberData(nameof(CultureName_TestData))]
- public void CultureName(TextInfo textInfo, string expected)
- {
- Assert.Equal(expected, textInfo.CultureName);
- }
- }
-}
+++ /dev/null
-// 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 TextInfoEquals
- {
- public static IEnumerable<object[]> Equals_TestData()
- {
- yield return new object[] { CultureInfo.InvariantCulture.TextInfo, CultureInfo.InvariantCulture.TextInfo, true };
- yield return new object[] { CultureInfo.InvariantCulture.TextInfo, new CultureInfo("").TextInfo, true };
- yield return new object[] { CultureInfo.InvariantCulture.TextInfo, new CultureInfo("en-US"), false };
-
- yield return new object[] { new CultureInfo("en-US").TextInfo, new CultureInfo("en-US").TextInfo, true };
- yield return new object[] { new CultureInfo("en-US").TextInfo, new CultureInfo("fr-FR").TextInfo, false };
-
- yield return new object[] { new CultureInfo("en-US").TextInfo, null, false };
- yield return new object[] { new CultureInfo("en-US").TextInfo, new object(), false };
- yield return new object[] { new CultureInfo("en-US").TextInfo, 123, false };
- yield return new object[] { new CultureInfo("en-US").TextInfo, "en-US", false };
-
- }
-
- [Theory]
- [MemberData(nameof(Equals_TestData))]
- public void Equals(TextInfo textInfo, object obj, bool expected)
- {
- Assert.Equal(expected, textInfo.Equals(obj));
- if (obj is TextInfo)
- {
- Assert.Equal(expected, textInfo.GetHashCode().Equals(obj.GetHashCode()));
- }
- }
- }
-}
+++ /dev/null
-// 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 TextInfoIsReadOnly
- {
- public static IEnumerable<object[]> IsReadOnly_TestData()
- {
- yield return new object[] { CultureInfo.ReadOnly(new CultureInfo("en-US")).TextInfo, true };
- yield return new object[] { CultureInfo.InvariantCulture.TextInfo, true };
- yield return new object[] { new CultureInfo("").TextInfo, false };
- yield return new object[] { new CultureInfo("en-US").TextInfo, false };
- yield return new object[] { new CultureInfo("fr-FR").TextInfo, false };
- }
-
- [Theory]
- [MemberData(nameof(IsReadOnly_TestData))]
- public void IsReadOnly(TextInfo textInfo, bool expected)
- {
- Assert.Equal(expected, textInfo.IsReadOnly);
- }
- }
-}
+++ /dev/null
-// 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 TextInfoIsRightToLeft
- {
- [Theory]
- [InlineData("en-US", false)]
- [InlineData("ar", true)]
- public void IsRightToLeft(string name, bool expected)
- {
- Assert.Equal(expected, new CultureInfo(name).TextInfo.IsRightToLeft);
- }
- }
-}
+++ /dev/null
-// 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 TextInfoListSeparator
- {
- [Fact]
- public void ListSeparator_EnUS()
- {
- Assert.NotEqual(string.Empty, new CultureInfo("en-US").TextInfo.ListSeparator);
- }
-
- [Theory]
- [InlineData("")]
- [InlineData(" ")]
- [InlineData("abcdef")]
- public void ListSeparator_Set(string newListSeparator)
- {
- TextInfo textInfo = new CultureInfo("en-US").TextInfo;
- textInfo.ListSeparator = newListSeparator;
- Assert.Equal(newListSeparator, textInfo.ListSeparator);
- }
-
- [Fact]
- public void ListSeparator_Set_Invalid()
- {
- Assert.Throws<InvalidOperationException>(() => CultureInfo.InvariantCulture.TextInfo.ListSeparator = "");
- AssertExtensions.Throws<ArgumentNullException>("value", () => new CultureInfo("en-US").TextInfo.ListSeparator = null);
- }
- }
-}
+++ /dev/null
-// 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 System.Reflection;
-using Xunit;
-
-namespace System.Globalization.Tests
-{
- public class TextInfoMiscTests
- {
- public static IEnumerable<object[]> TextInfo_TestData()
- {
- yield return new object[] { "", 0x7f, 0x4e4, 0x25, 0x2710, 0x1b5, false };
- yield return new object[] { "en-US", 0x409, 0x4e4, 0x25, 0x2710, 0x1b5, false };
- yield return new object[] { "ja-JP", 0x411, 0x3a4, 0x4f42, 0x2711, 0x3a4, false };
- yield return new object[] { "zh-CN", 0x804, 0x3a8, 0x1f4, 0x2718, 0x3a8, false };
- yield return new object[] { "ar-SA", 0x401, 0x4e8, 0x4fc4, 0x2714, 0x2d0, true };
- yield return new object[] { "ko-KR", 0x412, 0x3b5, 0x5161, 0x2713, 0x3b5, false };
- yield return new object[] { "he-IL", 0x40d, 0x4e7, 0x1f4, 0x2715, 0x35e, true };
- }
-
- [Theory]
- [MemberData(nameof(TextInfo_TestData))]
- public void MiscTest(string cultureName, int lcid, int ansiCodePage, int ebcdiCCodePage, int macCodePage, int oemCodePage, bool isRightToLeft)
- {
- TextInfo ti = CultureInfo.GetCultureInfo(cultureName).TextInfo;
- Assert.Equal(lcid, ti.LCID);
- Assert.Equal(ansiCodePage, ti.ANSICodePage);
- Assert.Equal(ebcdiCCodePage, ti.EBCDICCodePage);
- Assert.Equal(macCodePage, ti.MacCodePage);
- Assert.Equal(oemCodePage, ti.OEMCodePage);
- Assert.Equal(isRightToLeft, ti.IsRightToLeft);
- }
-
- [Fact]
- public void ReadOnlyTest()
- {
- TextInfo ti = CultureInfo.GetCultureInfo("en-US").TextInfo;
- Assert.True(ti.IsReadOnly, "IsReadOnly should be true with cached TextInfo object");
-
- ti = (TextInfo) ti.Clone();
- Assert.False(ti.IsReadOnly, "IsReadOnly should be false with cloned TextInfo object");
-
- ti = TextInfo.ReadOnly(ti);
- Assert.True(ti.IsReadOnly, "IsReadOnly should be true with created read-nly TextInfo object");
- }
-
- [Fact]
- public void ToTitleCaseTest()
- {
- TextInfo ti = CultureInfo.GetCultureInfo("en-US").TextInfo;
- Assert.Equal("A Tale Of Two Cities", ti.ToTitleCase("a tale of two cities"));
- Assert.Equal("Growl To The Rescue", ti.ToTitleCase("gROWL to the rescue"));
- Assert.Equal("Inside The US Government", ti.ToTitleCase("inside the US government"));
- Assert.Equal("Sports And MLB Baseball", ti.ToTitleCase("sports and MLB baseball"));
- Assert.Equal("The Return Of Sherlock Holmes", ti.ToTitleCase("The Return of Sherlock Holmes"));
- Assert.Equal("UNICEF And Children", ti.ToTitleCase("UNICEF and children"));
-
- AssertExtensions.Throws<ArgumentNullException>("str", () => ti.ToTitleCase(null));
- }
-
- public static IEnumerable<object[]> DutchTitleCaseInfo_TestData()
- {
- yield return new object[] { "nl-NL", "IJ IJ IJ IJ", "ij iJ Ij IJ" };
- yield return new object[] { "nl-be", "IJzeren Eigenschappen", "ijzeren eigenschappen" };
- yield return new object[] { "NL-NL", "Lake IJssel", "lake iJssel" };
- yield return new object[] { "NL-BE", "Boba N' IJango Fett PEW PEW", "Boba n' Ijango fett PEW PEW" };
- yield return new object[] { "en-us", "Ijill And Ijack", "ijill and ijack" };
- yield return new object[] { "de-DE", "Ij Ij IJ Ij", "ij ij IJ ij" };
- yield return new object[] { "he-il", "Ijon't Know What Will Happen.", "Ijon't know what Will happen." };
- }
-
- [Theory]
- [MemberData(nameof(DutchTitleCaseInfo_TestData))]
- [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Desktop Framework hasn't received the fix for dotnet/corefx#16770 yet.")]
- public void ToTitleCaseDutchTest(string cultureName, string expected, string actual)
- {
- TextInfo ti = CultureInfo.GetCultureInfo(cultureName).TextInfo;
- Assert.Equal(expected, ti.ToTitleCase(actual));
- }
- }
-}
+++ /dev/null
-// 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 TextInfoToLower
- {
- private static readonly string [] s_cultureNames = new string[] { "", "en-US", "fr", "fr-FR" };
-
- // ToLower_TestData_net46 has the data which is specific to the full framework
- public static IEnumerable<object[]> ToLower_TestData_net46()
- {
- foreach (string cultureName in s_cultureNames)
- {
- if (PlatformDetection.IsWindows7)
- {
- // on Windows 7, Desktop framework is using its own sorting DLL and not calling the OS except with Invariant culture
- yield return new object[] { cultureName, "\U00010400", cultureName == "" ? "\U00010400" : "\U00010428" };
- }
- else
- {
- yield return new object[] { cultureName, "\U00010400", "\U00010428" };
- }
- }
- }
-
- // ToLower_TestData_netcore has the data which is specific to netcore framework
- public static IEnumerable<object[]> ToLower_TestData_netcore()
- {
- foreach (string cultureName in s_cultureNames)
- {
- // DESERT CAPITAL LETTER LONG I has a lower case variant (but not on Windows 7).
- yield return new object[] { cultureName, "\U00010400", PlatformDetection.IsWindows7 ? "\U00010400" : "\U00010428" };
- }
- }
-
- public static IEnumerable<object[]> ToLower_TestData()
- {
- foreach (string cultureName in s_cultureNames)
- {
- yield return new object[] { cultureName, "", "" };
-
- yield return new object[] { cultureName, "A", "a" };
- yield return new object[] { cultureName, "a", "a" };
- yield return new object[] { cultureName, "ABC", "abc" };
- yield return new object[] { cultureName, "abc", "abc" };
-
- yield return new object[] { cultureName, "1", "1" };
- yield return new object[] { cultureName, "123", "123" };
- yield return new object[] { cultureName, "!", "!" };
-
- yield return new object[] { cultureName, "HELLOWOR!LD123", "hellowor!ld123" };
- yield return new object[] { cultureName, "HelloWor!ld123", "hellowor!ld123" };
- yield return new object[] { cultureName, "Hello\n\0World\u0009!", "hello\n\0world\t!" };
-
- yield return new object[] { cultureName, "THIS IS A LONGER TEST CASE", "this is a longer test case" };
- yield return new object[] { cultureName, "this Is A LONGER mIXEd casE test case", "this is a longer mixed case test case" };
-
- yield return new object[] { cultureName, "THIS \t hAs \t SOMe \t tabs", "this \t has \t some \t tabs" };
- yield return new object[] { cultureName, "EMBEDDED\0NuLL\0Byte\0", "embedded\0null\0byte\0" };
-
- // LATIN CAPITAL LETTER O WITH ACUTE, which has a lower case variant.
- yield return new object[] { cultureName, "\u00D3", "\u00F3" };
-
- // SNOWMAN, which does not have a lower case variant.
- yield return new object[] { cultureName, "\u2603", "\u2603" };
-
- // RAINBOW (outside the BMP and does not case)
- yield return new object[] { cultureName, "\U0001F308", "\U0001F308" };
-
- // Unicode defines some codepoints which expand into multiple codepoints
- // when cased (see SpecialCasing.txt from UNIDATA for some examples). We have never done
- // these sorts of expansions, since it would cause string lengths to change when cased,
- // which is non-intuitive. In addition, there are some context sensitive mappings which
- // we also don't preform.
- // Greek Capital Letter Sigma (does not to case to U+03C2 with "final sigma" rule).
- yield return new object[] { cultureName, "\u03A3", "\u03C3" };
- }
-
- foreach (string cultureName in new string[] { "tr", "tr-TR", "az", "az-Latn-AZ" })
- {
- yield return new object[] { cultureName, "\u0130", "i" };
- yield return new object[] { cultureName, "i", "i" };
- yield return new object[] { cultureName, "I", "\u0131" };
- yield return new object[] { cultureName, "HI!", "h\u0131!" };
- yield return new object[] { cultureName, "HI\n\0H\u0130\t!", "h\u0131\n\0hi\u0009!" };
- }
-
- // ICU has special tailoring for the en-US-POSIX locale which treats "i" and "I" as different letters
- // instead of two letters with a case difference during collation. Make sure this doesn't confuse our
- // casing implementation, which uses collation to understand if we need to do Turkish casing or not.
- if (!PlatformDetection.IsWindows)
- {
- yield return new object[] { "en-US-POSIX", "I", "i" };
- }
- }
-
- public void TestToLower(string name, string str, string expected)
- {
- Assert.Equal(expected, new CultureInfo(name).TextInfo.ToLower(str));
- if (str.Length == 1)
- {
- Assert.Equal(expected[0], new CultureInfo(name).TextInfo.ToLower(str[0]));
- }
- }
-
- [Theory]
- [MemberData(nameof(ToLower_TestData))]
- public void ToLower(string name, string str, string expected)
- {
- TestToLower(name, str, expected);
- }
-
- [Theory]
- [MemberData(nameof(ToLower_TestData_netcore))]
- [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
- public void ToLower_Netcore(string name, string str, string expected)
- {
- TestToLower(name, str, expected);
- }
-
- [Theory]
- [MemberData(nameof(ToLower_TestData_net46))]
- [SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
- public void ToLower_net46(string name, string str, string expected)
- {
- TestToLower(name, str, expected);
- }
-
- [Fact]
- public void ToLower_InvalidSurrogates()
- {
- // Invalid UTF-16 in a string (mismatched surrogate pairs) should be unchanged.
- foreach (string cultureName in new string[] { "", "en-US", "fr" })
- {
- ToLower(cultureName, "BE CAREFUL, \uD83C\uD83C, THIS ONE IS TRICKY", "be careful, \uD83C\uD83C, this one is tricky");
- ToLower(cultureName, "BE CAREFUL, \uDF08\uD83C, THIS ONE IS TRICKY", "be careful, \uDF08\uD83C, this one is tricky");
- ToLower(cultureName, "BE CAREFUL, \uDF08\uDF08, THIS ONE IS TRICKY", "be careful, \uDF08\uDF08, this one is tricky");
- }
- }
-
- [Theory]
- [InlineData("")]
- [InlineData("en-US")]
- [InlineData("fr")]
- public void ToLower_Null_ThrowsArgumentNullException(string cultureName)
- {
- AssertExtensions.Throws<ArgumentNullException>("str", () => new CultureInfo(cultureName).TextInfo.ToLower(null));
- }
- }
-}
+++ /dev/null
-// 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 TextInfoToString
- {
- [Theory]
- [InlineData("en-US", "TextInfo - en-US")]
- [InlineData("fr-FR", "TextInfo - fr-FR")]
- [InlineData("", "TextInfo - ")]
- public void ToString(string name, string expected)
- {
- Assert.Equal(expected, new CultureInfo(name).TextInfo.ToString());
- }
- }
-}
+++ /dev/null
-// 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 TextInfoToUpper
- {
- private static readonly string [] s_cultureNames = new string[] { "", "en-US", "fr", "fr-FR" };
-
- // ToUpper_TestData_netcore has the data which is specific to netcore framework
- public static IEnumerable<object[]> ToUpper_TestData_netcore()
- {
- foreach (string cultureName in s_cultureNames)
- {
- // DESERT SMALL LETTER LONG I has an upper case variant (but not on Windows 7).
- yield return new object[] { cultureName, "\U00010428", PlatformDetection.IsWindows7 ? "\U00010428" : "\U00010400" };
- }
- }
-
- // ToUpper_TestData_net46 has the data which is specific to the full framework
- public static IEnumerable<object[]> ToUpper_TestData_net46()
- {
- foreach (string cultureName in s_cultureNames)
- {
- if (PlatformDetection.IsWindows7)
- {
- // on Windows 7, Desktop framework is using its own sorting DLL and not calling the OS except with Invariant culture
- yield return new object[] { cultureName, "\U00010428", cultureName == "" ? "\U00010428" : "\U00010400" };
- }
- else
- {
- yield return new object[] { cultureName, "\U00010428", "\U00010400" };
- }
- }
- }
-
- public static IEnumerable<object[]> ToUpper_TestData()
- {
- foreach (string cultureName in s_cultureNames)
- {
- yield return new object[] { cultureName, "", "" };
-
- yield return new object[] { cultureName, "a", "A" };
- yield return new object[] { cultureName, "abc", "ABC" };
- yield return new object[] { cultureName, "A", "A" };
- yield return new object[] { cultureName, "ABC", "ABC" };
-
- yield return new object[] { cultureName, "1", "1" };
- yield return new object[] { cultureName, "123", "123" };
- yield return new object[] { cultureName, "!", "!" };
-
- yield return new object[] { cultureName, "HelloWor!ld123", "HELLOWOR!LD123" };
- yield return new object[] { cultureName, "HELLOWOR!LD123", "HELLOWOR!LD123" };
- yield return new object[] { cultureName, "Hello\n\0World\u0009!", "HELLO\n\0WORLD\t!" };
-
- yield return new object[] { cultureName, "this is a longer test case", "THIS IS A LONGER TEST CASE" };
- yield return new object[] { cultureName, "this Is A LONGER mIXEd casE test case", "THIS IS A LONGER MIXED CASE TEST CASE" };
- yield return new object[] { cultureName, "this \t HaS \t somE \t TABS", "THIS \t HAS \t SOME \t TABS" };
-
- yield return new object[] { cultureName, "embedded\0NuLL\0Byte\0", "EMBEDDED\0NULL\0BYTE\0" };
-
- // LATIN SMALL LETTER O WITH ACUTE, which has an upper case variant.
- yield return new object[] { cultureName, "\u00F3", "\u00D3" };
-
- // SNOWMAN, which does not have an upper case variant.
- yield return new object[] { cultureName, "\u2603", "\u2603" };
-
- // RAINBOW (outside the BMP and does not case)
- yield return new object[] { cultureName, "\U0001F308", "\U0001F308" };
-
- // Unicode defines some codepoints which expand into multiple codepoints
- // when cased (see SpecialCasing.txt from UNIDATA for some examples). We have never done
- // these sorts of expansions, since it would cause string lengths to change when cased,
- // which is non-intuitive. In addition, there are some context sensitive mappings which
- // we also don't preform.
- // es-zed does not case to SS when uppercased.
- yield return new object[] { cultureName, "\u00DF", "\u00DF" };
-
- // Ligatures do not expand when cased.
- yield return new object[] { cultureName, "\uFB00", "\uFB00" };
-
- // Precomposed character with no uppercase variant, we don't want to "decompose" this
- // as part of casing.
- yield return new object[] { cultureName, "\u0149", "\u0149" };
- }
-
- // Turkish i
- foreach (string cultureName in new string[] { "tr", "tr-TR", "az", "az-Latn-AZ" })
- {
- yield return new object[] { cultureName, "i", "\u0130" };
- yield return new object[] { cultureName, "\u0130", "\u0130" };
- yield return new object[] { cultureName, "\u0131", "I" };
- yield return new object[] { cultureName, "I", "I" };
- yield return new object[] { cultureName, "H\u0131\n\0Hi\u0009!", "HI\n\0H\u0130\t!" };
- }
-
- // ICU has special tailoring for the en-US-POSIX locale which treats "i" and "I" as different letters
- // instead of two letters with a case difference during collation. Make sure this doesn't confuse our
- // casing implementation, which uses collation to understand if we need to do Turkish casing or not.
- if (!PlatformDetection.IsWindows)
- {
- yield return new object[] { "en-US-POSIX", "i", "I" };
- }
- }
-
- public void TestToUpper(string name, string str, string expected)
- {
- Assert.Equal(expected, new CultureInfo(name).TextInfo.ToUpper(str));
- if (str.Length == 1)
- {
- Assert.Equal(expected[0], new CultureInfo(name).TextInfo.ToUpper(str[0]));
- }
- }
-
- [Theory]
- [MemberData(nameof(ToUpper_TestData))]
- public void ToUpper(string name, string str, string expected)
- {
- TestToUpper(name, str, expected);
- }
-
- [Theory]
- [MemberData(nameof(ToUpper_TestData_netcore))]
- [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
- public void ToUpper_netcore(string name, string str, string expected)
- {
- TestToUpper(name, str, expected);
- }
-
- [Theory]
- [MemberData(nameof(ToUpper_TestData_net46))]
- [SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
- public void ToUpper_net46(string name, string str, string expected)
- {
- TestToUpper(name, str, expected);
- }
-
- [Fact]
- public void ToUpper_InvalidSurrogates()
- {
- // Invalid UTF-16 in a string (mismatched surrogate pairs) should be unchanged.
- foreach (string cultureName in new string[] { "", "en-US", "fr"})
- {
- ToUpper(cultureName, "be careful, \uD83C\uD83C, this one is tricky", "BE CAREFUL, \uD83C\uD83C, THIS ONE IS TRICKY");
- ToUpper(cultureName, "be careful, \uDF08\uD83C, this one is tricky", "BE CAREFUL, \uDF08\uD83C, THIS ONE IS TRICKY");
- ToUpper(cultureName, "be careful, \uDF08\uDF08, this one is tricky", "BE CAREFUL, \uDF08\uDF08, THIS ONE IS TRICKY");
- }
- }
-
- [Theory]
- [InlineData("")]
- [InlineData("en-US")]
- [InlineData("fr")]
- public void ToUpper_Null_ThrowsArgumentNullException(string cultureName)
- {
- AssertExtensions.Throws<ArgumentNullException>("str", () => new CultureInfo(cultureName).TextInfo.ToUpper(null));
- }
- }
-}
+++ /dev/null
-// 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.Globalization;
-using Xunit;
-
-namespace System.Globalization.Tests
-{
- public class UnicodeCategoryTests
- {
- [Theory]
- [InlineData(UnicodeCategory.UppercaseLetter, 0)]
- [InlineData(UnicodeCategory.LowercaseLetter, 1)]
- [InlineData(UnicodeCategory.TitlecaseLetter, 2)]
- [InlineData(UnicodeCategory.ModifierLetter, 3)]
- [InlineData(UnicodeCategory.OtherLetter, 4)]
- [InlineData(UnicodeCategory.NonSpacingMark, 5)]
- [InlineData(UnicodeCategory.SpacingCombiningMark, 6)]
- [InlineData(UnicodeCategory.EnclosingMark, 7)]
- [InlineData(UnicodeCategory.DecimalDigitNumber, 8)]
- [InlineData(UnicodeCategory.LetterNumber, 9)]
- [InlineData(UnicodeCategory.OtherNumber, 10)]
- [InlineData(UnicodeCategory.SpaceSeparator, 11)]
- [InlineData(UnicodeCategory.LineSeparator, 12)]
- [InlineData(UnicodeCategory.ParagraphSeparator, 13)]
- [InlineData(UnicodeCategory.Control, 14)]
- [InlineData(UnicodeCategory.Format, 15)]
- [InlineData(UnicodeCategory.Surrogate, 16)]
- [InlineData(UnicodeCategory.PrivateUse, 17)]
- [InlineData(UnicodeCategory.ConnectorPunctuation, 18)]
- [InlineData(UnicodeCategory.DashPunctuation, 19)]
- [InlineData(UnicodeCategory.OpenPunctuation, 20)]
- [InlineData(UnicodeCategory.ClosePunctuation, 21)]
- [InlineData(UnicodeCategory.InitialQuotePunctuation, 22)]
- [InlineData(UnicodeCategory.FinalQuotePunctuation, 23)]
- [InlineData(UnicodeCategory.OtherPunctuation, 24)]
- [InlineData(UnicodeCategory.MathSymbol, 25)]
- [InlineData(UnicodeCategory.CurrencySymbol, 26)]
- [InlineData(UnicodeCategory.ModifierSymbol, 27)]
- [InlineData(UnicodeCategory.OtherSymbol, 28)]
- [InlineData(UnicodeCategory.OtherNotAssigned, 29)]
- public void Cases(UnicodeCategory category, int expected)
- {
- Assert.Equal(expected, (int)category);
- }
- }
-}