提交 194ece29 编写于 作者: R Remy Willems 提交者: Neal Gafter

Added missing With methods in CompilationOptions (#13826)

(thank you @keyboardDrummer!)
上级 52523854
......@@ -179,7 +179,7 @@ public new CSharpCompilationOptions WithOutputKind(OutputKind kind)
return new CSharpCompilationOptions(this) { OutputKind = kind };
}
public CSharpCompilationOptions WithModuleName(string moduleName)
public new CSharpCompilationOptions WithModuleName(string moduleName)
{
if (moduleName == this.ModuleName)
{
......@@ -189,7 +189,7 @@ public CSharpCompilationOptions WithModuleName(string moduleName)
return new CSharpCompilationOptions(this) { ModuleName = moduleName };
}
public CSharpCompilationOptions WithScriptClassName(string name)
public new CSharpCompilationOptions WithScriptClassName(string name)
{
if (name == this.ScriptClassName)
{
......@@ -199,7 +199,7 @@ public CSharpCompilationOptions WithScriptClassName(string name)
return new CSharpCompilationOptions(this) { ScriptClassName = name };
}
public CSharpCompilationOptions WithMainTypeName(string name)
public new CSharpCompilationOptions WithMainTypeName(string name)
{
if (name == this.MainTypeName)
{
......@@ -209,7 +209,7 @@ public CSharpCompilationOptions WithMainTypeName(string name)
return new CSharpCompilationOptions(this) { MainTypeName = name };
}
public CSharpCompilationOptions WithCryptoKeyContainer(string name)
public new CSharpCompilationOptions WithCryptoKeyContainer(string name)
{
if (name == this.CryptoKeyContainer)
{
......@@ -219,7 +219,7 @@ public CSharpCompilationOptions WithCryptoKeyContainer(string name)
return new CSharpCompilationOptions(this) { CryptoKeyContainer = name };
}
public CSharpCompilationOptions WithCryptoKeyFile(string path)
public new CSharpCompilationOptions WithCryptoKeyFile(string path)
{
if (path == this.CryptoKeyFile)
{
......@@ -229,7 +229,7 @@ public CSharpCompilationOptions WithCryptoKeyFile(string path)
return new CSharpCompilationOptions(this) { CryptoKeyFile = path };
}
public CSharpCompilationOptions WithCryptoPublicKey(ImmutableArray<byte> value)
public new CSharpCompilationOptions WithCryptoPublicKey(ImmutableArray<byte> value)
{
if (value.IsDefault)
{
......@@ -244,7 +244,7 @@ public CSharpCompilationOptions WithCryptoPublicKey(ImmutableArray<byte> value)
return new CSharpCompilationOptions(this) { CryptoPublicKey = value };
}
public CSharpCompilationOptions WithDelaySign(bool? value)
public new CSharpCompilationOptions WithDelaySign(bool? value)
{
if (value == this.DelaySign)
{
......@@ -279,7 +279,7 @@ public new CSharpCompilationOptions WithOptimizationLevel(OptimizationLevel valu
return new CSharpCompilationOptions(this) { OptimizationLevel = value };
}
public CSharpCompilationOptions WithOverflowChecks(bool enabled)
public new CSharpCompilationOptions WithOverflowChecks(bool enabled)
{
if (enabled == this.CheckOverflow)
{
......@@ -634,6 +634,46 @@ internal override Diagnostic FilterDiagnostic(Diagnostic diagnostic)
return CSharpDiagnosticFilter.Filter(diagnostic, WarningLevel, GeneralDiagnosticOption, SpecificDiagnosticOptions);
}
protected override CompilationOptions CommonWithModuleName(string moduleName)
{
return WithModuleName(moduleName);
}
protected override CompilationOptions CommonWithMainTypeName(string mainTypeName)
{
return WithMainTypeName(mainTypeName);
}
protected override CompilationOptions CommonWithScriptClassName(string scriptClassName)
{
return WithScriptClassName(scriptClassName);
}
protected override CompilationOptions CommonWithCryptoKeyContainer(string cryptoKeyContainer)
{
return WithCryptoKeyContainer(cryptoKeyContainer);
}
protected override CompilationOptions CommonWithCryptoKeyFile(string cryptoKeyFile)
{
return WithCryptoKeyFile(cryptoKeyFile);
}
protected override CompilationOptions CommonWithCryptoPublicKey(ImmutableArray<byte> cryptoPublicKey)
{
return WithCryptoPublicKey(cryptoPublicKey);
}
protected override CompilationOptions CommonWithDelaySign(bool? delaySign)
{
return WithDelaySign(delaySign);
}
protected override CompilationOptions CommonWithCheckOverflow(bool checkOverflow)
{
return WithOverflowChecks(checkOverflow);
}
// 1.1 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
[EditorBrowsable(EditorBrowsableState.Never)]
public CSharpCompilationOptions(
......
......@@ -23,20 +23,28 @@ public static void VerifyErrors(this CSharpCompilationOptions options, params Di
public class CSharpCompilationOptionsTests : CSharpTestBase
{
private void TestProperty<T>(
Func<CSharpCompilationOptions, T, CSharpCompilationOptions> factory,
Func<CSharpCompilationOptions, T> getter,
/// <summary>
/// Using an instance of <see cref="CSharpCompilationOptions"/>, tests a property in <see cref="CompilationOptions"/> , even it is hidden by <see cref="CSharpCompilationOptions"/>.
/// </summary>
private void TestHiddenProperty<T>(
Func<CompilationOptions, T, CompilationOptions> factory,
Func<CompilationOptions, T> getter,
T validNonDefaultValue)
{
var oldOpt1 = new CSharpCompilationOptions(OutputKind.ConsoleApplication);
TestPropertyGeneric(new CSharpCompilationOptions(OutputKind.ConsoleApplication), factory, getter, validNonDefaultValue);
}
var validDefaultValue = getter(oldOpt1);
private static void TestPropertyGeneric<TOptions, T>(TOptions oldOptions, Func<TOptions, T, TOptions> factory,
Func<TOptions, T> getter, T validNonDefaultValue)
where TOptions : CompilationOptions
{
var validDefaultValue = getter(oldOptions);
// we need non-default value to test Equals and GetHashCode
Assert.NotEqual(validNonDefaultValue, validDefaultValue);
// check that the assigned value can be read:
var newOpt1 = factory(oldOpt1, validNonDefaultValue);
var newOpt1 = factory(oldOptions, validNonDefaultValue);
Assert.Equal(validNonDefaultValue, getter(newOpt1));
Assert.Equal(0, newOpt1.Errors.Length);
......@@ -45,14 +53,50 @@ public class CSharpCompilationOptionsTests : CSharpTestBase
Assert.Same(newOpt1_alias, newOpt1);
// check that Equals and GetHashCode work
var newOpt2 = factory(oldOpt1, validNonDefaultValue);
Assert.False(newOpt1.Equals(oldOpt1));
var newOpt2 = factory(oldOptions, validNonDefaultValue);
Assert.False(newOpt1.Equals(oldOptions));
Assert.True(newOpt1.Equals(newOpt2));
Assert.Equal(newOpt1.GetHashCode(), newOpt2.GetHashCode());
// test default(T):
Assert.NotNull(factory(oldOpt1, default(T)));
Assert.NotNull(factory(oldOptions, default(T)));
}
[Fact]
public void ShadowInvariants()
{
TestHiddenProperty((old, value) => old.WithOutputKind(value), opt => opt.OutputKind, OutputKind.DynamicallyLinkedLibrary);
TestHiddenProperty((old, value) => old.WithModuleName(value), opt => opt.ModuleName, "foo.dll");
TestHiddenProperty((old, value) => old.WithMainTypeName(value), opt => opt.MainTypeName, "Foo.Bar");
TestHiddenProperty((old, value) => old.WithScriptClassName(value), opt => opt.ScriptClassName, "<Script>");
TestHiddenProperty((old, value) => old.WithOptimizationLevel(value), opt => opt.OptimizationLevel, OptimizationLevel.Release);
TestHiddenProperty((old, value) => old.WithOverflowChecks(value), opt => opt.CheckOverflow, true);
TestHiddenProperty((old, value) => old.WithCryptoKeyContainer(value), opt => opt.CryptoKeyContainer, "foo");
TestHiddenProperty((old, value) => old.WithCryptoKeyFile(value), opt => opt.CryptoKeyFile, "foo");
TestHiddenProperty((old, value) => old.WithCryptoPublicKey(value), opt => opt.CryptoPublicKey, ImmutableArray.Create<byte>(0, 1, 2, 3));
TestHiddenProperty((old, value) => old.WithDelaySign(value), opt => opt.DelaySign, true);
TestHiddenProperty((old, value) => old.WithPlatform(value), opt => opt.Platform, Platform.Itanium);
TestHiddenProperty((old, value) => old.WithGeneralDiagnosticOption(value), opt => opt.GeneralDiagnosticOption, ReportDiagnostic.Suppress);
TestHiddenProperty((old, value) => old.WithSpecificDiagnosticOptions(value), opt => opt.SpecificDiagnosticOptions,
new Dictionary<string, ReportDiagnostic> { { "CS0001", ReportDiagnostic.Error } }.ToImmutableDictionary());
TestHiddenProperty((old, value) => old.WithReportSuppressedDiagnostics(value), opt => opt.ReportSuppressedDiagnostics, true);
TestHiddenProperty((old, value) => old.WithConcurrentBuild(value), opt => opt.ConcurrentBuild, false);
TestHiddenProperty((old, value) => old.WithXmlReferenceResolver(value), opt => opt.XmlReferenceResolver, new XmlFileResolver(null));
TestHiddenProperty((old, value) => old.WithMetadataReferenceResolver(value), opt => opt.MetadataReferenceResolver, new TestMetadataReferenceResolver());
TestHiddenProperty((old, value) => old.WithAssemblyIdentityComparer(value), opt => opt.AssemblyIdentityComparer, new DesktopAssemblyIdentityComparer(new AssemblyPortabilityPolicy()));
TestHiddenProperty((old, value) => old.WithStrongNameProvider(value), opt => opt.StrongNameProvider, new DesktopStrongNameProvider());
}
private void TestProperty<T>(
Func<CSharpCompilationOptions, T, CSharpCompilationOptions> factory,
Func<CSharpCompilationOptions, T> getter,
T validNonDefaultValue)
{
TestPropertyGeneric(new CSharpCompilationOptions(OutputKind.ConsoleApplication), factory, getter, validNonDefaultValue);
}
[Fact]
......@@ -79,7 +123,7 @@ public void Invariants()
TestProperty((old, value) => old.WithReportSuppressedDiagnostics(value), opt => opt.ReportSuppressedDiagnostics, true);
TestProperty((old, value) => old.WithConcurrentBuild(value), opt => opt.ConcurrentBuild, false);
TestProperty((old, value) => old.WithCurrentLocalTime(value), opt => opt.CurrentLocalTime, new DateTime(2005,1,1));
TestProperty((old, value) => old.WithCurrentLocalTime(value), opt => opt.CurrentLocalTime, new DateTime(2005, 1, 1));
TestProperty((old, value) => old.WithExtendedCustomDebugInformation(value), opt => opt.ExtendedCustomDebugInformation, false);
TestProperty((old, value) => old.WithDebugPlusMode(value), opt => opt.DebugPlusMode, true);
......
......@@ -159,7 +159,7 @@ public abstract class CompilationOptions
internal DateTime CurrentLocalTime { get; private set; }
internal DateTime CurrentLocalTime_internal_protected_set { set { CurrentLocalTime = value; } }
/// <summary>
/// Emit extended custom debug information to the PDB file.
/// </summary>
......@@ -467,6 +467,46 @@ public CompilationOptions WithStrongNameProvider(StrongNameProvider provider)
return CommonWithStrongNameProvider(provider);
}
public CompilationOptions WithModuleName(string moduleName)
{
return CommonWithModuleName(moduleName);
}
public CompilationOptions WithMainTypeName(string mainTypeName)
{
return CommonWithMainTypeName(mainTypeName);
}
public CompilationOptions WithScriptClassName(string scriptClassName)
{
return CommonWithScriptClassName(scriptClassName);
}
public CompilationOptions WithCryptoKeyContainer(string cryptoKeyContainer)
{
return CommonWithCryptoKeyContainer(cryptoKeyContainer);
}
public CompilationOptions WithCryptoKeyFile(string cryptoKeyFile)
{
return CommonWithCryptoKeyFile(cryptoKeyFile);
}
public CompilationOptions WithCryptoPublicKey(ImmutableArray<byte> cryptoPublicKey)
{
return CommonWithCryptoPublicKey(cryptoPublicKey);
}
public CompilationOptions WithDelaySign(bool? delaySign)
{
return CommonWithDelaySign(delaySign);
}
public CompilationOptions WithOverflowChecks(bool checkOverflow)
{
return CommonWithCheckOverflow(checkOverflow);
}
protected abstract CompilationOptions CommonWithConcurrentBuild(bool concurrent);
protected abstract CompilationOptions CommonWithDeterministic(bool deterministic);
protected abstract CompilationOptions CommonWithOutputKind(OutputKind kind);
......@@ -482,6 +522,15 @@ public CompilationOptions WithStrongNameProvider(StrongNameProvider provider)
protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> specificDiagnosticOptions);
protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions);
protected abstract CompilationOptions CommonWithReportSuppressedDiagnostics(bool reportSuppressedDiagnostics);
protected abstract CompilationOptions CommonWithModuleName(string moduleName);
protected abstract CompilationOptions CommonWithMainTypeName(string mainTypeName);
protected abstract CompilationOptions CommonWithScriptClassName(string scriptClassName);
protected abstract CompilationOptions CommonWithCryptoKeyContainer(string cryptoKeyContainer);
protected abstract CompilationOptions CommonWithCryptoKeyFile(string cryptoKeyFile);
protected abstract CompilationOptions CommonWithCryptoPublicKey(ImmutableArray<byte> cryptoPublicKey);
protected abstract CompilationOptions CommonWithDelaySign(bool? delaySign);
protected abstract CompilationOptions CommonWithCheckOverflow(bool checkOverflow);
[Obsolete]
protected abstract CompilationOptions CommonWithFeatures(ImmutableArray<string> features);
......
......@@ -14,6 +14,14 @@ Microsoft.CodeAnalysis.Compilation.CreateTupleTypeSymbol(System.Collections.Immu
Microsoft.CodeAnalysis.Compilation.Emit(System.IO.Stream peStream, System.IO.Stream pdbStream = null, System.IO.Stream xmlDocumentationStream = null, System.IO.Stream win32Resources = null, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources = null, Microsoft.CodeAnalysis.Emit.EmitOptions options = null, Microsoft.CodeAnalysis.IMethodSymbol debugEntryPoint = null, System.IO.Stream sourceLinkStream = null, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.EmbeddedText> embeddedTexts = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.Emit.EmitResult
Microsoft.CodeAnalysis.Compilation.Emit(System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.IMethodSymbol debugEntryPoint, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.Emit.EmitResult
Microsoft.CodeAnalysis.CompilationOptions.WithConcurrentBuild(bool concurrent) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithCryptoKeyContainer(string cryptoKeyContainer) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithCryptoKeyFile(string cryptoKeyFile) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithCryptoPublicKey(System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithDelaySign(bool? delaySign) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithMainTypeName(string mainTypeName) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithModuleName(string moduleName) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithOverflowChecks(bool checkOverflow) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithScriptClassName(string scriptClassName) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.Diagnostics.AnalysisContext.RegisterOperationAction(System.Action<Microsoft.CodeAnalysis.Diagnostics.OperationAnalysisContext> action, params Microsoft.CodeAnalysis.OperationKind[] operationKinds) -> void
Microsoft.CodeAnalysis.Diagnostics.CompilationStartAnalysisContext.RegisterOperationAction(System.Action<Microsoft.CodeAnalysis.Diagnostics.OperationAnalysisContext> action, params Microsoft.CodeAnalysis.OperationKind[] operationKinds) -> void
Microsoft.CodeAnalysis.Diagnostics.OperationAnalysisContext
......
......@@ -386,7 +386,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' </summary>
''' <param name="moduleName">The moduleName.</param>
''' <returns>A new instance of VisualBasicCompilationOptions, if the module name is different; otherwise current instance.</returns>
Public Function WithModuleName(moduleName As String) As VisualBasicCompilationOptions
Public Shadows Function WithModuleName(moduleName As String) As VisualBasicCompilationOptions
If String.Equals(moduleName, Me.ModuleName, StringComparison.Ordinal) Then
Return Me
End If
......@@ -1199,5 +1199,37 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
referencesSupersedeLowerVersions:=False)
End Sub
Protected Overrides Function CommonWithModuleName(moduleName As String) As CompilationOptions
Return WithModuleName(moduleName)
End Function
Protected Overrides Function CommonWithMainTypeName(mainTypeName As String) As CompilationOptions
Return WithMainTypeName(mainTypeName)
End Function
Protected Overrides Function CommonWithScriptClassName(scriptClassName As String) As CompilationOptions
Return WithScriptClassName(scriptClassName)
End Function
Protected Overrides Function CommonWithCryptoKeyContainer(cryptoKeyContainer As String) As CompilationOptions
Return WithCryptoKeyContainer(cryptoKeyContainer)
End Function
Protected Overrides Function CommonWithCryptoKeyFile(cryptoKeyFile As String) As CompilationOptions
Return WithCryptoKeyFile(cryptoKeyFile)
End Function
Protected Overrides Function CommonWithCryptoPublicKey(cryptoPublicKey As ImmutableArray(Of Byte)) As CompilationOptions
Return WithCryptoPublicKey(cryptoPublicKey)
End Function
Protected Overrides Function CommonWithDelaySign(delaySign As Boolean?) As CompilationOptions
Return WithDelaySign(delaySign)
End Function
Protected Overrides Function CommonWithCheckOverflow(checkOverflow As Boolean) As CompilationOptions
Return WithOverflowChecks(checkOverflow)
End Function
End Class
End Namespace
......@@ -10,19 +10,59 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
Public Class VisualBasicCompilationOptionsTests
Inherits BasicTestBase
''' <summary>
''' Using an instance of <see cref="VisualBasicCompilationOptions"/>, tests a property in <see cref="CompilationOptions"/> , even it is hidden by <see cref="VisualBasicCompilationOptions"/>.
''' </summary>
Private Sub TestHiddenProperty(Of T)(factory As Func(Of CompilationOptions, T, CompilationOptions),
getter As Func(Of CompilationOptions, T),
validNonDefaultValue As T)
TestPropertyGeneric(New VisualBasicCompilationOptions(OutputKind.ConsoleApplication), factory, getter, validNonDefaultValue)
End Sub
<Fact>
Public Sub ShadowInvariants()
TestHiddenProperty(Function(old, value) old.WithOutputKind(value), Function(opt) opt.OutputKind, OutputKind.DynamicallyLinkedLibrary)
TestHiddenProperty(Function(old, value) old.WithModuleName(value), Function(opt) opt.ModuleName, "foo.dll")
TestHiddenProperty(Function(old, value) old.WithMainTypeName(value), Function(opt) opt.MainTypeName, "Foo.Bar")
TestHiddenProperty(Function(old, value) old.WithScriptClassName(value), Function(opt) opt.ScriptClassName, "<Script>")
TestHiddenProperty(Function(old, value) old.WithOptimizationLevel(value), Function(opt) opt.OptimizationLevel, OptimizationLevel.Release)
TestHiddenProperty(Function(old, value) old.WithOverflowChecks(value), Function(opt) opt.CheckOverflow, False)
TestHiddenProperty(Function(old, value) old.WithCryptoKeyContainer(value), Function(opt) opt.CryptoKeyContainer, "foo")
TestHiddenProperty(Function(old, value) old.WithCryptoKeyFile(value), Function(opt) opt.CryptoKeyFile, "foo")
TestHiddenProperty(Function(old, value) old.WithCryptoPublicKey(value), Function(opt) opt.CryptoPublicKey, ImmutableArray.CreateRange(Of Byte)({1, 2, 3, 4}))
TestHiddenProperty(Function(old, value) old.WithDelaySign(value), Function(opt) opt.DelaySign, True)
TestHiddenProperty(Function(old, value) old.WithPlatform(value), Function(opt) opt.Platform, Platform.X64)
TestHiddenProperty(Function(old, value) old.WithGeneralDiagnosticOption(value), Function(opt) opt.GeneralDiagnosticOption, ReportDiagnostic.Suppress)
TestHiddenProperty(Function(old, value) old.WithSpecificDiagnosticOptions(value), Function(opt) opt.SpecificDiagnosticOptions,
New Dictionary(Of String, ReportDiagnostic) From {{"VB0001", ReportDiagnostic.Error}}.ToImmutableDictionary())
TestHiddenProperty(Function(old, value) old.WithReportSuppressedDiagnostics(value), Function(opt) opt.ReportSuppressedDiagnostics, True)
TestHiddenProperty(Function(old, value) old.WithConcurrentBuild(value), Function(opt) opt.ConcurrentBuild, False)
TestHiddenProperty(Function(old, value) old.WithXmlReferenceResolver(value), Function(opt) opt.XmlReferenceResolver, New XmlFileResolver(Nothing))
TestHiddenProperty(Function(old, value) old.WithSourceReferenceResolver(value), Function(opt) opt.SourceReferenceResolver, New SourceFileResolver(ImmutableArray(Of String).Empty, Nothing))
TestHiddenProperty(Function(old, value) old.WithMetadataReferenceResolver(value), Function(opt) opt.MetadataReferenceResolver, New TestMetadataReferenceResolver())
TestHiddenProperty(Function(old, value) old.WithAssemblyIdentityComparer(value), Function(opt) opt.AssemblyIdentityComparer, New DesktopAssemblyIdentityComparer(New AssemblyPortabilityPolicy()))
End Sub
Private Sub TestProperty(Of T)(factory As Func(Of VisualBasicCompilationOptions, T, VisualBasicCompilationOptions),
getter As Func(Of VisualBasicCompilationOptions, T),
validNonDefaultValue As T)
TestPropertyGeneric(New VisualBasicCompilationOptions(OutputKind.ConsoleApplication), factory, getter, validNonDefaultValue)
End Sub
Dim oldOpt1 = New VisualBasicCompilationOptions(OutputKind.ConsoleApplication)
Dim validDefaultValue = getter(oldOpt1)
Private Shared Sub TestPropertyGeneric(Of TOptions As CompilationOptions, T)(oldOptions As TOptions,
factory As Func(Of TOptions, T, TOptions),
getter As Func(Of TOptions, T), validNonDefaultValue As T)
Dim validDefaultValue = getter(oldOptions)
' we need non-default value to test Equals And GetHashCode
Assert.NotEqual(validNonDefaultValue, validDefaultValue)
' check that the assigned value can be read
Dim newOpt1 = factory(oldOpt1, validNonDefaultValue)
Dim newOpt1 = factory(oldOptions, validNonDefaultValue)
Assert.Equal(validNonDefaultValue, getter(newOpt1))
Assert.Equal(0, newOpt1.Errors.Length)
......@@ -31,14 +71,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
Assert.Same(newOpt1_alias, newOpt1)
' check that Equals And GetHashCode work
Dim newOpt2 = factory(oldOpt1, validNonDefaultValue)
Assert.False(newOpt1.Equals(oldOpt1))
Dim newOpt2 = factory(oldOptions, validNonDefaultValue)
Assert.False(newOpt1.Equals(oldOptions))
Assert.True(newOpt1.Equals(newOpt2))
Assert.Equal(newOpt1.GetHashCode(), newOpt2.GetHashCode())
' test Nothing:
Assert.NotNull(factory(oldOpt1, Nothing))
Assert.NotNull(factory(oldOptions, Nothing))
End Sub
<Fact>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册