当前位置: 首页>>代码示例>>C#>>正文


C# TestUtils.StringTextBuffer类代码示例

本文整理汇总了C#中System.Web.WebPages.TestUtils.StringTextBuffer的典型用法代码示例。如果您正苦于以下问题:C# StringTextBuffer类的具体用法?C# StringTextBuffer怎么用?C# StringTextBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringTextBuffer类属于System.Web.WebPages.TestUtils命名空间,在下文中一共展示了StringTextBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans

        public void CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans() {
            // Arrange
            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);

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

            Assert.AreEqual(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.AreEqual(PartialParseResult.Rejected, result);
            MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
            Assert.AreEqual(2, parseCount);
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:26,代码来源:RazorEditorParserTest.cs

示例2: TreesAreDifferentReturnsFalseIfTreeStructureIsSame

 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)
         }));
 }
开发者ID:billwaddyjr,项目名称:Razor,代码行数:27,代码来源:RazorEditorParserTest.cs

示例3: RunParseTest

        internal virtual void RunParseTest(string document, Func<ParserBase, Action> parserActionSelector, Block expectedRoot, IList<RazorError> expectedErrors, bool designTimeParser) {
            // Create the source
            using (StringTextBuffer reader = new StringTextBuffer(document)) {
                ParserResults results = null;
                try {
                    ParserBase codeParser = CreateCodeParser();
                    MarkupParser markupParser = CreateMarkupParser();
                    SyntaxTreeBuilderVisitor listener = new SyntaxTreeBuilderVisitor();
                    ParserContext context = CreateParserRun(new TextBufferReader(reader), codeParser, markupParser, listener);
                    context.DesignTimeMode = designTimeParser;

                    codeParser.Context = context;
                    markupParser.Context = context;

                    // Run the parser
                    parserActionSelector(context.ActiveParser)();
                    context.OnComplete();

                    // Collect the results
                    results = listener.Results;
                    EvaluateResults(TestContext, results, expectedRoot, expectedErrors);
                }
                finally {
                    if (TestContext != null && results != null && results.Document != null) {
                        TestContext.WriteLine(String.Empty);
                        TestContext.WriteLine("Actual Parse Tree:");
                        WriteNode(0, TestContext, results.Document);
                    }
                }
            }
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:31,代码来源:ParserTestBase.cs

示例4: TreesAreDifferentReturnsFalseForAddedContent

        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);
        }
开发者ID:huoxudong125,项目名称:Razor,代码行数:58,代码来源:RazorEditorParserTest.cs

示例5: SpanWithAcceptTrailingDotOffProvisionallyAcceptsEndReplacementWithTrailingDot

        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);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:13,代码来源:ImplciitExpressionSpanTest.cs

示例6: SpanWithAcceptTrailingDotOnAcceptsIntelliSenseReplaceWhichActuallyInsertsDot

        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);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:13,代码来源:ImplciitExpressionSpanTest.cs

示例7: TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent

 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)
         }));
 }
开发者ID:KennyBu,项目名称:Razor,代码行数:22,代码来源:RazorEditorParserTest.cs

示例8: CheckForStructureChangesStartsReparseAndFiresDocumentParseCompletedEventIfNoAdditionalChangesQueued

        public void CheckForStructureChangesStartsReparseAndFiresDocumentParseCompletedEventIfNoAdditionalChangesQueued() {
            // Arrange
            using (RazorEditorParser parser = CreateClientParser()) {
                StringTextBuffer input = new StringTextBuffer(SimpleCSHTMLDocument.ReadAllText());

                DocumentParseCompleteEventArgs capturedArgs = null;
                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);
                Assert.AreEqual(SimpleCSHTMLDocumentGenerated.ReadAllText(),
                                MiscUtils.StripRuntimeVersion(
                                    capturedArgs.GeneratorResults.GeneratedCode.GenerateCode<CSharpCodeProvider>()
                                ));
            }
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:24,代码来源:RazorEditorParserTest.cs

示例9: NormalizeDoesntAffectShrinkingReplacements

        public void NormalizeDoesntAffectShrinkingReplacements()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("D");
            var oldBuffer = new StringTextBuffer("DateTime");
            var original = new TextChange(0, 8, oldBuffer, 1, newBuffer);

            // Act
            TextChange normalized = original.Normalize();

            // Assert
            Assert.Equal(original, normalized);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:13,代码来源:TextChangeTest.cs

示例10: NormalizeDoesntAffectChangesWithoutCommonPrefixes

        public void NormalizeDoesntAffectChangesWithoutCommonPrefixes()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("DateTime.");
            var oldBuffer = new StringTextBuffer("Date.");
            var original = new TextChange(0, 5, oldBuffer, 9, newBuffer);

            // Act
            TextChange normalized = original.Normalize();

            // Assert
            Assert.Equal(original, normalized);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:13,代码来源:TextChangeTest.cs

示例11: NormalizeFixesUpIntelliSenseStyleReplacements

        public void NormalizeFixesUpIntelliSenseStyleReplacements()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("Date.");
            var oldBuffer = new StringTextBuffer("Date");
            var original = new TextChange(0, 4, oldBuffer, 5, newBuffer);

            // Act
            TextChange normalized = original.Normalize();

            // Assert
            Assert.Equal(new TextChange(4, 0, oldBuffer, 1, newBuffer), normalized);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:13,代码来源:TextChangeTest.cs

示例12: ApplyChangeWithReplacedTextReturnsNewContentWithChangeApplied

        public void ApplyChangeWithReplacedTextReturnsNewContentWithChangeApplied()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("abcdefg");
            var oldBuffer = new StringTextBuffer("");
            var textChange = new TextChange(1, 1, oldBuffer, 2, newBuffer);

            // Act
            string text = textChange.ApplyChange("abcdefg", 1);

            // Assert
            Assert.Equal("bcbcdefg", text);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:13,代码来源:TextChangeTest.cs

示例13: NewTextWithReplaceReturnsChangedTextFromBuffer

        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);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:15,代码来源:TextChangeTest.cs

示例14: NewTextWithDeleteReturnsEmptyString

        public void NewTextWithDeleteReturnsEmptyString()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("test");
            var oldBuffer = new StringTextBuffer("");
            var textChange = new TextChange(1, 1, oldBuffer, 0, newBuffer);

            // Act
            string text = textChange.NewText;

            // Assert
            Assert.Equal(String.Empty, text);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:13,代码来源:TextChangeTest.cs

示例15: NewTextWithInsertReturnsChangedTextFromBuffer

        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);
        }
开发者ID:KennyBu,项目名称:Razor,代码行数:15,代码来源:TextChangeTest.cs


注:本文中的System.Web.WebPages.TestUtils.StringTextBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。