static void AddSubnodes(BBTag[] allowedTags, SyntaxTreeNode node) { int count = PexChoose.ValueFromRange("count", 0, 3); bool lastWasText = false; for (int i = 0; i < count; i++) { var subNode = CreateNode(allowedTags, !lastWasText); lastWasText = subNode is TextNode; node.SubNodes.Add(subNode); } }
public static Dictionary <int, int> createDictionaryArrays([PexAssumeNotNull] int[] keys, int max) { PexAssume.AreDistinctValues(keys); PexAssume.IsTrue(max > 0); PexAssume.IsTrue(keys.Length <= 5 || keys.Length > 5); //PexAssume.TrueForAll(pairs, p => (p.Key > -11 && p.Key < 11) && (p.Value > -11 && p.Value < 11)); //DataStructures.Utility.Int32EqualityComparer comparer = new DataStructures.Utility.Int32EqualityComparer(); Dictionary.Dictionary <int, int> ret = new Dictionary.Dictionary <int, int>();// DataStructure has big enough capacity for Commutativity Test for (int i = 0; i < keys.Length; i++) { ret.Add(keys[i], PexChoose.ValueFromRange("value", 0, max)); } return(ret); }
public static HashSet.HashSet <int> CreateChoose(int min, int max) { //PexAssume.IsTrue(elems != null && elems.Length < 11); //PexAssume.AreDistinctValues(elems); //PexChoose. PexAssume.IsTrue(min <= 0 || min > 0); PexAssume.IsTrue(max <= 0 || max > 0); HashSet.HashSet <int> ret = new HashSet.HashSet <int>();// DataStructure has big enough capacity for Commutativity Test //for (int i = 0; i < elems.Length; i++) //{ //PexAssume.IsTrue(elems[i] > -101 && elems[i] < 101); // For stack, add any element. //if(!ret.Contains(elems[i])) ret.Add(PexChoose.ValueFromRange("elements", min, max)); //} return(ret); }
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); } }
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)); }