예제 #1
0
        //[TestMethod]
        public void TestIgnoreCaseTransformer()
        {
            CharSetSolver         solver = new CharSetSolver();
            int                   t      = System.Environment.TickCount;
            IgnoreCaseTransformer ic     = new IgnoreCaseTransformer(solver);

            //simple test first:
            //BDD a2c = solver.MkRangeConstraint('a', 'c');
            //BDD a2cA2C = ic.Apply(a2c);
            //BDD a2cA2C_expected = a2c.Or(solver.MkRangeConstraint('A', 'C'));
            //Assert.AreEqual<BDD>(a2cA2C, a2cA2C_expected);
            //
            //comprehensive test:
            //
            //test that the whole array is correct:
            // Microsoft.Automata.Generated.IgnoreCaseRelation.ignorecase
            //  (generated by:)
            //
            // IgnoreCaseRelationGenerator.Generate(
            //    "Microsoft.Automata.Generated",
            //    "IgnoreCaseRelation",
            //    @"C:\GitHub\AutomataDotNet\Automata\src\Automata\Internal\Generated");
            //
            //test that all characters in it are truly equivalent wrt the igore-case option of regex
            //
            for (int i = 0; i <= 0xFFFF; i++)
            {
                char c = (char)i;
                if (ic.IsInDomain(c))
                {
                    BDD cC = ic.Apply(solver.MkCharConstraint(c));
                    foreach (char d in solver.GenerateAllCharacters(cC))
                    {
                        Assert.IsTrue(Regex.IsMatch(d.ToString(), "^(?i:" + StringUtility.Escape(c) + ")$"));
                    }
                }
            }
            //
            //second, test that all characters outside the domain are only equivalent (up-to-case) to themsevles
            //
            // for some reson this does not succeed, ??? some characters, e.g. '\xF7', are
            // equivalent to some other characters in the below test, but not when tested individually
            // there is a bug in Regex.IsMatch with ignore-case combined with intervals
            //
            //for (int i = 2; i <= 0xFFFD; i++)
            //{
            //    char c = (char)i;
            //    if (!ic.IsInDomain(c))
            //    {
            //        if (Regex.IsMatch(c.ToString(), @"^([\0-" + StringUtility.Escape((char)(i - 1)) + StringUtility.Escape((char)(i + 1)) + @"-\uFFFF])$", RegexOptions.IgnoreCase))
            //            Console.WriteLine(StringUtility.Escape(c));
            //    }
            //}
        }
예제 #2
0
        public void TestIgnoreCaseTransformer_SimpleCases()
        {
            CharSetSolver         solver = new CharSetSolver();
            int                   t      = System.Environment.TickCount;
            IgnoreCaseTransformer ic     = new IgnoreCaseTransformer(solver);
            //simple test first:
            BDD a2c             = solver.MkRangeConstraint('a', 'c');
            BDD a2cA2C          = ic.Apply(a2c);
            BDD a2cA2C_expected = a2c.Or(solver.MkRangeConstraint('A', 'C'));

            Assert.AreEqual <BDD>(a2cA2C, a2cA2C_expected);
            //digits are not changed
            BDD ascii_digits  = solver.MkRangeConstraint('0', '9');
            BDD ascii_digits1 = ic.Apply(ascii_digits);

            Assert.AreEqual <BDD>(ascii_digits1, ascii_digits);
            var tt       = ic.Apply(solver.True);
            var tt_compl = solver.MkNot(tt);

            Assert.AreEqual <BDD>(ic.Apply(solver.True), solver.True);
        }
예제 #3
0
 /// <summary>Initialize the solver.</summary>
 /// <remarks>Consumers should use the singleton <see cref="Instance"/>.</remarks>
 private CharSetSolver()
 {
     _nonAscii   = CreateCharSetFromRange('\x80', '\uFFFF');
     _ignoreCase = new IgnoreCaseTransformer(this); // do this last in ctor, as IgnoreCaseTransform's ctor uses `this`
 }