예제 #1
0
 public void EmptyTest()
 {
     Prims.Empty <Char, Char>()
     .Run("inputString".AsStream())
     .Case(
         failure: (restStream, errorMessage) =>
         Assert.Fail(),
         success: (restStream, value) =>
     {
         Assert.True(Enumerable.Equals(value, Enumerable.Empty <Char>()));
         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);
     });
 }
예제 #2
0
        public void AppendTest()
        {
            Prims.Empty <Char, Char>()
            .Append(Chars.Char('f'))
            .Append(Chars.Char('o'))
            .Append(Chars.Char('o'))
            .Run("foo".AsStream())
            .Case(
                failure: (restStream, errorMessage) =>
                Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "foo"));
                Assert.False(restStream.Current.HasValue);
            });

            Prims.Empty <Char, Char>()
            .Append(Chars.Char('f'))
            .Append(Chars.Char('o').Optional())
            .Append(Chars.Char('o'))
            .Run("foo".AsStream())
            .Case(
                failure: (restStream, errorMessage) =>
                Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "foo"));
                Assert.False(restStream.Current.HasValue);
            });

            Prims.Empty <Char, Char>()
            .Append(Chars.Char('f'))
            .Append(Chars.Char('X').Optional())
            .Append(Chars.Char('o'))
            .Run("foo".AsStream())
            .Case(
                failure: (restStream, errorMessage) =>
                Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "fo"));
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual('o', restStream.Current.Value.Item0);
            });

            Prims.Empty <Char, Char>()
            .Append(Chars.Char('f'))
            .Append(Chars.Char('X'))
            .Append(Chars.Char('o'))
            .Run("foo".AsStream())
            .Case(
                failure: (restStream, errorMessage) =>
            {
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual('o', restStream.Current.Value.Item0);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(2, restStream.Current.Value.Item1.Column);
            },
                success: (restStream, value) => Assert.Fail());

            Prims.Empty <Char, Char>()
            .Append(Chars.Char('f'))
            .Append(Chars.Char('o').Optional())
            .Append(Chars.Char('o'))
            .Append(Prims.Empty <Char, Char>()
                    .Append(Chars.Char('b'))
                    .Append(Chars.Char('a'))
                    .Append(Chars.Char('r')))
            .Run("foobar".AsStream())
            .Case(
                failure: (restStream, errorMessage) =>
                Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "foobar"));
                Assert.False(restStream.Current.HasValue);
            });

            Prims.Empty <Char, Char>()
            .Append(Chars.Char('f'))
            .Append(Chars.Char('o').Optional())
            .Append(Chars.Char('o'))
            .Append(Prims.Empty <Char, Char>()
                    .Append(Chars.Char('b'))
                    .Append(Chars.Char('X'))
                    .Append(Chars.Char('r'))
                    .Optional())
            .Run("foobar".AsStream())
            .Case(
                failure: (restStream, errorMessage) =>
                Assert.Fail(),
                success: (restStream, value) =>
            {
                Assert.True(Enumerable.SequenceEqual(value, "foo"));
                Assert.True(restStream.Current.HasValue);
                Assert.AreEqual('b', restStream.Current.Value.Item0);
                Assert.AreEqual(1, restStream.Current.Value.Item1.Line);
                Assert.AreEqual(4, restStream.Current.Value.Item1.Column);
            });
        }