public Property MatchShouldMatchPatternsCorrectly(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            bool matchSuccessful = Match.Create <string, bool>()
                                   .Case(pattern, _ => true)
                                   .Case(Pattern.Any <string>(), _ => false)
                                   .ExecuteOn(value);

            return((matchSuccessful == pattern.Match(value).IsSome).ToProperty());
        }
        public Property MatchToFunctionWithFallthroughShouldNeverReturnNull(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            var result = Match.Create <string, bool>(fallthroughByDefault: true)
                         .Case(pattern, _ => true)
                         .Case(Pattern.Any <string>(), _ => false)
                         .ToFunctionWithFallthrough()(value);

            return((result != null).ToProperty());
        }
        public Property NonStrictMatchShouldMatchPatternsCorrectlyWithNullable(
            Func <string, bool> predicate,
            string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            var matchSuccessful = Match.Create <string, bool?>()
                                  .Case(pattern, _ => true)
                                  .Case(Pattern.Any <string>(), _ => false)
                                  .ExecuteNonStrict(value)
                                  .IfNoneUnsafe(() => null);

            return((matchSuccessful == pattern.Match(value).IsSome).ToProperty());
        }
        public Property NonStrictMatchToFunctionShouldMatchPatternsCorrectly(
            Func <string, bool> predicate,
            string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            bool matchSuccessful = Match.Create <string, bool>()
                                   .Case(pattern, _ => true)
                                   .Case(Pattern.Any <string>(), _ => false)
                                   .ToNonStrictFunction()(value)
                                   .IfNoneUnsafe(() => false);

            return((matchSuccessful == pattern.Match(value).IsSome).ToProperty());
        }
Esempio n. 5
0
        public Property StrictMatchToFunctionWithFallthroughFalseShouldMatchPatternsCorrectly(
            Func <string, bool> predicate,
            string value)
        {
            var pattern    = new SimplePattern <string>(predicate);
            int matchCount = 0;

            int result = Match.Create <string>(fallthroughByDefault: true)
                         .Case(pattern, fallthrough: false, _ => { matchCount++; })
                         .Case(Pattern.Any <string>(), _ => { matchCount++; })
                         .ToStrictFunctionWithFallthrough()(value);

            return((result == 1 && matchCount == 1).ToProperty());
        }
Esempio n. 6
0
        public Property MatchWithFallthroughShouldMatchPatternsCorrectly(Func <string, bool> predicate, string value)
        {
            var pattern    = new SimplePattern <string>(predicate);
            int matchCount = 0;

            int result = Match.Create <string>(fallthroughByDefault: true)
                         .Case(pattern, _ => { matchCount++; })
                         .Case(Pattern.Any <string>(), _ => { matchCount++; })
                         .ExecuteWithFallthrough(value);

            return(pattern.Match(value).IsSome
                ? (result == 2 && matchCount == 2).ToProperty()
                : (result == 1 && matchCount == 1).ToProperty());
        }
        public Property MatchWithFallthroughShouldMatchPatternsCorrectly(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            var result = Match.Create <string, bool>(fallthroughByDefault: true)
                         .Case(pattern, _ => true)
                         .Case(Pattern.Any <string>(), _ => false)
                         .ExecuteWithFallthrough(value);

            var success = new List <bool> {
                true, false
            };
            var failure = new List <bool> {
                false
            };

            return(pattern.Match(value).IsSome
                ? result.SequenceEqual(success).ToProperty()
                : result.SequenceEqual(failure).ToProperty());
        }
        public Property NonStrictMatchToFunctionWithFallthroughTrueShouldMatchPatternsCorrectlyWithNullable(
            Func <string, bool> predicate,
            string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            var result = Match.Create <string, bool?>(fallthroughByDefault: false)
                         .Case(pattern, fallthrough: true, _ => true)
                         .Case(Pattern.Any <string>(), _ => false)
                         .ToNonStrictFunctionWithFallthrough()(value);

            var success = new List <bool?> {
                true, false
            };
            var failure = new List <bool?> {
                false
            };

            return(pattern.Match(value).IsSome
                ? result.SequenceEqual(success).ToProperty()
                : result.SequenceEqual(failure).ToProperty());
        }
 public Property AnyShouldAlwaysSucceed(string x)
 => Pattern.Any <string>().Match(x).IsSome.ToProperty();