Beispiel #1
0
 public void NoScript_AnyInput(ErrorMode errorMode, [PexAssumeNotNull] string input)
 {
     PexAssume.EnumIsDefined(errorMode);
     try
     {
         var output = BBEncodeForTest(input, errorMode);
         PexAssert.IsTrue(!output.Contains("<script"));
     }
     catch (BBCodeParsingException)
     {
         PexAssume.Fail();
     }
 }
Beispiel #2
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 #3
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 #4
0
        static SyntaxTreeNode CreateNode(BBTag[] allowedTags, bool allowText)
        {
            switch (PexChoose.ValueFromRange("type", allowText ? 0 : 1, 2))
            {
            case 0:
                var text = PexChoose.Value <string>("text");
                PexAssume.IsTrue(!String.IsNullOrEmpty(text));
                return(new TextNode(text));

            case 1:
                var tag  = allowedTags[PexChoose.ValueFromRange("tag", 0, allowedTags.Length)];
                var node = new TagNode(tag);

                AddSubnodes(allowedTags, node);

                if (tag.Attributes != null)
                {
                    var selectedIds = new List <string>();
                    foreach (var attr in tag.Attributes)
                    {
                        if (!selectedIds.Contains(attr.ID) && PexChoose.Value <bool>("include"))
                        {
                            var val = PexChoose.Value <string>("val");
                            PexAssume.IsTrue(val != null);
                            PexAssume.IsTrue(val.IndexOfAny("[] ".ToCharArray()) == -1);
                            node.AttributeValues[attr] = val;
                            selectedIds.Add(attr.ID);
                        }
                    }
                }
                return(node);

            default:
                PexAssume.Fail();
                return(null);
            }
        }
Beispiel #5
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);
        }