Пример #1
0
        public void Regressions()
        {
            IntSet a = IntSet.Parse("[^ \t\r\n\\\\]"), b = IntSet.Parse("[ \t]");

            AreEqual(IntSet.Parse("[^\r\n\\\\]"), b.Union(a));
            AreEqual(IntSet.Parse("[^\r\n\\\\]"), a.Union(b));             // a bug here produced [^]
        }
Пример #2
0
        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\\\\]"));
        }
Пример #3
0
        private void PrintAndParse(IntSet set, string expect)
        {
            string s = set.ToString();

            AreEqual(expect, s);
            AreEqual(IntSet.Parse(expect), set);
        }