public void FlattenFlattensStartAndEndTagTagHelpers() { // Arrange var spanFactory = SpanFactory.CreateCsHtml(); var blockFactory = new BlockFactory(spanFactory); var tagHelper = (TagHelperBlock)blockFactory.TagHelperBlock( tagName: "div", tagMode: TagMode.StartTagAndEndTag, start: SourceLocation.Zero, startTag: blockFactory.MarkupTagBlock("<div>"), children: new SyntaxTreeNode[0], endTag: blockFactory.MarkupTagBlock("</div>")); spanFactory.Reset(); var expectedStartTag = spanFactory.Markup("<div>"); var expectedEndTag = spanFactory.Markup("</div>"); // Act var flattenedNodes = tagHelper.Flatten(); // Assert Assert.Collection( flattenedNodes, first => { Assert.True(first.EquivalentTo(expectedStartTag)); }, second => { Assert.True(second.EquivalentTo(expectedEndTag)); }); }
public static void RunMultiAtEscapeTest( Action <string, Block> testMethod, AcceptedCharacters lastSpanAcceptedCharacters = AcceptedCharacters.None ) { var factory = SpanFactory.CreateCsHtml(); testMethod( "<foo>@@@@@bar</foo>", new MarkupBlock( factory.Markup("<foo>"), factory.Markup("@").Hidden(), factory.Markup("@"), factory.Markup("@").Hidden(), factory.Markup("@"), new ExpressionBlock( factory.CodeTransition(), factory .Code("bar") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharacters.NonWhiteSpace) ), factory.Markup("</foo>").Accepts(lastSpanAcceptedCharacters) ) ); }
public void ImplicitExpressionProvisionallyAcceptsDotlessCommitInsertions() { SpanFactory factory = SpanFactory.CreateCsHtml(); var changed = new StringTextBuffer("foo @DateT. baz"); var old = new StringTextBuffer("foo @DateT baz"); var textChange = new TextChange(10, 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.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, "DateT."); old = changed; changed = new StringTextBuffer("foo @DateTime. baz"); textChange = new TextChange(10, 0, old, 3, changed); applyAndVerifyPartialChange(textChange, PartialParseResult.Accepted | PartialParseResult.Provisional, "DateTime."); }
public void ImplicitExpressionAcceptsAdditionalIdentifierStartCharactersIfEndOfSpanIsDot() { var factory = SpanFactory.CreateCsHtml(); StringTextBuffer changed = new StringTextBuffer("@{@foo.b}"); StringTextBuffer old = new StringTextBuffer("@{@foo.}"); RunPartialParseTest( new TextChange(7, 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.b") .AsImplicitExpression( CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true ) .Accepts(AcceptedCharacters.NonWhiteSpace) ), factory.EmptyCSharp().AsStatement(), factory.MetaCode("}").Accepts(AcceptedCharacters.None) ), factory.EmptyHtml() ) ); }
public void TreesAreDifferentReturnsFalseIfTreeStructureIsSame() { var factory = SpanFactory.CreateCsHtml(); var original = new MarkupBlock( factory.Markup("<p>"), new ExpressionBlock( factory.CodeTransition(), factory.Code("f") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)), factory.Markup("</p>")); factory.Reset(); var modified = new MarkupBlock( factory.Markup("<p>"), new ExpressionBlock( factory.CodeTransition(), factory.Code("foo") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)), factory.Markup("</p>")); original.LinkNodes(); modified.LinkNodes(); var oldBuffer = new StringTextBuffer("<p>@f</p>"); var newBuffer = new StringTextBuffer("<p>@foo</p>"); Assert.False(BackgroundParser.TreesAreDifferent( original, modified, new[] { new TextChange(position: 5, oldLength: 0, oldBuffer: oldBuffer, newLength: 2, newBuffer: newBuffer) })); }
public void AddLiteralChunk_AppendsToPreviousChunk_IfChunkWasLiteral() { // Arrange var spanFactory = SpanFactory.CreateCsHtml(); var previousSpan = spanFactory.Markup("<a>").Builder.Build(); var newSpan = spanFactory.Markup("<p>").Builder.Build(); var builder = new ChunkTreeBuilder(); // Act builder.AddLiteralChunk("<a>", previousSpan); builder.AddLiteralChunk("<p>", newSpan); // Assert var chunk = Assert.Single(builder.Root.Children); var literalChunk = Assert.IsType <ParentLiteralChunk>(chunk); Assert.Equal(2, literalChunk.Children.Count); var span = Assert.IsType <Span>(literalChunk.Children[0].Association); Assert.Same(span, previousSpan); span = Assert.IsType <Span>(literalChunk.Children[1].Association); Assert.Same(span, newSpan); }
public void ParseMethodUsesProvidedParserListenerIfSpecified() { var factory = SpanFactory.CreateCsHtml(); // Arrange RazorParser parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); // Act ParserResults results = parser.Parse(new StringReader("foo @bar baz")); // Assert ParserTestBase.EvaluateResults( results, new MarkupBlock( factory.Markup("foo "), new ExpressionBlock( factory.CodeTransition(), factory .Code("bar") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharacters.NonWhiteSpace) ), factory.Markup(" baz") ) ); }
public async Task CreateParseTask_ReturnsWithoutThrowingIfTaskIsCancelled() { // Arrange var factory = SpanFactory.CreateCsHtml(); var visitor = new Mock <ParserVisitor> { CallBase = true }; var parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); var cancelTokenSource = new CancellationTokenSource(); var visited = false; // Act var task = parser.CreateParseTask( new StringReader("foo @bar baz"), (span) => { visited = true; Assert.Equal("foo ", span.Content); cancelTokenSource.Cancel(); }, errorCallback: null, cancelToken: cancelTokenSource.Token ); task.Start(); await task; // Assert Assert.True(visited); }
public void ImplicitExpressionAcceptsDotAtEndOfNonWhitespaceCharacters() { var factory = SpanFactory.CreateCsHtml(); StringTextBuffer changed = new StringTextBuffer(@"@{ @foo. }"); StringTextBuffer old = new StringTextBuffer(@"@{ @foo }"); RunPartialParseTest(new TextChange(12, 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(@"foo.") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true) .Accepts(AcceptedCharacters.NonWhiteSpace)), factory.Code("\r\n").AsStatement(), factory.MetaCode("}").Accepts(AcceptedCharacters.None)), factory.EmptyHtml())); }
public void ImplicitExpressionAcceptsIdentifierTypedAfterDotIfLastChangeWasProvisionalAcceptanceOfDot() { var factory = SpanFactory.CreateCsHtml(); // Arrange TextChange dotTyped = new TextChange(8, 0, new StringTextBuffer("foo @foo bar"), 1, new StringTextBuffer("foo @foo. bar")); TextChange charTyped = new TextChange(9, 0, new StringTextBuffer("foo @foo. bar"), 1, new StringTextBuffer("foo @foo.b bar")); using (TestParserManager manager = CreateParserManager()) { manager.InitializeWithDocument(dotTyped.OldBuffer); // Apply the dot change Assert.Equal(PartialParseResult.Provisional | PartialParseResult.Accepted, manager.CheckForStructureChangesAndWait(dotTyped)); // Act (apply the identifier start char change) PartialParseResult result = manager.CheckForStructureChangesAndWait(charTyped); // Assert Assert.Equal(PartialParseResult.Accepted, result); Assert.False(manager.Parser.LastResultProvisional, "LastResultProvisional flag should have been cleared but it was not"); ParserTestBase.EvaluateParseTree(manager.Parser.CurrentParseTree, new MarkupBlock( factory.Markup("foo "), new ExpressionBlock( factory.CodeTransition(), factory.Code("foo.b") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharacters.NonWhiteSpace)), factory.Markup(" bar"))); } }
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 = SpanFactory.CreateCsHtml(); var changed = new StringTextBuffer("@{" + Environment.NewLine + " @foo." + Environment.NewLine + "}"); var old = new StringTextBuffer("@{" + Environment.NewLine + " @foo" + Environment.NewLine + "}"); RunPartialParseTest(new TextChange(10 + Environment.NewLine.Length, 0, old, 1, changed), new MarkupBlock( factory.EmptyHtml(), new StatementBlock( factory.CodeTransition(), factory.MetaCode("{").Accepts(AcceptedCharacters.None), factory.Code(Environment.NewLine + " ") .AsStatement() .AutoCompleteWith(autoCompleteString: null), new ExpressionBlock( factory.CodeTransition(), factory.Code(@"foo.") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true) .Accepts(AcceptedCharacters.NonWhiteSpace)), factory.Code(Environment.NewLine).AsStatement(), factory.MetaCode("}").Accepts(AcceptedCharacters.None)), factory.EmptyHtml())); }
public void AddSpanAddsSpanToCurrentBlockBuilder() { // Arrange var factory = SpanFactory.CreateCsHtml(); Mock <ParserVisitor> mockListener = new Mock <ParserVisitor>(); var context = SetupTestContext("phoo"); var builder = new SpanBuilder() { Kind = SpanKind.Code }; builder.Accept(new CSharpSymbol(1, 0, 1, "foo", CSharpSymbolType.Identifier)); var added = builder.Build(); using (context.StartBlock(BlockType.Functions)) { context.AddSpan(added); } var expected = new BlockBuilder() { Type = BlockType.Functions, }; expected.Children.Add(added); // Assert ParserTestBase.EvaluateResults(context.CompleteParse(), expected.Build()); }
public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block() { // Arrange var factory = SpanFactory.CreateCsHtml(); Block start = new MarkupBlock( factory.Markup("test"), new ExpressionBlock( factory.Code(" ").AsExpression(), factory.CodeTransition(SyntaxConstants.TransitionString), factory.Code("foo").AsExpression() ), factory.Markup("test") ); WhiteSpaceRewriter rewriter = new WhiteSpaceRewriter(new HtmlMarkupParser().BuildSpan); // Act Block actual = rewriter.Rewrite(start); factory.Reset(); // Assert ParserTestBase.EvaluateParseTree(actual, new MarkupBlock( factory.Markup("test"), factory.Markup(" "), new ExpressionBlock( factory.CodeTransition(SyntaxConstants.TransitionString), factory.Code("foo").AsExpression() ), factory.Markup("test") )); }
public void ParseModelKeyword_ErrorOnMissingModelType() { // Arrange + Act List <RazorError> errors = new List <RazorError>(); var document = "@model "; var spans = ParseDocument(document, errors); // Assert var factory = SpanFactory.CreateCsHtml(); var expectedSpans = new Span[] { factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code(" ") .As(new SetModelTypeCodeGenerator(String.Empty, "{0}<{1}>")), }; var expectedErrors = new[] { new RazorError("The 'model' keyword must be followed by a type name on the same line.", new SourceLocation(9, 0, 9), 1) }; Assert.Equal(expectedSpans, spans.ToArray()); Assert.Equal(expectedErrors, errors.ToArray()); }
public async Task CreateParseTask_ParsesDocumentAndInvokesVisitor() { // Arrange var factory = SpanFactory.CreateCsHtml(); var visitor = new Mock <ParserVisitor> { CallBase = true }; var parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); // Act var task = parser.CreateParseTask(new StringReader("foo @bar baz"), visitor.Object); task.Start(); await task; // Assert visitor.Verify( v => v.VisitSpan(It.Is <Span>(s => s.Kind == SpanKind.Markup && s.Content == "foo ")) ); visitor.Verify( v => v.VisitSpan(It.Is <Span>(s => s.Kind == SpanKind.Transition && s.Content == "@")) ); visitor.Verify( v => v.VisitSpan(It.Is <Span>(s => s.Kind == SpanKind.Code && s.Content == "bar")) ); visitor.Verify( v => v.VisitSpan(It.Is <Span>(s => s.Kind == SpanKind.Markup && s.Content == " baz")) ); }
public void AddLiteralChunk_AddsChunkToChunkTree_IfPreviousChunkWasNotLiteral() { // Arrange var spanFactory = SpanFactory.CreateCsHtml(); var codeSpan = spanFactory.Code("int a = 10;") .AsStatement() .Builder.Build(); var literalSpan = spanFactory.Markup("<p>").Builder.Build(); var builder = new ChunkTreeBuilder(); // Act builder.AddStatementChunk("int a = 10;", codeSpan); builder.AddLiteralChunk("<p>", literalSpan); // Assert var chunks = builder.Root.Children; Assert.Equal(2, chunks.Count); var statementChunk = Assert.IsType <StatementChunk>(chunks[0]); Assert.Equal("int a = 10;", statementChunk.Code); Assert.Same(codeSpan, statementChunk.Association); var literalChunk = Assert.IsType <LiteralChunk>(chunks[1]); Assert.Equal("<p>", literalChunk.Text); Assert.Same(literalSpan, literalChunk.Association); }
public void AddLiteralChunk_CreatesNewChunk_IfChunkIsNotLiteral() { // Arrange var spanFactory = SpanFactory.CreateCsHtml(); var span1 = spanFactory.Markup("<a>").Builder.Build(); var span2 = spanFactory.Markup("<p>").Builder.Build(); var span3 = spanFactory.Code("Hi!").AsExpression().Builder.Build(); var builder = new ChunkTreeBuilder(); // Act builder.AddLiteralChunk("<a>", span1); builder.AddLiteralChunk("<p>", span2); builder.AddExpressionChunk("Hi!", span3); // Assert Assert.Equal(2, builder.Root.Children.Count); var literalChunk = Assert.IsType <ParentLiteralChunk>(builder.Root.Children[0]); Assert.Equal(2, literalChunk.Children.Count); var span = Assert.IsType <Span>(literalChunk.Children[0].Association); Assert.Same(span, span1); span = Assert.IsType <Span>(literalChunk.Children[1].Association); Assert.Same(span, span2); Assert.IsType <ExpressionChunk>(builder.Root.Children[1]); }
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 void TreesAreDifferentReturnsFalseForAddedContent(string content) { // Arrange var factory = SpanFactory.CreateCsHtml(); var blockFactory = new BlockFactory(factory); var original = new MarkupBlock( blockFactory.MarkupTagBlock("<p>"), blockFactory.TagHelperBlock( tagName: "div", tagMode: TagMode.StartTagAndEndTag, start: new SourceLocation(3, 0, 3), startTag: blockFactory.MarkupTagBlock("<div>"), children: new SyntaxTreeNode[] { factory.Markup($"{Environment.NewLine}{Environment.NewLine}") }, endTag: blockFactory.MarkupTagBlock("</div>")), blockFactory.MarkupTagBlock("</p>")); factory.Reset(); var modified = new MarkupBlock( blockFactory.MarkupTagBlock("<p>"), blockFactory.TagHelperBlock( tagName: "div", tagMode: TagMode.StartTagAndEndTag, start: new SourceLocation(3, 0, 3), startTag: blockFactory.MarkupTagBlock("<div>"), children: new SyntaxTreeNode[] { factory.Markup($"{Environment.NewLine}{content}{Environment.NewLine}") }, endTag: blockFactory.MarkupTagBlock("</div>")), blockFactory.MarkupTagBlock("</p>")); original.LinkNodes(); modified.LinkNodes(); var oldBuffer = new StringTextBuffer($"<p><div>{Environment.NewLine}{Environment.NewLine}</div></p>"); var newBuffer = new StringTextBuffer( $"<p><div>{Environment.NewLine}{content}{Environment.NewLine}</div></p>"); // Act var treesAreDifferent = BackgroundParser.TreesAreDifferent( original, modified, new[] { new TextChange( position: 8 + Environment.NewLine.Length, oldLength: 0, oldBuffer: oldBuffer, newLength: content.Length, newBuffer: newBuffer) }); // Assert Assert.False(treesAreDifferent); }
public static void RunSingleAtEscapeTest(Action<string, Block> testMethod, AcceptedCharacters lastSpanAcceptedCharacters = AcceptedCharacters.None) { var factory = SpanFactory.CreateCsHtml(); testMethod("<foo>@@bar</foo>", new MarkupBlock( factory.Markup("<foo>"), factory.Markup("@").Hidden(), factory.Markup("@bar</foo>").Accepts(lastSpanAcceptedCharacters))); }
public void ImplicitExpressionAcceptsMultipleInsertionIfItOnlyCausesIdentifierExpansion() { var factory = SpanFactory.CreateCsHtml(); StringTextBuffer changed = new StringTextBuffer("foo @barbiz baz"); StringTextBuffer 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"))); }
public void ImplicitExpressionAcceptsDeleteOfIdentifierPartsIfSomeOfIdentifierRemains() { var factory = SpanFactory.CreateCsHtml(); StringTextBuffer changed = new StringTextBuffer("foo @Us baz"); StringTextBuffer 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"))); }
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); }
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"))); }
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 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 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 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); }