示例#1
0
        public void regexes_are_single_line_setting_by_default(string regex, string inputString, bool isMatch)
        {
            IMatchingParser subject = new RegularExpression(regex);
            var scanner = new ScanStrings(inputString);
            var result = subject.TryMatch(scanner);

            Assert.That(result.Success, Is.EqualTo(isMatch), "Match result");
        }
示例#2
0
        public void regex_dot_matches_carriage_return_but_not_line_feed()
        {
            IMatchingParser subject = new RegularExpression(@".*");
            var scanner = new ScanStrings("line one\r\nline two");
            var result = subject.TryMatch(scanner);

            Assert.That(result.Value, Contains.Substring("\r"));
        }
示例#3
0
        public void regexes_whose_match_does_not_start_at_the_current_scanner_position_are_failures()
        {
            IMatchingParser subject = new RegularExpression(@"\w+");
            var scanner = new ScanStrings("      some words");

            var result = subject.TryMatch(scanner);

            Assert.That(result.Success, Is.False);
        }
示例#4
0
        public void non_matching_regexes_result_in_failing_parses_and_do_not_advance_the_scanner(string regex, string inputString)
        {
            IMatchingParser subject = new RegularExpression(regex);
            var scanner = new ScanStrings(inputString);
            var result = subject.TryMatch(scanner);

            Assert.That(result.Success, Is.False, "Match result");
            Assert.That(scanner.Offset, Is.EqualTo(0), "Scanner offset");
        }
        public void regular_expression_parser_can_have_Regex_options_set(string inputString, string pattern, RegexOptions options, bool success, string match)
        {
            var subject = new RegularExpression(pattern, options);
            var scanner = new ScanStrings(inputString);
            var result = subject.TryMatch(scanner);

            Assert.That(result.Success, Is.EqualTo(success));
            if (success) Assert.That(result.Value, Is.EqualTo(match));
        }
示例#6
0
        public void regexes_that_can_match_empty_strings_can_return_successful_empty_matches()
        {
            IMatchingParser subject = new RegularExpression(@"\W*");
            var scanner = new ScanStrings("123456");

            var result = subject.TryMatch(scanner);

            Assert.That(result.Success, Is.True);
            Assert.That(result.Value, Is.EqualTo(""));
        }
示例#7
0
        public void matching_regexes_result_in_matching_parses_and_contain_the_match_and_advance_the_scanner(string regex, string inputString, string match)
        {
            IMatchingParser subject = new RegularExpression(regex);
            var scanner = new ScanStrings(inputString);
            var result = subject.TryMatch(scanner);

            Assert.That(result.Success, Is.True, "Match result");
            Assert.That(result.Value, Is.EqualTo(match), "Parser match string");
            Assert.That(scanner.Offset, Is.EqualTo(match.Length), "Scanner offset");
        }