' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Collections.Immutable Imports System.Linq Imports Roslyn.Test.Utilities Public Class VisualBasicParseOptionsTests Inherits BasicTestBase Private Sub TestProperty(Of T)(factory As Func(Of VisualBasicParseOptions, T, VisualBasicParseOptions), getter As Func(Of VisualBasicParseOptions, T), validValue As T) Dim oldOpt1 = VisualBasicParseOptions.Default Dim newOpt1 = factory(oldOpt1, validValue) Dim newOpt2 = factory(newOpt1, validValue) Assert.Equal(validValue, getter(newOpt1)) Assert.Same(newOpt2, newOpt1) End Sub Public Sub WithXxx() TestProperty(Function(old, value) old.WithKind(value), Function(opt) opt.Kind, SourceCodeKind.Script) TestProperty(Function(old, value) old.WithLanguageVersion(value), Function(opt) opt.LanguageVersion, LanguageVersion.VisualBasic9) TestProperty(Function(old, value) old.WithDocumentationMode(value), Function(opt) opt.DocumentationMode, DocumentationMode.None) End Sub Public Sub WithLatestLanguageVersion() Dim oldOpt1 = VisualBasicParseOptions.Default Dim newOpt1 = oldOpt1.WithLanguageVersion(LanguageVersion.Latest) Dim newOpt2 = newOpt1.WithLanguageVersion(LanguageVersion.Latest) Assert.Equal(LanguageVersion.Latest.MapSpecifiedToEffectiveVersion, oldOpt1.LanguageVersion) Assert.Equal(LanguageVersion.Latest.MapSpecifiedToEffectiveVersion, newOpt1.LanguageVersion) Assert.Equal(LanguageVersion.Latest.MapSpecifiedToEffectiveVersion, newOpt2.LanguageVersion) newOpt1 = oldOpt1.WithLanguageVersion(LanguageVersion.Default) newOpt2 = newOpt1.WithLanguageVersion(LanguageVersion.Default) Assert.Equal(LanguageVersion.Latest.MapSpecifiedToEffectiveVersion, oldOpt1.LanguageVersion) Assert.Equal(LanguageVersion.Latest.MapSpecifiedToEffectiveVersion, newOpt1.LanguageVersion) Assert.Equal(LanguageVersion.Latest.MapSpecifiedToEffectiveVersion, newOpt2.LanguageVersion) End Sub Public Sub WithPreprocessorSymbols() Dim syms = ImmutableArray.Create(New KeyValuePair(Of String, Object)("A", 1), New KeyValuePair(Of String, Object)("B", 2), New KeyValuePair(Of String, Object)("C", 3)) TestProperty(Function(old, value) old.WithPreprocessorSymbols(value), Function(opt) opt.PreprocessorSymbols, syms) Assert.Equal(0, VisualBasicParseOptions.Default.WithPreprocessorSymbols(syms).WithPreprocessorSymbols(CType(Nothing, ImmutableArray(Of KeyValuePair(Of String, Object)))).PreprocessorSymbols.Length) Assert.Equal(0, VisualBasicParseOptions.Default.WithPreprocessorSymbols(syms).WithPreprocessorSymbols(DirectCast(Nothing, IEnumerable(Of KeyValuePair(Of String, Object)))).PreprocessorSymbols.Length) Assert.Equal(0, VisualBasicParseOptions.Default.WithPreprocessorSymbols(syms).WithPreprocessorSymbols(DirectCast(Nothing, KeyValuePair(Of String, Object)())).PreprocessorSymbols.Length) End Sub Public Sub PredefinedPreprocessorSymbolsTests() Dim options = VisualBasicParseOptions.Default Dim empty = ImmutableArray.Create(Of KeyValuePair(Of String, Object))() Dim symbols = AddPredefinedPreprocessorSymbols(OutputKind.NetModule) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", PredefinedPreprocessorSymbols.CurrentVersionNumber), New KeyValuePair(Of String, Object)("TARGET", "module")}, symbols.AsEnumerable) ' if the symbols are already there, don't change their values symbols = AddPredefinedPreprocessorSymbols(OutputKind.DynamicallyLinkedLibrary, symbols) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", PredefinedPreprocessorSymbols.CurrentVersionNumber), New KeyValuePair(Of String, Object)("TARGET", "module")}, symbols.AsEnumerable) symbols = AddPredefinedPreprocessorSymbols(OutputKind.WindowsApplication, {New KeyValuePair(Of String, Object)("VBC_VER", "Foo"), New KeyValuePair(Of String, Object)("TARGET", 123)}) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", "Foo"), New KeyValuePair(Of String, Object)("TARGET", 123)}, symbols.AsEnumerable) symbols = AddPredefinedPreprocessorSymbols(OutputKind.WindowsApplication, New KeyValuePair(Of String, Object)("VBC_VER", "Foo"), New KeyValuePair(Of String, Object)("TARGET", 123)) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", "Foo"), New KeyValuePair(Of String, Object)("TARGET", 123)}, symbols.AsEnumerable) symbols = AddPredefinedPreprocessorSymbols(OutputKind.ConsoleApplication, empty) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", PredefinedPreprocessorSymbols.CurrentVersionNumber), New KeyValuePair(Of String, Object)("TARGET", "exe")}, symbols.AsEnumerable) symbols = AddPredefinedPreprocessorSymbols(OutputKind.WindowsApplication, empty) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", PredefinedPreprocessorSymbols.CurrentVersionNumber), New KeyValuePair(Of String, Object)("TARGET", "winexe")}, symbols.AsEnumerable) End Sub Public Sub CurrentVersionNumber() Dim highest = System.Enum. GetValues(GetType(LanguageVersion)). Cast(Of LanguageVersion). Select(Function(x) CInt(x)). Where(Function(x) x <> LanguageVersion.Latest). Max() Assert.Equal(highest, CInt(PredefinedPreprocessorSymbols.CurrentVersionNumber)) End Sub Public Sub PredefinedPreprocessorSymbols_Win8() Dim options = VisualBasicParseOptions.Default Dim symbols = AddPredefinedPreprocessorSymbols(OutputKind.WindowsRuntimeApplication) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", PredefinedPreprocessorSymbols.CurrentVersionNumber), New KeyValuePair(Of String, Object)("TARGET", "appcontainerexe")}, symbols.AsEnumerable) symbols = AddPredefinedPreprocessorSymbols(OutputKind.WindowsRuntimeMetadata) AssertEx.SetEqual({New KeyValuePair(Of String, Object)("VBC_VER", PredefinedPreprocessorSymbols.CurrentVersionNumber), New KeyValuePair(Of String, Object)("TARGET", "winmdobj")}, symbols.AsEnumerable) End Sub Public Sub ParseOptionsPass() ParseAndVerify() ParseAndVerify() ParseAndVerify() ParseAndVerify() End Sub Public Sub BC30208ERR_ExpectedOptionCompare() ParseAndVerify(, ) End Sub Public Sub BC30979ERR_InvalidOptionInfer() ParseAndVerify(, ) End Sub Public Sub BC31141ERR_InvalidOptionStrictCustom() ParseAndVerify(, ) End Sub Public Sub BC30620ERR_InvalidOptionStrict_FollowedByAssemblyAttribute() ParseAndVerify( ]]>, ) End Sub Public Sub BC30627ERR_OptionStmtWrongOrder() ParseAndVerify(, ) End Sub Public Sub BC30206ERR_ExpectedForOptionStmt_NullReferenceException() ParseAndVerify(, ) ParseAndVerify(, ) End Sub Public Sub BC30205ERR_ExpectedEOS_ParseOption_ExtraSyntaxAtEOL() ParseAndVerify(, ) End Sub ''' ''' If this test fails, please update the ''' And methods to ''' make sure they are doing the right thing with your New field And then update the baseline ''' here. ''' Public Sub TestFieldsForEqualsAndGetHashCode() ReflectionAssert.AssertPublicAndInternalFieldsAndProperties( (GetType(VisualBasicParseOptions)), "Features", "Language", "LanguageVersion", "PreprocessorSymbolNames", "PreprocessorSymbols", "SpecifiedLanguageVersion") End Sub End Class