Ejemplo n.º 1
0
        public void RegexTransform2()
        {
            string e = @"^
        ([a-zA-Z][-+.a-zA-Z\d]*):                     (?# 1: scheme)
        (?:
           ((?:[-_.!~*'()a-zA-Z\d;?:@&=+$,]|%[a-fA-F\d]{2})(?:[-_.!~*'()a-zA-Z\d;/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*)              (?# 2: opaque)
        |
           (?:(?:
             //(?:
                 (?:(?:((?:[-_.!~*'()a-zA-Z\d;:&=+$,]|%[a-fA-F\d]{2})*)@)?  (?# 3: userinfo)
                   (?:((?:(?:(?:[a-zA-Z\d](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-fA-F\d]{1,4}:)*[a-fA-F\d]{1,4})?::(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)\]))(?::(\d*))?))?(?# 4: host, 5: port)
               |
                 ((?:[-_.!~*'()a-zA-Z\d$,;+@&=+]|%[a-fA-F\d]{2})+)           (?# 6: registry)
               )
             |
             (?!//))                              (?# XXX: '//' is the mark for hostport)
             (/(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*)*(?:/(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*)*)*)?              (?# 7: path)
           )(?:\?((?:[-_.!~*'()a-zA-Z\d;/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*))?           (?# 8: query)
        )
        (?:\#((?:[-_.!~*'()a-zA-Z\d;/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*))?            (?# 9: fragment)
      $";
            bool   hasGAnchor;
            string t = RegexpTransformer.Transform(e, RubyRegexOptions.Extended | RubyRegexOptions.Multiline, out hasGAnchor);

            Assert(e == t);
            Assert(!hasGAnchor);
            new Regex(t);
        }
Ejemplo n.º 2
0
        //[DebuggerHidden]
        private void TestCorrectPatternTranslation(string /*!*/ pattern, RubyRegexOptions options, string /*!*/ expected, bool expectedGAnchor)
        {
            bool   hasGAnchor;
            string actual = RegexpTransformer.Transform(pattern, options, out hasGAnchor);

            AreEqual(expected, actual);
            new Regex(expected);
            Assert(hasGAnchor == expectedGAnchor);
        }
Ejemplo n.º 3
0
        //[DebuggerHidden]
        private void TestCorrectPatternTranslation(string /*!*/ pattern, RubyRegexOptions options, string /*!*/ expected, bool expectedGAnchor, IList <string> expectedWarnings)
        {
            bool          hasGAnchor;
            List <string> warnings;
            string        actual = RegexpTransformer.Transform(pattern, options, out hasGAnchor, out warnings);

            AreEqual(expected, actual);
            new Regex(expected);
            Assert(hasGAnchor == expectedGAnchor);
            if (warnings != null)
            {
                Assert(expectedWarnings != null);
                Assert(expectedWarnings.Count == warnings.Count);
                foreach (var warning in expectedWarnings)
                {
                    Assert(warnings.IndexOf(warning) >= 0);
                }
            }
            else
            {
                Assert(expectedWarnings == null || expectedWarnings.Count == 0);
            }
        }
Ejemplo n.º 4
0
        public void RegexTransform1()
        {
            string[] incorrectPatterns = new string[] {
                @"\",
                @"\",

                @"\\\",
                @"\\\",

                @"\x",
                @"\x",

                @"\1", // TODO
                @"\1",
            };

            string[] correctPatterns = new string[] {
                @"",
                @"",

                @"\\",
                @"\\",

                @"\_",
                @"_",

                @"abc\0\01\011\a\sabc\Wabc\w",
                @"abc\0\01\011\a\sabc\Wabc\w",

                @"\xd",
                @"\x0d",

                @"\xdz",
                @"\x0dz",

                @"\*",
                @"\*",

                @"\[",
                @"\[",

                @"\#",
                @"\#",

                @"\0",
                @"\0",

                @"[a\-z]",
                @"[a\-z]",
            };

            string[] correctPatternsWithG = new string[] {
                @"\G",
                @"\G",
            };

            for (int i = 0; i < incorrectPatterns.Length; i += 2)
            {
                bool   hasGAnchor;
                string expected = incorrectPatterns[i + 1];
                string actual   = RegexpTransformer.Transform(incorrectPatterns[i], RubyRegexOptions.NONE, out hasGAnchor);
                AreEqual(expected, actual);
            }

            for (int i = 0; i < correctPatterns.Length; i += 2)
            {
                TestCorrectPatternTranslation(correctPatterns[i], correctPatterns[i + 1], false);
            }

            for (int i = 0; i < correctPatternsWithG.Length; i += 2)
            {
                TestCorrectPatternTranslation(correctPatternsWithG[i], correctPatternsWithG[i + 1], true);
            }
        }