Ejemplo n.º 1
0
        public void SepBy0Test()
        {
            Combinator.SepBy0(
                Parser.Fail <Char, Char>("Failure"),
                Parser.Fail <Char, Unit>("Failure"))
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.False(value.Any());
            });

            Combinator.SepBy0(
                Chars.Any(),
                Chars.Char(',').Ignore())
            .Run("i,n,p,u,t,S,t,r,i,n,g".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "inputString"));
                Assert.False(restStream.Current.HasValue);
            });

            Combinator.SepBy0(
                Chars.Any(),
                Chars.Char(',').Ignore())
            .Run("i,n,p,u,t,S,t,r,i,n,g,".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "inputString"));
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual(',', restStream.Current.Value.Item0);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(22, restStream.Current.Value.Item1.Column);
            });
        }