コード例 #1
0
ファイル: Combinator.Test.cs プロジェクト: Zaid-Ajaj/parseq
        public void RepeatTest()
        {
            Combinator.Repeat(Parser.Fail <Char, Char>("Failure"), 0)
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, _) => { /* OK */ });

            Combinator.Repeat(Chars.Any(), 5)
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) => Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "input"));
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual('S', restStream.Current.Value.Item0);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(6, restStream.Current.Value.Item1.Column);
            });

            Combinator.Repeat(Chars.Any(), 12)
            .Run("inputString".AsStream())
            .Case(
                failure: (restStream, _) =>
            {
                Assert.False(restStream.Current.HasValue);
            },
                success: (restStream, value) => Assert.Fail());
        }