Beispiel #1
0
        public void OptionalTest()
        {
            Combinator.Optional(Chars.Any())
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, optionalValue) =>
            {
                Assert.True(optionalValue.HasValue);
                Assert.AreEqual('i', optionalValue.Value);
            });

            Combinator.Optional(Chars.Any())
            .Run("".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, optionalValue) =>
            {
                Assert.False(optionalValue.HasValue);
            });

            Combinator.Optional(Combinator.Sequence("inpXtString".Select(Chars.Char)))
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, optionalValue) =>
            {
                Assert.False(optionalValue.HasValue);
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual('i', restStream.Current.Value.Item0);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Column);
            });
        }