Ejemplo n.º 1
0
        public void MatchesToNamedGroupsDictionaries_Throws_FormatException_When_Named_Groups_Are_Absent()
        {
            var input   = "Hello";
            var pattern = ".";

            var ex = Should.Throw <FormatException>(() => RegexUtility.MatchesToNamedGroupsDictionaries(input, pattern));
        }
Ejemplo n.º 2
0
        public void MatchesToNamedGroupsDictionaries_Accepts_RegexOptions_To_Ignore_Case()
        {
            var input   = "Hello, World!";
            var pattern = @"(?<Greeting>heLlO), (?<Subject>\w+)!";

            Dictionary <string, string> result = RegexUtility.MatchesToNamedGroupsDictionaries(input, pattern, RegexOptions.IgnoreCase).Single();

            result["Greeting"].ShouldBe("Hello");
            result["Subject"].ShouldBe("World");
        }
Ejemplo n.º 3
0
        public void MatchesToNamedGroupsDictionaries_Returns_Expected_Result()
        {
            var input   = "123-456-7890 hello 098-765-4321";
            var pattern = @"(?<AreaCode>\d{3})-(?<First>\d{3})-(?<Last>\d{4})";

            string[] groupNames = new[] { "AreaCode", "First", "Last" };

            Dictionary <string, string>[] results = RegexUtility.MatchesToNamedGroupsDictionaries(input, pattern);

            results.Length.ShouldBe(2);
            results[0].Keys.Count.ShouldBe(groupNames.Length);
            results[1][groupNames[0]].ShouldBe("098");
            results[1][groupNames[1]].ShouldBe("765");
            results[1][groupNames[2]].ShouldBe("4321");
        }