Exemplo n.º 1
0
        public void ReplaceTextSpans_WhenEverythingIsConvertedToX_OutputContainsOnlyX_CheckedWithContains()
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, txt.Length, new TextNode("x")), }, null);

            Assert.True(!tree2.ToBBCode().Contains("a"));
        }
Exemplo n.º 2
0
        public void ReplaceTextSpans_WhenEverythingIsConvertedToX_OutputContainsOnlyX_CheckedWithTreeWalk()
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, txt.Length, new TextNode("x")), }, null);

            new TextAssertVisitor(str => Assert.True(str == "x")).Visit(tree2);
        }
Exemplo n.º 3
0
        public void ReplaceTextSpans_WhenNoModifications_TreeIsPreserved()
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new TextSpanReplaceInfo[0], null);

            Assert.Same(tree1, tree2);
        }
Exemplo n.º 4
0
        public void ReplaceTextSpans_WhenEmptyModifications_TreeIsPreserved()
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, 0, null), }, null);

            Assert.Equal(tree1.ToBBCode(), tree2.ToBBCode());
        }
        public void ContentTransformer_EmptyAttribute_CanChooseValueFromAttributeRenderingContext()
        {
            var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.Strict, true, BBTagClosingStyle.AutoCloseElement, false);

            Assert.Equal(@"<a href=""http://codekicker.de"">http://codekicker.de</a>", parser.ToHtml(@"[url2]http://codekicker.de[/url2]"));
            Assert.Equal(@"<a href=""http://codekicker.de"">http://codekicker.de</a>", parser.ToHtml(@"[url2=http://codekicker.de]http://codekicker.de[/url2]"));
        }
Exemplo n.º 6
0
        static void ReplaceTextSpans_ManualTestCases_TestCase(string bbCode, string expected, Func <string, IList <TextSpanReplaceInfo> > getTextSpansToReplace, Func <TagNode, bool> tagFilter)
        {
            var tree1 = BBCodeTestUtil.GetParserForTest(ErrorMode.Strict, false, BBTagClosingStyle.AutoCloseElement, false).ParseSyntaxTree(bbCode);
            var tree2 = BBCode.ReplaceTextSpans(tree1, getTextSpansToReplace ?? (txt => new TextSpanReplaceInfo[0]), tagFilter);

            Assert.Equal(expected, tree2.ToBBCode());
        }
Exemplo n.º 7
0
        public void DefaultVisitorModifiesNothing()
        {
            var tree  = BBCodeTestUtil.GetAnyTree();
            var tree2 = new SyntaxTreeVisitor().Visit(tree);

            Assert.True(ReferenceEquals(tree, tree2));
        }
Exemplo n.º 8
0
        public void TextModifiedTreesAreNotEqual()
        {
            var tree  = BBCodeTestUtil.GetAnyTree();
            var tree2 = new TextModificationSyntaxTreeVisitor().Visit(tree);

            Assert.True(tree != tree2);
        }
        public void CorrectingErrorMode()
        {
            Assert.True(BBCodeTestUtil.IsValid(@"", ErrorMode.TryErrorCorrection));
            Assert.True(BBCodeTestUtil.IsValid(@"[b]abc[/b]", ErrorMode.TryErrorCorrection));
            Assert.True(BBCodeTestUtil.IsValid(@"[b]abc", ErrorMode.TryErrorCorrection));

            Assert.Equal(@"\", BBEncodeForTest(@"\", ErrorMode.TryErrorCorrection));
            Assert.Equal(@"\x", BBEncodeForTest(@"\x", ErrorMode.TryErrorCorrection));
            Assert.Equal(@"\", BBEncodeForTest(@"\\", ErrorMode.TryErrorCorrection));
        }
 public void StrictErrorMode()
 {
     Assert.True(BBCodeTestUtil.IsValid(@"", ErrorMode.Strict));
     Assert.True(BBCodeTestUtil.IsValid(@"[b]abc[/b]", ErrorMode.Strict));
     Assert.False(BBCodeTestUtil.IsValid(@"[b]abc", ErrorMode.Strict));
     Assert.False(BBCodeTestUtil.IsValid(@"abc[0]def", ErrorMode.Strict));
     Assert.False(BBCodeTestUtil.IsValid(@"\", ErrorMode.Strict));
     Assert.False(BBCodeTestUtil.IsValid(@"\x", ErrorMode.Strict));
     Assert.False(BBCodeTestUtil.IsValid(@"[", ErrorMode.Strict));
     Assert.False(BBCodeTestUtil.IsValid(@"]", ErrorMode.Strict));
 }
 public static string BBEncodeForTest(string bbCode, ErrorMode errorMode, BBTagClosingStyle listItemBbTagClosingStyle, bool enableIterationElementBehavior)
 {
     return(BBCodeTestUtil.GetParserForTest(errorMode, true, listItemBbTagClosingStyle, enableIterationElementBehavior).ToHtml(bbCode).Replace("\r", "").Replace("\n", "<br/>"));
 }