Example #1
0
        public void ForCharacteraandStringnullShouldReturnnull()
        {
            var    a      = new IOptional(new Character('a'));
            IMatch actual = a.Match(null);

            Assert.Null(actual.RemainingText());
        }
Example #2
0
        public void ForCharacterMinusandString123ShouldReturntrue()
        {
            var    sign   = new IOptional(new Character('-'));
            IMatch actual = sign.Match("123");

            Assert.True(actual.Succes());
        }
Example #3
0
        public void ForCharacteraandStringnullShouldReturnTrue()
        {
            var    a      = new IOptional(new Character('a'));
            IMatch actual = a.Match(null);

            Assert.True(actual.Succes());
        }
Example #4
0
        public void ForCharacterAAndStringAbcShouldReturnTrue()
        {
            IOptional a      = new IOptional(new Character('a'));
            IMatch    actual = a.Match(Text);

            Assert.True(actual.Succes());
        }
Example #5
0
        public void ForCharacteraandStringEmptyStringShouldReturnEmptyString()
        {
            var    a      = new IOptional(new Character('a'));
            IMatch actual = a.Match(string.Empty);

            Assert.Equal(string.Empty, actual.RemainingText());
        }
Example #6
0
        public void ForCharacteraandStringbcShouldReturnbc()
        {
            var    a      = new IOptional(new Character('a'));
            IMatch actual = a.Match("bc");

            Assert.Equal("bc", actual.RemainingText());
        }
Example #7
0
        public void ForCharacterMinusandStringMinus123ShouldReturn123()
        {
            var    a      = new IOptional(new Character('-'));
            IMatch actual = a.Match("-123");

            Assert.Equal("123", actual.RemainingText());
        }
Example #8
0
 public static TValue GetValue <TValue>(this IOptional <TValue> optional)
 {
     return(optional.Match(
                exists: val => val,
                nothing: () => { throw new Exception("Cannot get value on Nothing"); }));
 }
Example #9
0
 public static Boolean HasValue <TValue>(this IOptional <TValue> optional)
 {
     return(optional.Match(
                exists: val => true,
                nothing: () => false));
 }