Ejemplo n.º 1
0
        public void ArrayImplicit_Initializer_OpenBraceOnSameLine_Enter()
        {
            var code = @"class C
{
    public void man()
    {
        int[] arr = $$
    }
}";

            var expected      = @"class C
{
    public void man()
    {
        int[] arr = {

        }
    }
}";
            var globalOptions = new OptionsCollection(LanguageNames.CSharp)
            {
                { CSharpFormattingOptions2.NewLinesForBracesInObjectCollectionArrayInitializers, false }
            };

            using var session = CreateSession(code, globalOptions);
            Assert.NotNull(session);

            CheckStart(session.Session);
            CheckReturn(session.Session, 12, expected);
        }
Ejemplo n.º 2
0
        public void BlockIndentationWithAutomaticBraceFormattingDisabled()
        {
            var code = @"class C
{
    public void X()
    $$
}";

            var expected = @"class C
{
    public void X()
    {}
}";

            var expectedAfterReturn = @"class C
{
    public void X()
    {

    }
}";
            var globalOptions       = new OptionsCollection(LanguageNames.CSharp)
            {
                { AutoFormattingOptionsStorage.FormatOnCloseBrace, false },
                { FormattingOptions2.SmartIndent, FormattingOptions2.IndentStyle.Block },
            };

            using var session = CreateSession(code, globalOptions);
            Assert.NotNull(session);

            CheckStart(session.Session);
            Assert.Equal(expected, session.Session.SubjectBuffer.CurrentSnapshot.GetText());

            CheckReturn(session.Session, 4, expectedAfterReturn);
        }
Ejemplo n.º 3
0
        public void BlockIndentationWithAutomaticBraceFormatting()
        {
            var code = @"namespace NS1
{
        public class C1
        $$
}";

            var expected = @"namespace NS1
{
        public class C1
        { }
}";

            var expectedAfterReturn = @"namespace NS1
{
        public class C1
        {

        }
}";

            var globalOptions = new OptionsCollection(LanguageNames.CSharp)
            {
                { FormattingOptions2.SmartIndent, FormattingOptions2.IndentStyle.Block },
            };

            using var session = CreateSession(code, globalOptions);
            Assert.NotNull(session);

            CheckStart(session.Session);
            Assert.Equal(expected, session.Session.SubjectBuffer.CurrentSnapshot.GetText());

            CheckReturn(session.Session, 8, expectedAfterReturn);
        }
Ejemplo n.º 4
0
 internal static async Task TestChangeSignatureViaCommandAsync(
     string languageName,
     string markup,
     bool expectedSuccess   = true,
     int[] updatedSignature = null,
     string expectedUpdatedInvocationDocumentCode     = null,
     ChangeSignatureFailureKind?expectedFailureReason = null,
     int?totalParameters       = null,
     bool verifyNoDiagnostics  = false,
     ParseOptions parseOptions = null,
     OptionsCollection options = null,
     int expectedSelectedIndex = -1
     ) =>
 await TestChangeSignatureViaCommandAsync(
     languageName,
     markup,
     updatedSignature?.Select(i => new AddedParameterOrExistingIndex(i)).ToArray(),
     expectedSuccess,
     expectedUpdatedInvocationDocumentCode,
     expectedFailureReason,
     totalParameters,
     verifyNoDiagnostics,
     parseOptions,
     options,
     expectedSelectedIndex
     );
 private void OnRemoveOptionClick(object sender, RoutedEventArgs e)
 {
     ValidateDeleteButton();
     if (OptionsCollection.Any() && IsSelectedItem())
     {
         var index = expressionsListBox.SelectedIndex;
         OptionsCollection.RemoveAt(index);
         var count = OptionsCollection.Count;
         if (count > 0)
         {
             if (index >= count)
             {
                 index = count - 1;
             }
             expressionsListBox.SelectedIndex = index;
         }
         else
         {
             if (!string.IsNullOrEmpty(_expressionEditor.ExpressionText))
             {
                 _expressionEditor.ExpressionText = string.Empty;
             }
         }
     }
 }
Ejemplo n.º 6
0
        public static ChangeSignatureTestState Create(
            string markup,
            string languageName,
            ParseOptions parseOptions = null,
            OptionsCollection options = null
            )
        {
            var workspace = languageName switch
            {
                "XML" => TestWorkspace.Create(markup, composition: s_composition),
                LanguageNames.CSharp
                => TestWorkspace.CreateCSharp(
                    markup,
                    composition: s_composition,
                    parseOptions: (CSharpParseOptions)parseOptions
                    ),
                LanguageNames.VisualBasic
                => TestWorkspace.CreateVisualBasic(
                    markup,
                    composition: s_composition,
                    parseOptions: parseOptions,
                    compilationOptions: new VisualBasicCompilationOptions(
                        OutputKind.DynamicallyLinkedLibrary
                        )
                    ),
                _ => throw new ArgumentException("Invalid language name.")
            };

            if (options != null)
            {
                workspace.ApplyOptions(options);
            }

            return(new ChangeSignatureTestState(workspace));
        }
        internal static async Task TestChangeSignatureViaCommandAsync(
            string languageName,
            string markup,
            AddedParameterOrExistingIndex[] updatedSignature,
            bool expectedSuccess = true,
            string expectedUpdatedInvocationDocumentCode = null,
            string expectedErrorText  = null,
            int?totalParameters       = null,
            bool verifyNoDiagnostics  = false,
            ParseOptions parseOptions = null,
            OptionsCollection options = null,
            int expectedSelectedIndex = -1)
        {
            using (var testState = ChangeSignatureTestState.Create(markup, languageName, parseOptions, options))
            {
                testState.TestChangeSignatureOptionsService.UpdatedSignature = updatedSignature;
                var result = testState.ChangeSignature();

                if (expectedSuccess)
                {
                    Assert.True(result.Succeeded);
                    Assert.Null(testState.ErrorMessage);
                }
                else
                {
                    Assert.False(result.Succeeded);

                    if (expectedErrorText != null)
                    {
                        Assert.Equal(expectedErrorText, testState.ErrorMessage);
                        Assert.Equal(NotificationSeverity.Error, testState.ErrorSeverity);
                    }
                }

                // Allow testing of invocation document regardless of success/failure
                if (expectedUpdatedInvocationDocumentCode != null)
                {
                    var updatedInvocationDocument = result.UpdatedSolution.GetDocument(testState.InvocationDocument.Id);
                    var updatedCode = (await updatedInvocationDocument.GetTextAsync()).ToString();
                    Assert.Equal(expectedUpdatedInvocationDocumentCode, updatedCode);
                }

                if (verifyNoDiagnostics)
                {
                    var diagnostics = (await testState.InvocationDocument.GetSemanticModelAsync()).GetDiagnostics();

                    if (diagnostics.Length > 0)
                    {
                        Assert.True(false, CreateDiagnosticsString(diagnostics, updatedSignature, testState.InvocationDocument, totalParameters, (await testState.InvocationDocument.GetTextAsync()).ToString()));
                    }
                }

                if (expectedSelectedIndex != -1)
                {
                    var parameterConfiguration = await testState.GetParameterConfigurationAsync();

                    Assert.Equal(expectedSelectedIndex, parameterConfiguration.SelectedIndex);
                }
            }
        }
Ejemplo n.º 8
0
        public async Task FormatSpanNullReference02()
        {
            var code =
                @"class C/*1*/
{
    void F()
    {
        System.Console.WriteLine();
    }
}/*2*/";

            var expected =
                @"class C
{
    void F()
    {
        System.Console.WriteLine();
    }
}";
            var changingOptions = new OptionsCollection(LanguageNames.CSharp)
            {
                { CSharpFormattingOptions2.WrappingPreserveSingleLine, false }
            };

            await AssertFormatAsync(code, expected, changedOptionSet : changingOptions);
        }
Ejemplo n.º 9
0
        public void ExtensionWithPositionalAndAssignmentOptions()
        {
            var actual  = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Value,Property='Some Value'}");
            var options = new OptionsCollection {
                new PositionalOption("Value"), new PropertyOption("Property", new StringNode("Some Value"))
            };

            Assert.AreEqual(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
        }
Ejemplo n.º 10
0
        private protected Task TestAllWrappingCasesAsync(
            string input,
            OptionsCollection options,
            params string[] outputs)
        {
            var parameters = new TestParameters(options: options);

            return(TestAllInRegularAndScriptAsync(input, parameters, outputs));
        }
Ejemplo n.º 11
0
        public void PropertyWithMoreThanOneSpaceBetweenTokensPropertiesOnly()
        {
            var actual  = MarkupExtensionParser.MarkupExtension.Parse("{Dummy   Property  =   SomeValue    }");
            var options = new OptionsCollection {
                new PropertyOption("Property", new StringNode("SomeValue"))
            };

            Assert.Equal(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
        }
Ejemplo n.º 12
0
        public async Task FormatRelationalPatterns1(
            [CombinatorialValues("<", "<=", ">", ">=")] string operatorText,
            BinaryOperatorSpacingOptions spacing)
        {
            var content = $@"
class A
{{
    bool Method(int value)
    {{
        return value  is  {operatorText}  3  or  {operatorText}  5;
    }}
}}
";

            var expectedSingle = $@"
class A
{{
    bool Method(int value)
    {{
        return value is {operatorText} 3 or {operatorText} 5;
    }}
}}
";
            var expectedIgnore = $@"
class A
{{
    bool Method(int value)
    {{
        return value is  {operatorText}  3  or  {operatorText}  5;
    }}
}}
";
            var expectedRemove = $@"
class A
{{
    bool Method(int value)
    {{
        return value is {operatorText}3 or {operatorText}5;
    }}
}}
";

            var expected = spacing switch
            {
                BinaryOperatorSpacingOptions.Single => expectedSingle,
                BinaryOperatorSpacingOptions.Ignore => expectedIgnore,
                BinaryOperatorSpacingOptions.Remove => expectedRemove,
                _ => throw ExceptionUtilities.Unreachable,
            };

            var changingOptions = new OptionsCollection(LanguageNames.CSharp)
            {
                { CSharpFormattingOptions2.SpacingAroundBinaryOperator, spacing },
            };

            await AssertFormatAsync(expected, content, changedOptionSet : changingOptions);
        }
Ejemplo n.º 13
0
 private protected Task AssertNoFormattingChangesAsync(
     string code,
     bool debugMode = false,
     OptionsCollection changedOptionSet = null,
     bool testWithTransformation        = true,
     ParseOptions parseOptions          = null)
 {
     return(AssertFormatAsync(code, code, SpecializedCollections.SingletonEnumerable(new TextSpan(0, code.Length)), debugMode, changedOptionSet, testWithTransformation, parseOptions));
 }
Ejemplo n.º 14
0
        public void PropertyWithDirectValueAndSpaces()
        {
            var actual  = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Property = SomeValue }");
            var options = new OptionsCollection {
                new PropertyOption("Property", new StringNode("SomeValue"))
            };

            Assert.Equal(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
        }
Ejemplo n.º 15
0
        public void ExtensionWithTwoPositionalOptions()
        {
            var actual  = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Value1,Value2}");
            var options = new OptionsCollection {
                new PositionalOption("Value1"), new PositionalOption("Value2")
            };

            Assert.AreEqual(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
        }
Ejemplo n.º 16
0
        public void ExtensionWithDottedPositionalOption()
        {
            var actual  = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Direct.Value}");
            var options = new OptionsCollection {
                new PositionalOption("Direct.Value"),
            };

            Assert.AreEqual(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
        }
Ejemplo n.º 17
0
        public void PositionalWithSpecialChars()
        {
            var actual  = MarkupExtensionParser.MarkupExtension.Parse("{Binding Foo^.Bar}");
            var options = new OptionsCollection {
                new PositionalOption("Foo^.Bar")
            };

            Assert.Equal(new MarkupExtensionNode(new IdentifierNode("BindingExtension"), options), actual);
        }
Ejemplo n.º 18
0
        public void SaveConfiguration(OptionsCollection options)
        {
            var serializableOptions = new SerializableOptionsCollection(options);

            using (var f = File.Open(_configFilename, FileMode.Create))
            {
                _serializer.Serialize(f, serializableOptions);
            }
        }
Ejemplo n.º 19
0
 internal IpV6MobilityOptions Pad(int paddingSize)
 {
     if (paddingSize == 0)
     {
         return(this);
     }
     return(new IpV6MobilityOptions(
                OptionsCollection.Concat(paddingSize == 1 ? (IpV6MobilityOption) new IpV6MobilityOptionPad1() : new IpV6MobilityOptionPadN(paddingSize - 2)),
                IsValid));
 }
        private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var fe    = (FrameworkElement)sender;
            var index = OptionsCollection.IndexOf((StyleOption)fe.DataContext);

            if (index >= 0)
            {
                expressionsListBox.SelectedIndex = index;
            }
        }
        public SerializableOptionsCollection(OptionsCollection options)
        {
            SerializableOptions          = new List <SerializableOption>();
            SerializableOptions.Capacity = options.Count;

            foreach (var opt in options)
            {
                SerializableOptions.Add(new SerializableOption(opt.Key, opt.Value));
            }
        }
        public OptionsCollection ToOptionsCollection()
        {
            var r = new OptionsCollection();

            foreach (var opt in SerializableOptions)
            {
                r.Add(opt.OptionName, opt.OptionValue);
            }

            return(r);
        }
Ejemplo n.º 23
0
 private protected Task AssertFormatAsync(
     string expected,
     string code,
     IEnumerable <TextSpan> spans,
     bool debugMode = false,
     OptionsCollection changedOptionSet = null,
     bool testWithTransformation        = true,
     ParseOptions parseOptions          = null)
 {
     return(AssertFormatAsync(expected, code, spans, LanguageNames.CSharp, debugMode, changedOptionSet, testWithTransformation, parseOptions));
 }
Ejemplo n.º 24
0
        internal IpV6Options Pad(int paddingSize)
        {
            if (paddingSize == 0)
            {
                return(this);
            }
            IEnumerable <IpV6Option> paddedOptions =
                OptionsCollection.Concat(paddingSize == 1 ? (IpV6Option) new IpV6OptionPad1() : new IpV6OptionPadN(paddingSize - 2));

            return(new IpV6Options(new Tuple <IList <IpV6Option>, bool>(paddedOptions.ToList(), IsValid)));
        }
Ejemplo n.º 25
0
        internal Task TestAllOptionsOffAsync(
            string initialMarkup, string expectedMarkup,
            ParseOptions parseOptions             = null,
            CompilationOptions compilationOptions = null,
            int index = 0, OptionsCollection options = null)
        {
            options = options ?? new OptionsCollection(GetLanguage());
            options.AddRange(AllOptionsOff);

            return(TestAsync(initialMarkup, expectedMarkup,
                             parseOptions, compilationOptions, index, options));
        }
        private void OnAddOptionClick(object sender, RoutedEventArgs e)
        {
            var opt = new StyleOption
            {
                Name = NewExpressionString
            };

            OptionsCollection.Add(opt);
            expressionsListBox.SelectedIndex = OptionsCollection.Count - 1;
            expressionsListBox.ScrollIntoView(opt);
            ValidateDeleteButton();
        }
Ejemplo n.º 27
0
        public void ParsePositionalAndPropertyOptions()
        {
            var actual   = MarkupExtensionParser.Options.Parse("value1,Property1=Value1,Property2='Some value'");
            var expected = new OptionsCollection(new List <Option>
            {
                new PositionalOption("value1"),
                new PropertyOption("Property1", new StringNode("Value1")),
                new PropertyOption("Property2", new StringNode("Some value"))
            });

            Assert.AreEqual(actual, expected);
        }
 public override void LoadConfiguration()
 {
     _lock.EnterWriteLock();
     try
     {
         _options = _configStore.LoadConfiguration();
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
        public EventHookupTestState(XElement workspaceElement, OptionsCollection options)
            : base(workspaceElement, GetExtraParts())
        {
            _commandHandler = new EventHookupCommandHandler(
                Workspace.ExportProvider.GetExportedValue <IThreadingContext>(),
                Workspace.GetService <IInlineRenameService>(),
                Workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>(),
                Workspace.ExportProvider.GetExportedValue <EventHookupSessionManager>());

            _testSessionHookupMutex = new Mutex(false);
            _commandHandler.TESTSessionHookupMutex = _testSessionHookupMutex;
            Workspace.ApplyOptions(options);
        }
        internal OptionsCollection MergeStyles(OptionsCollection first, OptionsCollection second)
        {
            var firstPreferences  = (NamingStylePreferences)first.First().Value;
            var secondPreferences = (NamingStylePreferences)second.First().Value;

            return(new OptionsCollection(_languageName)
            {
                { NamingStyleOptions.NamingPreferences, new NamingStylePreferences(
                      firstPreferences.SymbolSpecifications.AddRange(secondPreferences.SymbolSpecifications),
                      firstPreferences.NamingStyles.AddRange(secondPreferences.NamingStyles),
                      firstPreferences.NamingRules.AddRange(secondPreferences.NamingRules)) }
            });
        }
Ejemplo n.º 31
0
        public void ParsePositionalAndPropertyOptions()
        {
            var actual = MarkupExtensionParser.Options.Parse("value1,Property1=Value1,Property2='Some value'");
            var expected = new OptionsCollection(new List<Option>
            {
                new PositionalOption("value1"),
                new PropertyOption("Property1", new StringNode("Value1")),
                new PropertyOption("Property2", new StringNode("Some value"))
            });

            Assert.AreEqual(actual, expected);
        }
Ejemplo n.º 32
0
 public void ExtensionWithTwoPositionalOptions()
 {
     var actual = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Value1,Value2}");
     var options = new OptionsCollection { new PositionalOption("Value1"), new PositionalOption("Value2") };
     Assert.AreEqual(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
 }
Ejemplo n.º 33
0
 public MarkupExtensionNode(IdentifierNode identifier, OptionsCollection options)
 {
     Options = new OptionsCollection(options);
     Identifier = identifier;
 }
Ejemplo n.º 34
0
 public void ExtensionWithDottedPositionalOption()
 {
     var actual = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Direct.Value}");
     var options = new OptionsCollection { new PositionalOption("Direct.Value"), };
     Assert.AreEqual(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
 }
Ejemplo n.º 35
0
 public void ExtensionWithPositionalAndAssignmentOptions()
 {
     var actual = MarkupExtensionParser.MarkupExtension.Parse("{Dummy Value,Property='Some Value'}");
     var options = new OptionsCollection { new PositionalOption("Value"), new PropertyOption("Property", new StringNode("Some Value")) };
     Assert.AreEqual(new MarkupExtensionNode(new IdentifierNode("DummyExtension"), options), actual);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Creates a new HTML select element.
 /// </summary>
 internal HTMLSelectElement()
     : base(Tags.Select)
 {
     _options = new OptionsCollection(this);
     WillValidate = true;
 }