public void TagHelperTagBodiesRejectPartialChanges(object objectEdit) { // Arrange var edit = (TestEdit)objectEdit; var builder = TagHelperDescriptorBuilder.Create("PTagHelper", "TestAssembly"); builder.SetTypeName("PTagHelper"); builder.TagMatchingRule(rule => rule.TagName = "p"); var descriptors = new[] { builder.Build() }; var templateEngine = CreateTemplateEngine(tagHelpers: descriptors); var document = TestRazorCodeDocument.Create( TestRazorSourceDocument.Create(edit.OldSnapshot.GetText()), new[] { templateEngine.Options.DefaultImports }); templateEngine.Engine.Process(document); var syntaxTree = document.GetSyntaxTree(); var parser = new RazorSyntaxTreePartialParser(syntaxTree); // Act var result = parser.Parse(edit.Change); // Assert Assert.Equal(PartialParseResultInternal.Rejected, result); }
private void RunPartialParseRejectionTest(TestEdit edit, PartialParseResultInternal additionalFlags = 0) { var templateEngine = CreateTemplateEngine(); var document = TestRazorCodeDocument.Create(edit.OldSnapshot.GetText()); templateEngine.Engine.Process(document); var syntaxTree = document.GetSyntaxTree(); var parser = new RazorSyntaxTreePartialParser(syntaxTree); var result = parser.Parse(edit.Change); Assert.Equal(PartialParseResultInternal.Rejected | additionalFlags, result); }
private static void RunPartialParseTest(TestEdit edit, Block expectedTree, PartialParseResultInternal additionalFlags = 0) { var templateEngine = CreateTemplateEngine(); var document = TestRazorCodeDocument.Create(edit.OldSnapshot.GetText()); templateEngine.Engine.Process(document); var syntaxTree = document.GetSyntaxTree(); var parser = new RazorSyntaxTreePartialParser(syntaxTree); var result = parser.Parse(edit.Change); Assert.Equal(PartialParseResultInternal.Accepted | additionalFlags, result); ParserTestBase.EvaluateParseTree(expectedTree, syntaxTree.Root); }
private void OnResultsReady(object sender, DocumentStructureChangedEventArgs args) { _dispatcher.AssertBackgroundThread(); if (DocumentStructureChanged != null) { if (args.Snapshot != _textBuffer.CurrentSnapshot) { // A different text change is being parsed. return; } CodeDocument = args.CodeDocument; Snapshot = args.Snapshot; _partialParser = new RazorSyntaxTreePartialParser(CodeDocument.GetSyntaxTree()); DocumentStructureChanged(this, args); } }
public void TagHelperAttributesAreLocatedAndAcceptChangesCorrectly(object editObject, object partialParseResultObject) { // Arrange var edit = (TestEdit)editObject; var partialParseResult = (PartialParseResultInternal)partialParseResultObject; var builder = TagHelperDescriptorBuilder.Create("PTagHelper", "Test"); builder.SetTypeName("PTagHelper"); builder.TagMatchingRule(rule => rule.TagName = "p"); builder.BindAttribute(attribute => { attribute.Name = "obj-attr"; attribute.TypeName = typeof(object).FullName; attribute.SetPropertyName("ObjectAttribute"); }); builder.BindAttribute(attribute => { attribute.Name = "str-attr"; attribute.TypeName = typeof(string).FullName; attribute.SetPropertyName("StringAttribute"); }); var descriptors = new[] { builder.Build() }; var templateEngine = CreateTemplateEngine(tagHelpers: descriptors); var document = TestRazorCodeDocument.Create( TestRazorSourceDocument.Create(edit.OldSnapshot.GetText()), new[] { templateEngine.Options.DefaultImports }); templateEngine.Engine.Process(document); var syntaxTree = document.GetSyntaxTree(); var parser = new RazorSyntaxTreePartialParser(syntaxTree); // Act var result = parser.Parse(edit.Change); // Assert Assert.Equal(partialParseResult, result); }