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

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

            ILookup <string, string> result = RegexUtility.MatchesToNamedGroupsLookup(input, pattern, RegexOptions.IgnoreCase);

            result["Greeting"].ShouldContain("Hello");
            result["Greeting"].ShouldContain("hi");
        }
Ejemplo n.º 3
0
        public void MatchesToNamedGroupsLookup_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" };

            ILookup <string, string> result = RegexUtility.MatchesToNamedGroupsLookup(input, pattern);

            result.Count.ShouldBe(groupNames.Length);
            result[groupNames[0]].Count().ShouldBe(2);
            result[groupNames[1]].ShouldContain("456");
            result[groupNames[2]].ShouldContain("4321");
        }