Ejemplo n.º 1
0
        public void ImplicitExpressionAcceptsDotAtEndOfNonWhitespaceCharacters()
        {
            var factory = new SpanFactory();
            var changed = new StringTextSnapshot("@{" + Environment.NewLine
                                                 + "    @foo." + Environment.NewLine
                                                 + "}");
            var old = new StringTextSnapshot("@{" + Environment.NewLine
                                             + "    @foo" + Environment.NewLine
                                             + "}");

            RunPartialParseTest(new TestEdit(10 + Environment.NewLine.Length, 0, old, 1, changed, "."),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                                        factory.Code(Environment.NewLine + "    ")
                                        .AsStatement()
                                        .AutoCompleteWith(autoCompleteString: null),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code(@"foo.")
                                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                        factory.Code(Environment.NewLine).AsStatement(),
                                        factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
                                    factory.EmptyHtml()));
        }
        public void ImplicitExpressionAcceptsInnerInsertionsInStatementBlock()
        {
            // Arrange
            SpanFactory      factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("@{" + Environment.NewLine
                                                            + "    @DateTime..Now" + Environment.NewLine
                                                            + "}");
            StringTextBuffer old = new StringTextBuffer("@{" + Environment.NewLine
                                                        + "    @DateTime.Now" + Environment.NewLine
                                                        + "}");

            // Act and Assert
            RunPartialParseTest(new TextChange(17, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("{").Accepts(AcceptedCharacters.None),
                                        factory.Code("\r\n    ").AsStatement(),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code("DateTime..Now")
                                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                        factory.Code("\r\n").AsStatement(),
                                        factory.MetaCode("}").Accepts(AcceptedCharacters.None)),
                                    factory.EmptyHtml()));
        }
Ejemplo n.º 3
0
        public void ImplicitExpressionAcceptsInnerInsertionsInStatementBlock()
        {
            // Arrange
            var factory = new SpanFactory();
            var changed = new StringTextSnapshot("@{" + Environment.NewLine
                                                 + "    @DateTime..Now" + Environment.NewLine
                                                 + "}");
            var old = new StringTextSnapshot("@{" + Environment.NewLine
                                             + "    @DateTime.Now" + Environment.NewLine
                                             + "}");

            // Act and Assert
            RunPartialParseTest(new TestEdit(17, 0, old, 1, changed, "."),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                                        factory.Code(Environment.NewLine + "    ")
                                        .AsStatement()
                                        .AutoCompleteWith(autoCompleteString: null),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code("DateTime..Now")
                                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                        factory.Code(Environment.NewLine).AsStatement(),
                                        factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
                                    factory.EmptyHtml()));
        }
Ejemplo n.º 4
0
        public void ImplicitExpressionAcceptsDotlessCommitInsertionsInStatementBlockAfterIdentifiers()
        {
            SpanFactory      factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("@{" + Environment.NewLine
                                                            + "    @DateTime." + Environment.NewLine
                                                            + "}");
            StringTextBuffer old = new StringTextBuffer("@{" + Environment.NewLine
                                                        + "    @DateTime" + Environment.NewLine
                                                        + "}");

            var textChange = new TextChange(17, 0, old, 1, changed);

            using (TestParserManager manager = CreateParserManager())
            {
                Action <TextChange, PartialParseResult, string> applyAndVerifyPartialChange = (changeToApply, expectedResult, expectedCode) =>
                {
                    PartialParseResult result = manager.CheckForStructureChangesAndWait(textChange);

                    // Assert
                    Assert.Equal(expectedResult, result);
                    Assert.Equal(1, manager.ParseCount);
                    ParserTestBase.EvaluateParseTree(manager.Parser.CurrentParseTree, new MarkupBlock(
                                                         factory.EmptyHtml(),
                                                         new StatementBlock(
                                                             factory.CodeTransition(),
                                                             factory.MetaCode("{").Accepts(AcceptedCharacters.None),
                                                             factory.Code("\r\n    ").AsStatement(),
                                                             new ExpressionBlock(
                                                                 factory.CodeTransition(),
                                                                 factory.Code(expectedCode)
                                                                 .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                                                 .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                                             factory.Code("\r\n").AsStatement(),
                                                             factory.MetaCode("}").Accepts(AcceptedCharacters.None)),
                                                         factory.EmptyHtml()));
                };

                manager.InitializeWithDocument(textChange.OldBuffer);

                // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
                applyAndVerifyPartialChange(textChange, PartialParseResult.Accepted, "DateTime.");

                old     = changed;
                changed = new StringTextBuffer("@{" + Environment.NewLine
                                               + "    @DateTime.." + Environment.NewLine
                                               + "}");
                textChange = new TextChange(18, 0, old, 1, changed);

                applyAndVerifyPartialChange(textChange, PartialParseResult.Accepted, "DateTime..");

                old     = changed;
                changed = new StringTextBuffer("@{" + Environment.NewLine
                                               + "    @DateTime.Now." + Environment.NewLine
                                               + "}");
                textChange = new TextChange(18, 0, old, 3, changed);

                applyAndVerifyPartialChange(textChange, PartialParseResult.Accepted, "DateTime.Now.");
            }
        }
        public async Task ImplicitExpressionAcceptsDotlessCommitInsertionsInStatementBlockAfterIdentifiers()
        {
            var factory = new SpanFactory();
            var changed = new StringTextSnapshot("@{" + Environment.NewLine
                                                 + "    @DateTime." + Environment.NewLine
                                                 + "}");
            var original = new StringTextSnapshot("@{" + Environment.NewLine
                                                  + "    @DateTime" + Environment.NewLine
                                                  + "}");

            var edit = new TestEdit(15 + Environment.NewLine.Length, 0, original, 1, changed, ".");

            using (var manager = CreateParserManager(original))
            {
                void ApplyAndVerifyPartialChange(TestEdit testEdit, string expectedCode)
                {
                    manager.ApplyEdit(testEdit);
                    Assert.Equal(1, manager.ParseCount);
                    ParserTestBase.EvaluateParseTree(manager.PartialParsingSyntaxTreeRoot, new MarkupBlock(
                                                         factory.EmptyHtml(),
                                                         new StatementBlock(
                                                             factory.CodeTransition(),
                                                             factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                                                             factory.Code(Environment.NewLine + "    ")
                                                             .AsStatement()
                                                             .AutoCompleteWith(autoCompleteString: null),
                                                             new ExpressionBlock(
                                                                 factory.CodeTransition(),
                                                                 factory.Code(expectedCode)
                                                                 .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                                                 .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                                             factory.Code(Environment.NewLine).AsStatement(),
                                                             factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
                                                         factory.EmptyHtml()));
                };

                await manager.InitializeWithDocumentAsync(edit.OldSnapshot);

                // This is the process of a dotless commit when doing "." insertions to commit intellisense changes.
                ApplyAndVerifyPartialChange(edit, "DateTime.");

                original = changed;
                changed  = new StringTextSnapshot("@{" + Environment.NewLine
                                                  + "    @DateTime.." + Environment.NewLine
                                                  + "}");
                edit = new TestEdit(16 + Environment.NewLine.Length, 0, original, 1, changed, ".");

                ApplyAndVerifyPartialChange(edit, "DateTime..");

                original = changed;
                changed  = new StringTextSnapshot("@{" + Environment.NewLine
                                                  + "    @DateTime.Now." + Environment.NewLine
                                                  + "}");
                edit = new TestEdit(16 + Environment.NewLine.Length, 0, original, 3, changed, "Now");

                ApplyAndVerifyPartialChange(edit, "DateTime.Now.");
            }
        }
Ejemplo n.º 6
0
        public void ImplicitExpressionAcceptsDotIfTrailingDotsAreAllowed()
        {
            var factory = new SpanFactory();
            var changed = new StringTextSnapshot("@{@foo.}");
            var old     = new StringTextSnapshot("@{@foo}");

            RunPartialParseTest(new TestEdit(6, 0, old, 1, changed, "."),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("{").Accepts(AcceptedCharactersInternal.None),
                                        factory.EmptyCSharp()
                                        .AsStatement()
                                        .AutoCompleteWith(autoCompleteString: null),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code("foo.")
                                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                        factory.EmptyCSharp().AsStatement(),
                                        factory.MetaCode("}").Accepts(AcceptedCharactersInternal.None)),
                                    factory.EmptyHtml()));
        }
        public async Task ImplicitExpressionRejectsChangeWhichWouldHaveBeenAcceptedIfLastChangeWasProvisionallyAcceptedOnDifferentSpan()
        {
            // Arrange
            var factory   = new SpanFactory();
            var dotTyped  = new TestEdit(8, 0, new StringTextSnapshot("foo @foo @bar"), 1, new StringTextSnapshot("foo @foo. @bar"), ".");
            var charTyped = new TestEdit(14, 0, new StringTextSnapshot("foo @foo. @bar"), 1, new StringTextSnapshot("foo @foo. @barb"), "b");

            using (var manager = CreateParserManager(dotTyped.OldSnapshot))
            {
                await manager.InitializeWithDocumentAsync(dotTyped.OldSnapshot);

                // Apply the dot change
                await manager.ApplyEditAndWaitForReparseAsync(dotTyped);

                // Act (apply the identifier start char change)
                await manager.ApplyEditAndWaitForParseAsync(charTyped);

                // Assert
                Assert.Equal(2, manager.ParseCount);
                ParserTestBase.EvaluateParseTree(manager.PartialParsingSyntaxTreeRoot,
                                                 new MarkupBlock(
                                                     factory.Markup("foo "),
                                                     new ExpressionBlock(
                                                         factory.CodeTransition(),
                                                         factory.Code("foo")
                                                         .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                                                         .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                                     factory.Markup(". "),
                                                     new ExpressionBlock(
                                                         factory.CodeTransition(),
                                                         factory.Code("barb")
                                                         .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                                                         .Accepts(AcceptedCharactersInternal.NonWhiteSpace)),
                                                     factory.EmptyHtml()));
            }
        }