Esempio n. 1
0
        public MFTestResults RegExpTest_4_RegexpOptions_Test_1_IgnoreCase()
        {
            bool testResult = false;

            Regex regex;

            try
            {
                Log.Comment(" Test RegexOptions.IgnoreCase");
                regex = new Regex("abc(\\w*)");
                Log.Comment("RegexOptions.IgnoreCase abc(\\w*)");
                regex.Options = RegexOptions.IgnoreCase;
                Log.Comment("abc(d*)");
                if (!regex.IsMatch("abcddd"))
                {
                    Log.Comment("Did not match 'abcddd'.");
                    testResult = false;
                }
                else
                {
                    Log.Comment("abcddd = true");
                    TestTestsHelper.ShowParens(ref regex);
                    testResult = true;
                }

                if (!regex.IsMatch("aBcDDdd"))
                {
                    Log.Comment("Did not match 'aBcDDdd'.");
                    testResult = false;
                }
                else
                {
                    Log.Comment("aBcDDdd = true");
                    TestTestsHelper.ShowParens(ref regex);
                    testResult = true;
                }

                if (!regex.IsMatch("ABCDDDDD"))
                {
                    Log.Comment("Did not match 'ABCDDDDD'.");
                    testResult = false;
                }
                else
                {
                    Log.Comment("ABCDDDDD = true");
                    TestTestsHelper.ShowParens(ref regex);
                    testResult = true;
                }

                regex         = new Regex("(A*)b\\1");
                regex.Options = RegexOptions.IgnoreCase;
                if (!regex.IsMatch("AaAaaaBAAAAAA"))
                {
                    Log.Comment("Did not match 'AaAaaaBAAAAAA'.");
                    testResult = false;
                }
                else
                {
                    Log.Comment("AaAaaaBAAAAAA = true");
                    TestTestsHelper.ShowParens(ref regex);
                    testResult = true;
                }

                regex         = new Regex("[A-Z]*");
                regex.Options = RegexOptions.IgnoreCase;
                if (!regex.IsMatch("CaBgDe12"))
                {
                    Log.Comment("Did not match 'CaBgDe12'.");
                    testResult = false;
                }
                else
                {
                    Log.Comment("CaBgDe12 = true");
                    TestTestsHelper.ShowParens(ref regex);
                    testResult = true;
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                testResult = false;
            }

            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Esempio n. 2
0
        public MFTestResults RegExpTest_0_PrecompiledMatch()
        {
            bool testResult = false;

            try
            {
                Log.Comment("Pre-compiled regular expression \"a*b\"");
                char[] re1instructions =
                {
                    (char)0x007c, (char)0x0000, (char)0x001a, (char)0x007c, (char)0x0000, (char)0x000d, (char)0x0041,
                    (char)0x0001, (char)0x0004, (char)0x0061, (char)0x007c, (char)0x0000, (char)0x0003, (char)0x0047,
                    (char)0x0000, (char)0xfff6, (char)0x007c, (char)0x0000, (char)0x0003, (char)0x004e, (char)0x0000,
                    (char)0x0003, (char)0x0041, (char)0x0001, (char)0x0004, (char)0x0062, (char)0x0045, (char)0x0000,
                    (char)0x0000,
                };

                //need to make internals visible to
                RegexProgram re1 = new RegexProgram(re1instructions);

                // Simple test of pre-compiled regular expressions
                Regex r = new Regex(re1);

                Log.Comment("Matching Precompiled Expression a*b");
                testResult = r.IsMatch("aaab");
                Log.Comment("aaab = " + testResult);
                TestTestsHelper.ShowParens(ref r);
                if (!testResult)
                {
                    Log.Comment("\"aaab\" doesn't match to precompiled \"a*b\"");
                }

                testResult = r.IsMatch("b");
                Log.Comment("b = " + testResult);
                TestTestsHelper.ShowParens(ref r);
                if (!testResult)
                {
                    Log.Comment("\"b\" doesn't match to precompiled \"a*b\"");
                }

                testResult = r.IsMatch("c");
                Log.Comment("c = " + testResult);
                TestTestsHelper.ShowParens(ref r);
                if (testResult)
                {
                    Log.Comment("\"c\" matches to precompiled \"a*b\"");
                    testResult = false;
                }

                testResult = r.IsMatch("ccccaaaaab");
                Log.Comment("ccccaaaaab = " + testResult);
                TestTestsHelper.ShowParens(ref r);
                if (!testResult)
                {
                    Log.Comment("\"ccccaaaaab\" doesn't match to precompiled \"a*b\"");
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                testResult = false;
            }

            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }