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

            var result = Match.Create <string, bool>()
                         .Case(pattern, _ => true)
                         .ExecuteNonStrict(value);

            return((result.IsSome == pattern.Match(value).IsSome).ToProperty());
        }
Пример #2
0
        public Property MatchShouldReturnFalseIfNoMatchFound(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            bool matched = Match.Create <string>()
                           .Case(pattern, _ => { })
                           .ExecuteOn(value);

            return((matched == pattern.Match(value).IsSome).ToProperty());
        }
        public Property NonStrictMatchToFunctionWithFallthroughShouldReturnEmptyListIfNoMatchFound(string value)
        {
            var pattern = new SimplePattern <string>(_ => false);

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

            return(result.SequenceEqual(Enumerable.Empty <bool>()).ToProperty());
        }
Пример #4
0
        public Property MatchToFunctionWithFallthroughShouldReturn0IfNoMatchFound(string value)
        {
            var pattern = new SimplePattern <string>(_ => false);

            int result = Match.Create <string>(fallthroughByDefault: true)
                         .Case(pattern, _ => { })
                         .ToFunctionWithFallthrough()(value);

            return((result == 0).ToProperty());
        }
        public void MatchShouldThrowIfCaseFunctionIsNull(Func <string, bool> predicate)
        {
            var pattern = new SimplePattern <string>(predicate);

            Action action = () =>
                            Match.Create <string, bool>()
                            .Case(pattern, null);

            action.Should().Throw <ArgumentNullException>();
        }
Пример #6
0
        public void StrictMatchWithFallthroughShouldThrowIfNoMatchFound(string value)
        {
            var pattern = new SimplePattern <string>(_ => false);

            Action action = () =>
                            Match.Create <string>(fallthroughByDefault: true)
                            .Case(pattern, _ => { })
                            .ExecuteStrictWithFallthrough(value);

            action.Should().Throw <MatchException>();
        }
        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 void MatchToFunctionWithFallthroughShouldThrowIfNoMatchFound(string value)
        {
            var pattern = new SimplePattern <string>(_ => false);

            Action action = () =>
                            Match.Create <string, bool>(fallthroughByDefault: true)
                            .Case(pattern, _ => true)
                            .ToFunctionWithFallthrough()(value);

            action.Should().Throw <MatchException>();
        }
Пример #10
0
        public void MatchToFunctionShouldNotThrowIfNoMatchFound(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            Action action = () =>
                            Match.Create <string>()
                            .Case(pattern, _ => { })
                            .ToFunction()(value);

            action.Should().NotThrow <MatchException>();
        }
        public void NonStrictMatchShouldNotThrowIfNoMatchFound(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            Action action = () =>
                            Match.Create <string, bool>()
                            .Case(pattern, _ => true)
                            .ExecuteNonStrict(value);

            action.Should().NotThrow <MatchException>();
        }
Пример #12
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());
        }
Пример #13
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 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());
        }
        public void MatchShouldThrowIfNoMatchFound(Func <string, bool> predicate, string value)
        {
            var pattern = new SimplePattern <string>(predicate);

            Action action = () =>
                            Match.Create <string, bool>()
                            .Case(pattern, _ => true)
                            .ExecuteOn(value);

            if (pattern.Match(value).IsSome)
            {
                action.Should().NotThrow <MatchException>();
            }
            else
            {
                action.Should().Throw <MatchException>();
            }
        }
        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());
        }
Пример #19
0
 public Property OperatorAndPatternShouldBeSameAsBothPatterns(SimplePattern <string> pattern1, SimplePattern <string> pattern2, string x)
 => (pattern1.Match(x).IsNone || pattern2.Match(x).IsNone == (pattern1 & pattern2).Match(x).IsNone).ToProperty();
Пример #20
0
 public Property OrPatternShouldBeSameAsEitherPattern(SimplePattern <string> pattern1, SimplePattern <string> pattern2, string x)
 => (pattern1.Match(x).IsSome || pattern2.Match(x).IsSome == pattern1.Or(pattern2).Match(x).IsSome).ToProperty();
Пример #21
0
 public Property OperatorXorPatternShouldBeSameAsExlusiveEitherPattern(SimplePattern <string> pattern1, SimplePattern <string> pattern2, string x)
 => (pattern1.Match(x).IsSome ^ pattern2.Match(x).IsSome == (pattern1 ^ pattern2).Match(x).IsSome).ToProperty();
Пример #22
0
 public Property OperatorNotPatternShouldBeOppositeToPattern(SimplePattern <string> pattern, string x)
 => (pattern.Match(x).IsSome == (~pattern).Match(x).IsNone).ToProperty();
Пример #23
0
        public void SimplePatternConstructorShouldThrowForNull()
        {
            Action action = () => { var _ = new SimplePattern <string>(null); };

            action.Should().Throw <ArgumentNullException>();
        }