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

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

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

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

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

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

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

            Assert.Equal("123", actual.RemainingText());
        }
示例#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"); }));
 }
示例#9
0
 public static Boolean HasValue <TValue>(this IOptional <TValue> optional)
 {
     return(optional.Match(
                exists: val => true,
                nothing: () => false));
 }