public void TextModifiedTreesAreNotEqual()
        {
            var tree  = BBCodeTestUtil.GetAnyTree();
            var tree2 = new TextModificationSyntaxTreeVisitor().Visit(tree);

            Assert.IsTrue(tree != tree2);
        }
        public void DefaultVisitorModifiesNothing()
        {
            var tree  = BBCodeTestUtil.GetAnyTree();
            var tree2 = new SyntaxTreeVisitor().Visit(tree);

            Assert.IsTrue(ReferenceEquals(tree, tree2));
        }
        public void IdentityModifiedTreesAreEqual()
        {
            var tree  = BBCodeTestUtil.GetAnyTree();
            var tree2 = new IdentitiyModificationSyntaxTreeVisitor().Visit(tree);

            Assert.IsTrue(tree == tree2);
        }
예제 #4
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.IsTrue(str == "x")).Visit(tree2);
        }
예제 #5
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.IsTrue(!tree2.ToBBCode().Contains("a"));
        }
예제 #6
0
        public void ReplaceTextSpans_WhenEmptyModifications_TreeIsPreserved()
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, 0, null), }, null);

            Assert.AreEqual(tree1.ToBBCode(), tree2.ToBBCode());
        }
예제 #7
0
        public void ReplaceTextSpans_WhenNoModifications_TreeIsPreserved()
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new TextSpanReplaceInfo[0], null);

            Assert.AreSame(tree1, tree2);
        }
예제 #8
0
        public void EqualTreesHaveEqualBBCode(out string bbCode1, out string bbCode2)
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCodeTestUtil.GetAnyTree();

            bbCode1 = tree1.ToBBCode();
            bbCode2 = tree2.ToBBCode();
            Assert.AreEqual(tree1 == tree2, bbCode1 == bbCode2);
        }
예제 #9
0
        public void UnequalTexthasUnequalTrees(out string text1, out string text2)
        {
            var tree1 = BBCodeTestUtil.GetAnyTree();
            var tree2 = BBCodeTestUtil.GetAnyTree();

            text1 = tree1.ToText();
            text2 = tree2.ToText();
            if (text1 != text2)
            {
                Assert.IsTrue(tree1 != tree2);
            }
        }
예제 #10
0
        public void ReplaceTextSpans_ArbitraryTextSpans_NoCrash()
        {
            var tree1       = BBCodeTestUtil.GetAnyTree();
            var chosenTexts = new List <string>();
            var tree2       = BBCode.ReplaceTextSpans(tree1, txt =>
            {
                var count   = PexChoose.ValueFromRange("count", 0, 3);
                var indexes = PexChoose.Array <int>("indexes", count);
                PexAssume.TrueForAll(0, count, i => indexes[i] >= 0 && indexes[i] <= txt.Length && (i == 0 || indexes[i - 1] < indexes[i]));
                return
                (Enumerable.Range(0, count)
                 .Select(i =>
                {
                    var maxIndex = i == count - 1 ? txt.Length : indexes[i + 1];
                    var text = PexChoose.ValueNotNull <string>("text");
                    chosenTexts.Add(text);
                    return new TextSpanReplaceInfo(indexes[i], PexChoose.ValueFromRange("count", 0, indexes[i] - maxIndex + 1), new TextNode(text));
                })
                 .ToArray());
            }, null);
            var bbCode = tree2.ToBBCode();

            PexAssert.TrueForAll(chosenTexts, s => bbCode.Contains(s));
        }