提交 49a82631 编写于 作者: B B. Nordli

Fix tests in PatternMatchingTests that fails in cultures with different decimal separator than '.'.

上级 ac8f350e
......@@ -177,7 +177,9 @@ public static void Test<T>(object x)
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics(
);
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"expression 1 is not String
expression foo is not Int32
expression 1 is Int32 1
......@@ -186,7 +188,8 @@ public static void Test<T>(object x)
expression 1 is Nullable`1 1
expression is not Nullable`1
expression is not String";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact]
......@@ -285,11 +288,14 @@ private static void M(object o)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"No for 1
Yes for 10
No for 1.2";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact]
......@@ -317,11 +323,14 @@ private static bool M(object o, bool result)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"False for 1
True for 10
False for 1.2";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact]
......@@ -350,11 +359,14 @@ private static bool M(object o, bool result)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"False for 1
True for 10
False for 1.2";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact, WorkItem(8778, "https://github.com/dotnet/roslyn/issues/8778")]
......@@ -383,11 +395,14 @@ private static bool M(object o, bool result)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions.WithLocalFunctionsFeature());
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"False for 1
True for 10
False for 1.2";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact, WorkItem(8778, "https://github.com/dotnet/roslyn/issues/8778")]
......@@ -418,11 +433,14 @@ private static bool M(object o, bool result)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"False for 1
True for 10
False for 1.2";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact]
......@@ -489,11 +507,14 @@ private static bool M(object o, bool result)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"False for 1
True for 10
False for 1.2";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact]
......@@ -539,7 +560,9 @@ public static void Main()
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe, parseOptions: patternParseOptions);
compilation.VerifyDiagnostics();
var expectedOutput =
using (new EnsureEnglishCulture())
{
var expectedOutput =
@"one
int 10
long 20
......@@ -550,7 +573,8 @@ struct Boolean True
struct X X
class Exception System.Exception: boo
";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
[Fact]
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
namespace Roslyn.Test.Utilities
{
public class EnsureEnglishCulture : IDisposable
{
public static CultureInfo PreferredOrNull
{
get
{
var currentCultureName = CultureInfo.CurrentCulture.Name;
if (currentCultureName.Length == 0 || currentCultureName.StartsWith("en", StringComparison.OrdinalIgnoreCase))
{
return null;
}
return CultureInfo.InvariantCulture;
}
}
private bool _needToRestore;
private readonly CultureInfo _threadCulture;
private readonly int _threadId;
public EnsureEnglishCulture()
{
_threadId = Thread.CurrentThread.ManagedThreadId;
var preferred = PreferredOrNull;
if (preferred != null)
{
_threadCulture = CultureInfo.CurrentCulture;
_needToRestore = true;
#if DNX
CultureInfo.CurrentCulture = preferred;
#else
Thread.CurrentThread.CurrentCulture = preferred;
#endif
}
}
public void Dispose()
{
Debug.Assert(_threadId == Thread.CurrentThread.ManagedThreadId);
if (_needToRestore && _threadId == Thread.CurrentThread.ManagedThreadId)
{
_needToRestore = false;
#if DNX
CultureInfo.CurrentCulture = _threadCulture;
#else
Thread.CurrentThread.CurrentCulture = _threadCulture;
#endif
}
}
}
}
......@@ -43,6 +43,7 @@
<Compile Include="$(MSBuildThisFileDirectory)FX\CultureHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FX\DirectoryHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FX\EncodingUtilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FX\EnsureEnglishCulture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FX\EnsureEnglishUICulture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FX\EventWaiter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FX\ImmutableArrayTestExtensions.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册