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); }
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 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")); }
public void ReplaceTextSpans_WhenNoModifications_TreeIsPreserved() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new TextSpanReplaceInfo[0], null); Assert.Same(tree1, tree2); }
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()); }
public void ReplaceTextSpans_ArbitraryTextSpans_NoCrash() { for (int i = 0; i < RandomValue.Int(100, 10); i++) { var tree1 = BBCodeTestUtil.GetAnyTree(); var chosenTexts = new List <string>(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => { var count = RandomValue.Int(3, 0); var indexes = new List <int>(); for (int i = 0; i < count; i++) { indexes.Add(RandomValue.Int(txt.Length, 0)); } indexes.Sort(); _output.WriteLine(string.Join(", ", indexes)); return (Enumerable.Range(0, count) .Select(i => { var maxIndex = i == count - 1 ? txt.Length : indexes[i + 1]; var text = RandomValue.String(); chosenTexts.Add(text); return new TextSpanReplaceInfo(indexes[i], RandomValue.Int(indexes[i] - maxIndex + 1, 0), new TextNode(text)); }) .ToArray()); }, null); var bbCode = tree2.ToBBCode(); if (!chosenTexts.All(s => bbCode.Contains(s))) { } Assert.All(chosenTexts, s => Assert.Contains(s, bbCode)); } }
public void ReplaceTextSpans_WhenNoModifications_TreeIsPreserved() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => Array.Empty <TextSpanReplaceInfo>(), null); Assert.Equal(tree1, tree2); }
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)); }