public void ParsingAndPrinting() { IntSet empty = IntSet.Empty, all = IntSet.All; PrintAndParse(empty, "()"); empty.IsCharSet = true; PrintAndParse(empty, "[]"); empty.IsCharSet = false; // design flaw here - mutable property on readonly static field PrintAndParse(all, "~()"); all.IsCharSet = true; PrintAndParse(all, "[^]"); all.IsCharSet = false; // design flaw here - mutable property on readonly static field AreEqual(IntSet.WithCharRanges('a', 'd'), IntSet.Parse("[dacb]")); AreEqual(IntSet.With(1234), IntSet.Parse("(1234)")); AreEqual(IntSet.With(0x1234, '!'), IntSet.Parse("[\u1234!]")); AreEqual(IntSet.With(0x12, '!'), IntSet.Parse("[\x12!]")); IsNull(IntSet.TryParse("(12345678901)")); PrintAndParse(IntSet.WithCharRanges('a', 'd'), "[a-d]"); PrintAndParse(IntSet.WithChars('$', '-', '[', ']'), @"[$\-[\]]"); PrintAndParse(IntSet.WithoutCharRanges(-1, -1, '\n', '\n', '0', '9', '^', '^'), @"[^\$\n0-9^]"); PrintAndParse(IntSet.With(2, 3, 5, 7, 11), "(2..3, 5, 7, 11)"); PrintAndParse(IntSet.WithRanges(int.MinValue, 0), string.Format("({0}..0)", int.MinValue)); PrintAndParse(IntSet.WithoutRanges(1, int.MaxValue), string.Format("~(1..{0})", int.MaxValue)); // See the error? That's really a single backslash; to add backslash to // the set we need another backslash. int errorIndex; var set = IntSet.TryParse("[^\n\\]", out errorIndex); AreEqual(errorIndex, 4); AreEqual(IntSet.WithoutChars('\n', '\\'), IntSet.Parse("[^\n\\\\]")); }
public void BasicTests() { var ac = IntSet.WithCharRanges('A', 'C', '$', '$'); AreEqual(ac, IntSet.With('$', '$', 'A', 'B', 'C')); var ad = IntSet.WithCharRanges('A', 'D'); AreNotEqual(ad, IntSet.WithChars('A', 'B', 'C')); IsTrue(ac.Contains('$') && !ad.Contains('$')); IsTrue(ac.Contains('A') && ad.Contains('A')); IsTrue(ac.Contains('C') && ad.Contains('C')); IsTrue(!ac.Contains('D') && ad.Contains('D')); var ad2 = ac.Union(ad); IsTrue(ad2.Contains('$') && ad2.Contains('D')); CheckRanges(ad2, new IntRange('$'), new IntRange('A', 'D')); var ac2 = ac.Intersection(ad); CheckRanges(ac2, new IntRange('A', 'C')); CheckRanges(ac.Union(IntSet.With('@')), new IntRange('$'), new IntRange('@', 'C')); }