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)); }