Esempio n. 1
0
        public void ImplicitExpressionAcceptsDeleteOfIdentifierPartsIfSomeOfIdentifierRemains()
        {
            StringTextBuffer changed = new StringTextBuffer("foo @Us baz");
            StringTextBuffer old     = new StringTextBuffer("foo @User baz");

            RunPartialParseTest(new TextChange(7, 2, old, 0, changed),
                                new MarkupBlock(
                                    new MarkupSpan("foo "),
                                    new ExpressionBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new ImplicitExpressionSpan("Us", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                        ),
                                    new MarkupSpan(" baz")));
        }
Esempio n. 2
0
        public void ImplicitExpressionAcceptsMultipleInsertionIfItOnlyCausesIdentifierExpansion()
        {
            StringTextBuffer changed = new StringTextBuffer("foo @barbiz baz");
            StringTextBuffer old     = new StringTextBuffer("foo @bar baz");

            RunPartialParseTest(new TextChange(8, 0, old, 3, changed),
                                new MarkupBlock(
                                    new MarkupSpan("foo "),
                                    new ExpressionBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new ImplicitExpressionSpan("barbiz", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                        ),
                                    new MarkupSpan(" baz")));
        }
Esempio n. 3
0
        public void ImplicitExpressionAcceptsAdditionalIdentifierCharactersIfEndOfSpanIsIdentifier()
        {
            StringTextBuffer changed = new StringTextBuffer("foo @foob baz");
            StringTextBuffer old     = new StringTextBuffer("foo @foo bar");

            RunPartialParseTest(new TextChange(8, 0, old, 1, changed),
                                new MarkupBlock(
                                    new MarkupSpan("foo "),
                                    new ExpressionBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new ImplicitExpressionSpan("foob", VBCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                        ),
                                    new MarkupSpan(" bar")));
        }
Esempio n. 4
0
        public void SpanWithAcceptTrailingDotOnAcceptsIntelliSenseReplaceWhichActuallyInsertsDot()
        {
            // Arrange
            var span       = new ImplicitExpressionSpan("abcd", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true, acceptedCharacters: AcceptedCharacters.None);
            var newBuffer  = new StringTextBuffer("abcd.");
            var oldBuffer  = new StringTextBuffer("abcd");
            var textChange = new TextChange(0, 4, oldBuffer, 5, newBuffer);

            // Act
            PartialParseResult result = span.ApplyChange(textChange);

            // Assert
            Assert.AreEqual(PartialParseResult.Accepted, result);
        }
Esempio n. 5
0
        public void ImplicitExpressionAcceptsMultipleInsertionIfItOnlyCausesIdentifierExpansion()
        {
            var factory = SpanFactory.CreateCsHtml();
            var changed = new StringTextBuffer("foo @barbiz baz");
            var old     = new StringTextBuffer("foo @bar baz");

            RunPartialParseTest(new TextChange(8, 0, old, 3, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("barbiz").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")));
        }
Esempio n. 6
0
        public void ImplicitExpressionAcceptsDeleteOfIdentifierPartsIfSomeOfIdentifierRemains()
        {
            var factory = SpanFactory.CreateCsHtml();
            var changed = new StringTextBuffer("foo @Us baz");
            var old     = new StringTextBuffer("foo @User baz");

            RunPartialParseTest(new TextChange(7, 2, old, 0, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("Us").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")));
        }
Esempio n. 7
0
        public void SpanWithAcceptTrailingDotOffProvisionallyAcceptsEndReplacementWithTrailingDot()
        {
            // Arrange
            var span       = new ImplicitExpressionSpan("abcd.", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.None);
            var newBuffer  = new StringTextBuffer("abcdef.");
            var oldBuffer  = new StringTextBuffer("abcd.");
            var textChange = new TextChange(0, 5, oldBuffer, 7, newBuffer);

            // Act
            PartialParseResult result = span.ApplyChange(textChange);

            // Assert
            Assert.AreEqual(PartialParseResult.Accepted | PartialParseResult.Provisional, result);
        }
        public void NewTextWithInsertReturnsChangedTextFromBuffer()
        {
            // Arrange
            var newBuffer  = new StringTextBuffer("test");
            var oldBuffer  = new StringTextBuffer("");
            var textChange = new TextChange(0, 0, oldBuffer, 3, newBuffer);

            // Act
            string text    = textChange.NewText;
            string oldText = textChange.OldText;

            // Assert
            Assert.Equal("tes", text);
            Assert.Equal("", oldText);
        }
Esempio n. 9
0
        public void ImplicitExpressionProvisionallyAcceptsDotAfterIdentifierInMarkup()
        {
            StringTextBuffer changed = new StringTextBuffer("foo @foo. bar");
            StringTextBuffer old     = new StringTextBuffer("foo @foo bar");

            RunPartialParseTest(new TextChange(8, 0, old, 1, changed),
                                new MarkupBlock(
                                    new MarkupSpan("foo "),
                                    new ExpressionBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new ImplicitExpressionSpan("foo.", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                        ),
                                    new MarkupSpan(" bar")),
                                additionalFlags: PartialParseResult.Provisional);
        }
        public void NewTextWithReplaceReturnsChangedTextFromBuffer()
        {
            // Arrange
            var newBuffer  = new StringTextBuffer("test");
            var oldBuffer  = new StringTextBuffer("tebb");
            var textChange = new TextChange(2, 2, oldBuffer, 1, newBuffer);

            // Act
            string newText = textChange.NewText;
            string oldText = textChange.OldText;

            // Assert
            Assert.Equal("s", newText);
            Assert.Equal("bb", oldText);
        }
        public void ImplicitExpressionProvisionallyAcceptsMultipleInsertionIfItCausesIdentifierExpansionAndTrailingDot()
        {
            var factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @User. baz");
            StringTextBuffer old     = new StringTextBuffer("foo @U baz");

            RunPartialParseTest(new TextChange(6, 0, old, 4, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("User.").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")),
                                additionalFlags: PartialParseResult.Provisional);
        }
        public void ImplicitExpressionProvisionallyAcceptsDeleteOfIdentifierPartsIfDotRemains()
        {
            SpanFactory      factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @User. baz");
            StringTextBuffer old     = new StringTextBuffer("foo @User.Name baz");

            RunPartialParseTest(new TextChange(10, 4, old, 0, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("User.").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")),
                                additionalFlags: PartialParseResult.Provisional);
        }
Esempio n. 13
0
        public void ImplicitExpressionProvisionallyAcceptsMultipleInsertionIfItCausesIdentifierExpansionAndTrailingDot()
        {
            StringTextBuffer changed = new StringTextBuffer("foo @User. baz");
            StringTextBuffer old     = new StringTextBuffer("foo @U baz");

            RunPartialParseTest(new TextChange(6, 0, old, 4, changed),
                                new MarkupBlock(
                                    new MarkupSpan("foo "),
                                    new ExpressionBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new ImplicitExpressionSpan("User.", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                        ),
                                    new MarkupSpan(" baz")),
                                additionalFlags: PartialParseResult.Provisional);
        }
Esempio n. 14
0
        public void ImplicitExpressionProvisionallyAcceptsDeleteOfIdentifierPartsIfDotRemains()
        {
            StringTextBuffer changed = new StringTextBuffer("foo @User. baz");
            StringTextBuffer old     = new StringTextBuffer("foo @User.Name baz");

            RunPartialParseTest(new TextChange(10, 4, old, 0, changed),
                                new MarkupBlock(
                                    new MarkupSpan("foo "),
                                    new ExpressionBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new ImplicitExpressionSpan("User.", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                        ),
                                    new MarkupSpan(" baz")),
                                additionalFlags: PartialParseResult.Provisional);
        }
        public void ImplicitExpressionAcceptsDotlessCommitInsertionsInStatementBlock()
        {
            SpanFactory      factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("@{" + Environment.NewLine
                                                            + "    @DateT." + Environment.NewLine
                                                            + "}");
            StringTextBuffer old = new StringTextBuffer("@{" + Environment.NewLine
                                                        + "    @DateT" + Environment.NewLine
                                                        + "}");

            var textChange            = new TextChange(14, 0, old, 1, changed);
            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, "DateT.");

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

            applyAndVerifyPartialChange(textChange, PartialParseResult.Accepted, "DateTime.");
        }
Esempio n. 16
0
        public void AwaitPeriodInsertionAcceptedProvisionally()
        {
            // Arrange
            var factory = SpanFactory.CreateCsHtml();
            var changed = new StringTextBuffer("foo @await Html. baz");
            var old     = new StringTextBuffer("foo @await Html baz");

            // Act and Assert
            RunPartialParseTest(new TextChange(15, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("await Html.").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.WhiteSpace | AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")), additionalFlags: PartialParseResult.Provisional);
        }
        public void ImplicitExpressionAcceptsAdditionalIdentifierCharactersIfEndOfSpanIsIdentifier()
        {
            var factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @foob bar");
            StringTextBuffer old     = new StringTextBuffer("foo @foo bar");

            RunPartialParseTest(new TextChange(8, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("foob")
                                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" bar")));
        }
Esempio n. 18
0
        public void ImplicitExpressionAcceptsWholeIdentifierReplacement()
        {
            // Arrange
            SpanFactory      factory = SpanFactory.CreateCsHtml();
            StringTextBuffer old     = new StringTextBuffer("foo @date baz");
            StringTextBuffer changed = new StringTextBuffer("foo @DateTime baz");

            // Act and Assert
            RunPartialParseTest(new TextChange(5, 4, old, 8, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("DateTime").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")));
        }
        public void ImplicitExpressionAcceptsInnerInsertions()
        {
            // Arrange
            SpanFactory      factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @DateTime..Now baz");
            StringTextBuffer old     = new StringTextBuffer("foo @DateTime.Now baz");

            // Act and Assert
            RunPartialParseTest(new TextChange(13, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("DateTime..Now").AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")), additionalFlags: PartialParseResult.Provisional);
        }
        public void ImplicitExpressionProvisionallyAcceptsDotAfterIdentifierInMarkup()
        {
            var factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @foo. bar");
            StringTextBuffer old     = new StringTextBuffer("foo @foo bar");

            RunPartialParseTest(new TextChange(8, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("foo.")
                                        .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" bar")),
                                additionalFlags: PartialParseResult.Provisional);
        }
Esempio n. 21
0
        public void Parse(string text, string fileName = @"d:\projects\MyProject\test.ts")
        {
            ProjectContent = MockRepository.GenerateStub <IProjectContent>();
            var textBuffer = new StringTextBuffer(text);

            var scriptLoader = new ParseTestScriptLoader();
            var logger       = new LanguageServiceLogger();
            ITypeScriptContextFactory contextFactory = MockRepository.GenerateStub <ITypeScriptContextFactory>();

            contextFactory
            .Stub(f => f.CreateContext())
            .Return(new TypeScriptContext(scriptLoader, logger));

            var parser = new TypeScriptParser(contextFactory);

            CompilationUnit = parser.Parse(ProjectContent, fileName, textBuffer);
        }
Esempio n. 22
0
        public void ImplicitExpressionAcceptsAdditionalIdentifierStartCharactersIfEndOfSpanIsDot()
        {
            StringTextBuffer changed = new StringTextBuffer("@Code @foo.b End Code");
            StringTextBuffer old     = new StringTextBuffer("@Code @foo. End Code");

            RunPartialParseTest(new TextChange(11, 0, old, 1, changed),
                                new MarkupBlock(
                                    new StatementBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new MetaCodeSpan("Code", hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new CodeSpan(" "),
                                        new ExpressionBlock(
                                            new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                            new ImplicitExpressionSpan("foo.b", VBCodeParser.DefaultKeywords, acceptTrailingDot: true, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                            ),
                                        new CodeSpan(" "),
                                        new MetaCodeSpan("End Code", hidden: false, acceptedCharacters: AcceptedCharacters.None)),
                                    new MarkupSpan(String.Empty)));
        }
Esempio n. 23
0
        public void ImplicitExpressionProvisionallyAcceptsDotlessCommitInsertionsAfterIdentifiers()
        {
            SpanFactory factory    = SpanFactory.CreateCsHtml();
            var         changed    = new StringTextBuffer("foo @DateTime. baz");
            var         old        = new StringTextBuffer("foo @DateTime baz");
            var         textChange = new TextChange(13, 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.Markup("foo "),
                                                         new ExpressionBlock(
                                                             factory.CodeTransition(),
                                                             factory.Code(expectedCode).AsImplicitExpression(CSharpCodeParser.DefaultKeywords).Accepts(AcceptedCharacters.NonWhiteSpace)),
                                                         factory.Markup(" baz")));
                };

                manager.InitializeWithDocument(textChange.OldBuffer);

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

                old        = changed;
                changed    = new StringTextBuffer("foo @DateTime.. baz");
                textChange = new TextChange(14, 0, old, 1, changed);

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

                old        = changed;
                changed    = new StringTextBuffer("foo @DateTime.Now. baz");
                textChange = new TextChange(14, 0, old, 3, changed);

                applyAndVerifyPartialChange(textChange, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime.Now.");
            }
        }
Esempio n. 24
0
        public void ImplicitExpressionAcceptsDotIfTrailingDotsAreAllowed()
        {
            StringTextBuffer changed = new StringTextBuffer("@{@foo.}");
            StringTextBuffer old     = new StringTextBuffer("@{@foo}");

            RunPartialParseTest(new TextChange(6, 0, old, 1, changed),
                                new MarkupBlock(
                                    new StatementBlock(
                                        new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new MetaCodeSpan("{", hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                        new CodeSpan(String.Empty),
                                        new ExpressionBlock(
                                            new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None),
                                            new ImplicitExpressionSpan("foo.", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true, acceptedCharacters: AcceptedCharacters.NonWhiteSpace)
                                            ),
                                        new CodeSpan(String.Empty),
                                        new MetaCodeSpan("}", hidden: false, acceptedCharacters: AcceptedCharacters.None)),
                                    new MarkupSpan(String.Empty)));
        }
        public void CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans()
        {
            // Arrange
            using (
                RazorEditorParser parser = new RazorEditorParser(
                    CreateHost(),
                    TestLinePragmaFileName
                    )
                )
            {
                ITextBuffer original = new StringTextBuffer("Foo @bar Baz");
                ITextBuffer changed  = new StringTextBuffer("Foo @bap Daz");
                TextChange  change   = new TextChange(7, 3, original, 3, changed);

                using (ManualResetEventSlim parseComplete = new ManualResetEventSlim())
                {
                    int parseCount = 0;
                    parser.DocumentParseComplete += (sender, args) =>
                    {
                        Interlocked.Increment(ref parseCount);
                        parseComplete.Set();
                    };

                    Assert.Equal(
                        PartialParseResult.Rejected,
                        parser.CheckForStructureChanges(
                            new TextChange(0, 0, new StringTextBuffer(String.Empty), 12, original)
                            )
                        );
                    MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait); // Wait for the parse to finish
                    parseComplete.Reset();

                    // Act
                    PartialParseResult result = parser.CheckForStructureChanges(change);

                    // Assert
                    Assert.Equal(PartialParseResult.Rejected, result);
                    MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
                    Assert.Equal(2, parseCount);
                }
            }
        }
Esempio n. 26
0
        public void ImplicitExpressionRejectsWholeIdentifierReplacementToKeyword()
        {
            // Arrange
            RazorEngineHost   host   = CreateHost();
            RazorEditorParser parser = new RazorEditorParser(host, @"C:\This\Is\A\Test\Path");

            TestParserManager manager    = new TestParserManager(parser);
            StringTextBuffer  old        = new StringTextBuffer("foo @date baz");
            StringTextBuffer  changed    = new StringTextBuffer("foo @if baz");
            TextChange        textChange = new TextChange(5, 4, old, 2, changed);

            manager.InitializeWithDocument(old);

            // Act
            PartialParseResult result = manager.CheckForStructureChangesAndWait(textChange);

            // Assert
            Assert.Equal(PartialParseResult.Rejected, result);
            Assert.Equal(2, manager.ParseCount);
        }
        public void TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent()
        {
            var   factory  = SpanFactory.CreateCsHtml();
            Block original = new MarkupBlock(
                factory.Markup("<p>"),
                new ExpressionBlock(factory.CodeTransition()),
                factory.Markup("</p>")
                );
            Block modified = new MarkupBlock(
                factory.Markup("<p>"),
                new ExpressionBlock(
                    factory.CodeTransition("@"),
                    factory
                    .Code("f")
                    .AsImplicitExpression(
                        CSharpCodeParser.DefaultKeywords,
                        acceptTrailingDot: false
                        )
                    ),
                factory.Markup("</p>")
                );
            ITextBuffer oldBuffer = new StringTextBuffer("<p>@</p>");
            ITextBuffer newBuffer = new StringTextBuffer("<p>@f</p>");

            Assert.True(
                BackgroundParser.TreesAreDifferent(
                    original,
                    modified,
                    new[]
            {
                new TextChange(
                    position: 4,
                    oldLength: 0,
                    oldBuffer: oldBuffer,
                    newLength: 1,
                    newBuffer: newBuffer
                    )
            }
                    )
                );
        }
        public void CheckForStructureChangesStartsReparseAndFiresDocumentParseCompletedEventIfNoAdditionalChangesQueued()
        {
            // Arrange
            using (RazorEditorParser parser = CreateClientParser())
            {
                StringTextBuffer input = new StringTextBuffer(SimpleCSHTMLDocument.ReadAllText());

                DocumentParseCompleteEventArgs capturedArgs = null;
                using (ManualResetEventSlim parseComplete = new ManualResetEventSlim(false))
                {
                    parser.DocumentParseComplete += (sender, args) =>
                    {
                        capturedArgs = args;
                        parseComplete.Set();
                    };

                    // Act
                    parser.CheckForStructureChanges(
                        new TextChange(
                            0,
                            0,
                            new StringTextBuffer(String.Empty),
                            input.Length,
                            input
                            )
                        );

                    // Assert
                    MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);

                    string generatedCode =
                        capturedArgs.GeneratorResults.GeneratedCode.GenerateCode <CSharpCodeProvider>();

                    Assert.Equal(
                        SimpleCSHTMLDocumentGenerated.ReadAllText(),
                        MiscUtils.StripRuntimeVersion(generatedCode)
                        );
                }
            }
        }
        public void ImplicitExpressionAcceptsAdditionalIdentifierStartCharactersIfEndOfSpanIsDot()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("@Code @foo.b End Code");
            StringTextBuffer old     = new StringTextBuffer("@Code @foo. End Code");

            RunPartialParseTest(new TextChange(11, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("Code").Accepts(AcceptedCharacters.None),
                                        factory.Code(" ").AsStatement(),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code("foo.b")
                                            .AsImplicitExpression(VBCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                        factory.Code(" ").AsStatement(),
                                        factory.MetaCode("End Code").Accepts(AcceptedCharacters.None)),
                                    factory.EmptyHtml()));
        }
        public void ImplicitExpressionAcceptsDotIfTrailingDotsAreAllowed()
        {
            var factory = SpanFactory.CreateCsHtml();
            StringTextBuffer changed = new StringTextBuffer("@{@foo.}");
            StringTextBuffer old     = new StringTextBuffer("@{@foo}");

            RunPartialParseTest(new TextChange(6, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("{").Accepts(AcceptedCharacters.None),
                                        factory.EmptyCSharp().AsStatement(),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code("foo.")
                                            .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                        factory.EmptyCSharp().AsStatement(),
                                        factory.MetaCode("}").Accepts(AcceptedCharacters.None)),
                                    factory.EmptyHtml()));
        }