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())); }
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 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())); }
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."); } }
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())); }