Beispiel #1
0
        public void ContentTransformer_EmptyAttribute_CanChooseValueFromAttributeRenderingContext()
        {
            var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.Strict, true, BBTagClosingStyle.AutoCloseElement, false);

            Assert.AreEqual(@"<a href=""http://codekicker.de"">http://codekicker.de</a>", parser.ToHtml(@"[url2]http://codekicker.de[/url2]"));
            Assert.AreEqual(@"<a href=""http://codekicker.de"">http://codekicker.de</a>", parser.ToHtml(@"[url2=http://codekicker.de]http://codekicker.de[/url2]"));
        }
Beispiel #2
0
        public void ToTextDoesNotCrash([PexAssumeNotNull] string input, out string text)
        {
            var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.ErrorFree, true, BBTagClosingStyle.AutoCloseElement, false);

            text = parser.ParseSyntaxTree(input).ToText();
            Assert.IsTrue(text.Length <= input.Length);
        }
Beispiel #3
0
        public void NoScript_AnyInput_Tree()
        {
            var parser = BBCodeTestUtil.GetParserForTest(ErrorMode.ErrorFree, true, BBTagClosingStyle.AutoCloseElement, false);
            var tree   = BBCodeTestUtil.CreateRootNode(parser.Tags.ToArray());
            var output = tree.ToHtml();

            PexAssert.IsTrue(!output.Contains("<script"));
        }
Beispiel #4
0
        public void CorrectingErrorMode()
        {
            Assert.IsTrue(BBCodeTestUtil.IsValid(@"", ErrorMode.TryErrorCorrection));
            Assert.IsTrue(BBCodeTestUtil.IsValid(@"[b]abc[/b]", ErrorMode.TryErrorCorrection));
            Assert.IsTrue(BBCodeTestUtil.IsValid(@"[b]abc", ErrorMode.TryErrorCorrection));

            Assert.AreEqual(@"\", BBEncodeForTest(@"\", ErrorMode.TryErrorCorrection));
            Assert.AreEqual(@"\x", BBEncodeForTest(@"\x", ErrorMode.TryErrorCorrection));
            Assert.AreEqual(@"\", BBEncodeForTest(@"\\", ErrorMode.TryErrorCorrection));
        }
Beispiel #5
0
 public void StrictErrorMode()
 {
     Assert.IsTrue(BBCodeTestUtil.IsValid(@"", ErrorMode.Strict));
     Assert.IsTrue(BBCodeTestUtil.IsValid(@"[b]abc[/b]", ErrorMode.Strict));
     Assert.IsFalse(BBCodeTestUtil.IsValid(@"[b]abc", ErrorMode.Strict));
     Assert.IsFalse(BBCodeTestUtil.IsValid(@"abc[0]def", ErrorMode.Strict));
     Assert.IsFalse(BBCodeTestUtil.IsValid(@"\", ErrorMode.Strict));
     Assert.IsFalse(BBCodeTestUtil.IsValid(@"\x", ErrorMode.Strict));
     Assert.IsFalse(BBCodeTestUtil.IsValid(@"[", ErrorMode.Strict));
     Assert.IsFalse(BBCodeTestUtil.IsValid(@"]", ErrorMode.Strict));
 }
Beispiel #6
0
        public void Roundtrip(ErrorMode errorMode, out string bbcode, out string output)
        {
            PexAssume.EnumIsDefined(errorMode);

            var parser = BBCodeTestUtil.GetParserForTest(errorMode, false, BBTagClosingStyle.AutoCloseElement, false);
            var tree   = BBCodeTestUtil.CreateRootNode(parser.Tags.ToArray());

            bbcode = tree.ToBBCode();
            var tree2 = parser.ParseSyntaxTree(bbcode);

            output = tree2.ToHtml();
            Assert.IsTrue(tree == tree2);
        }
Beispiel #7
0
 public void NoHtmlChars_AnyInput(ErrorMode errorMode, [PexAssumeNotNull] string input)
 {
     PexAssume.EnumIsDefined(errorMode);
     try
     {
         var output = BBCodeTestUtil.SimpleBBEncodeForTest(input, errorMode);
         PexObserve.ValueForViewing("output", output);
         PexAssert.IsTrue(output.IndexOf('<') == -1);
         PexAssert.IsTrue(output.IndexOf('>') == -1);
     }
     catch (BBCodeParsingException)
     {
         PexAssume.Fail();
     }
 }
Beispiel #8
0
        public void TextNodesCannotBeSplit(ErrorMode errorMode, [PexAssumeNotNull] string input)
        {
            PexAssume.EnumIsDefined(errorMode);

            var          parser = BBCodeTestUtil.GetParserForTest(errorMode, true, BBTagClosingStyle.AutoCloseElement, false);
            SequenceNode tree;

            try
            {
                tree = parser.ParseSyntaxTree(input);
            }
#pragma warning disable 168
            catch (BBCodeParsingException e)
#pragma warning restore 168
            {
                PexAssume.Fail();
                return;
            }

            AssertTextNodesNotSplit(tree);
        }
Beispiel #9
0
        public void Roundtrip2(ErrorMode errorMode, [PexAssumeNotNull] string input, out string bbcode, out string output)
        {
            PexAssume.EnumIsDefined(errorMode);

            var          parser = BBCodeTestUtil.GetParserForTest(errorMode, false, BBTagClosingStyle.AutoCloseElement, false);
            SequenceNode tree;

            try
            {
                tree = parser.ParseSyntaxTree(input);
            }
#pragma warning disable 168
            catch (BBCodeParsingException e)
#pragma warning restore 168
            {
                PexAssume.Fail();
                tree = null;
            }

            bbcode = tree.ToBBCode();
            var tree2 = parser.ParseSyntaxTree(bbcode);
            output = tree2.ToHtml();
            Assert.IsTrue(tree == tree2);
        }
Beispiel #10
0
 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/>"));
 }