Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/System.Collections.NonGeneric.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.NonGeneric", "System.Collections.NonGeneric\src\System.Collections.NonGeneric.csproj", "{585E3764-534B-4A12-8BD5-8578CB826A45}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Collections.NonGeneric.Tests", "System.Collections.NonGeneric\tests\System.Collections.NonGeneric.Tests.csproj", "{D857AA4D-7D23-4EAF-8367-C548604F587F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{585E3764-534B-4A12-8BD5-8578CB826A45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{585E3764-534B-4A12-8BD5-8578CB826A45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{585E3764-534B-4A12-8BD5-8578CB826A45}.Release|Any CPU.Build.0 = Release|Any CPU
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D857AA4D-7D23-4EAF-8367-C548604F587F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections;
using System.Globalization;
using Xunit;

public class CaseInsensitiveComparer_CultureInfo
{

public bool runTest()
{
//////////// Global Variables used for all tests
int iCountErrors = 0;
int iCountTestcases = 0;

CaseInsensitiveComparer comparer;

try
{
///////////////////////// START TESTS ////////////////////////////
///////////////////////////////////////////////////////////////////

//[]vanila - the ctor simply sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo
//There is no easy way to test this other than make sure that string comparison is case insenstive

iCountTestcases++;
iCountTestcases++;
iCountTestcases++;

var somePopularCultureNames = new string[] {
"cs-CZ","da-DK","de-DE","el-GR","en-US",
"es-ES","fi-FI","fr-FR","hu-HU","it-IT",
"ja-JP","ko-KR","nb-NO","nl-NL","pl-PL",
"pt-BR","pt-PT","ru-RU","sv-SE","tr-TR",
"zh-CN","zh-HK","zh-TW" };
foreach (string cultureName in somePopularCultureNames)
{
CultureInfo culture = new CultureInfo(cultureName);
if (culture == null)
{
continue;
}
comparer = new CaseInsensitiveComparer(culture);

if (comparer.Compare("hello", "HELLO") != 0)
{
iCountErrors++;
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("hello", "HELLO"), culture.Name);
}

//same strings should work ok
if (comparer.Compare("hello", "hello") != 0)
{
iCountErrors++;
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("hello", "hello"), culture.Name);
}

//different strings should return false
if (comparer.Compare("hello", "mello") == 0)
{
iCountErrors++;
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", "non-zero", comparer.Compare("hello", "mello"), culture.Name);
}

// "tr-TR" = "Turkish (Turkey)"
// Turkish has lower-case and upper-case version of the dotted "i", so the upper case of "i" (U+0069) isn't "I" (U+0049), but rather "İ" (U+0130).
if (culture.Name != "tr-TR")
{
if (comparer.Compare("file", "FILE") != 0)
{
iCountErrors++;
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", 0, comparer.Compare("file", "FILE"), culture.Name);
}
}
else
{
if (comparer.Compare("file", "FILE") == 0)
{
iCountErrors++;
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>, Culture: {2}", "non-zero", comparer.Compare("file", "FILE"), culture.Name);
}
}

//[]Other data types should work as is
iCountTestcases++;
if (comparer.Compare(5, 5) != 0)
{
iCountErrors++;
Console.WriteLine("Err_347tsfg! wrong value returned");
}

if (comparer.Compare(5, 10) == 0)
{
iCountErrors++;
Console.WriteLine("Err_973425sdg! wrong value returned");
}
}

//[]parm test
iCountTestcases++;
try
{


comparer = new CaseInsensitiveComparer(null);

iCountErrors++;
Console.WriteLine("Err_9745sdg! Exception not thrown");
}
catch (ArgumentNullException)
{
}
catch (Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_9745sdg! Unexpected exception thrown, " + ex.GetType().Name);
}
///////////////////////////////////////////////////////////////////
/////////////////////////// END TESTS /////////////////////////////
}
catch (Exception exc_general)
{
++iCountErrors;
Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString());
}
//// Finish Diagnostics

if (iCountErrors == 0)
{
return true;
}
else
{
return false;
}
}



[Fact]
public static void ExecuteCaseInsensitiveComparer_CultureInfo()
{
bool bResult = false;
var test = new CaseInsensitiveComparer_CultureInfo();

try
{
bResult = test.runTest();
}
catch (Exception exc_main)
{
bResult = false;
Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main);
}

Assert.Equal(true, bResult);
}}


Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading;
using System.Collections;
using System.Globalization;
using Xunit;

public class CaseInsensitiveComparer_Default
{
public bool runTest()
{
//////////// Global Variables used for all tests
int iCountErrors = 0;
int iCountTestcases = 0;

CaseInsensitiveComparer comparer;
CaseInsensitiveComparer defaultComparer;

try
{
///////////////////////// START TESTS ////////////////////////////
///////////////////////////////////////////////////////////////////

//[]vanila - Default sets the ComapreInfo to the current culture - CultureInfo.CurrentCulture.CompareInfo
//There is no easy way to test this other than make sure that string comparison is case insenstive

iCountTestcases++;
iCountTestcases++;

var somePopularCultureNames = new string[] {
"cs-CZ","da-DK","de-DE","el-GR","en-US",
"es-ES","fi-FI","fr-FR","hu-HU","it-IT",
"ja-JP","ko-KR","nb-NO","nl-NL","pl-PL",
"pt-BR","pt-PT","ru-RU","sv-SE","tr-TR",
"zh-CN","zh-HK","zh-TW" };
foreach (string cultureName in somePopularCultureNames)
{
CultureInfo culture = new CultureInfo(cultureName);
if (culture == null)
{
continue;
}
comparer = new CaseInsensitiveComparer(culture);
defaultComparer = CaseInsensitiveComparer.Default;

if (defaultComparer.Compare("hello", "HELLO") != 0)
{
iCountErrors++;
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "HELLO"));
}

//same strings should work ok
if (defaultComparer.Compare("hello", "hello") != 0)
{
iCountErrors++;
Console.WriteLine("Err_93745sdg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "hello"));
}

//different strings should return false
if (defaultComparer.Compare("hello", "mello") == 0)
{
iCountErrors++;
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("hello", "mello"));
}

//What would turkey do? - Since we are comparing with the default culture, unless this is run on a turkish machine, this will pass
if (CultureInfo.CurrentCulture.Name != "tr-TR")
{
if (defaultComparer.Compare("file", "FILE") != 0)
{
iCountErrors++;
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("file", "FILE"));
}
}
else
{
if (defaultComparer.Compare("file", "FILE") == 0)
{
iCountErrors++;
Console.WriteLine("Err_3846tdfsg! wrong value returned. Expected - <{0}>, Returned - <{1}>", 0, defaultComparer.Compare("file", "FILE"));
}
}

//[]Other data types should work as is
iCountTestcases++;
if (defaultComparer.Compare(5, 5) != 0)
{
iCountErrors++;
Console.WriteLine("Err_347tsfg! wrong value returned");
}

if (defaultComparer.Compare(5, 10) == 0)
{
iCountErrors++;
Console.WriteLine("Err_973425sdg! wrong value returned");
}
}

///////////////////////////////////////////////////////////////////
/////////////////////////// END TESTS /////////////////////////////
}
catch (Exception exc_general)
{
++iCountErrors;
Console.WriteLine(" : Error Err_8888yyy! exc_general==" + exc_general.ToString());
}
//// Finish Diagnostics

if (iCountErrors == 0)
{
return true;
}
else
{
return false;
}
}



[Fact]
public static void ExecuteCaseInsensitiveComparer_Default()
{
bool bResult = false;
var test = new CaseInsensitiveComparer_Default();

try
{
bResult = test.runTest();
}
catch (Exception exc_main)
{
bResult = false;
Console.WriteLine("Fail! Error Err_main! Uncaught Exception in main(), exc_main==" + exc_main);
}

Assert.Equal(true, bResult);
}
}
Loading