public void RejectsEmptyInput()
 {
     AssertHelpers.FailAt(
         Parse.Byte(0x01).Once(),
         new byte[0],
         0);
 }
 public void ParsesThreeBytesInputWithMany()
 {
     AssertHelpers.Success(Parse.Byte(0x01).Many(), new byte[3] {
         0x01, 0x01, 0x01
     }, new byte[3] {
         0x01, 0x01, 0x01
     });
 }
        public void ParseUntilStopsOnTerminator()
        {
            var parser =
                from a in Parse.Byte().Until(Parse.Byte(0x00))
                select a;

            AssertHelpers.Success(parser, new byte[] { 0x31, 0x2e, 0x00 }, new byte[] { 0x31, 0x2e });
        }
        public void AcceptsByte()
        {
            var parser = Parse.Byte(0x01).Once();

            AssertHelpers.Success(
                parser,
                new byte[] { 0x01 },
                new byte[] { 0x01 });
        }
        public void RejectsWrongByte()
        {
            var parser = Parse.Byte(0x01).Once();

            AssertHelpers.FailAt(
                parser,
                new byte[] { 0x02 },
                0);
        }
        public void FailsIfParserTriesToReadMoreThanLengthBytes()
        {
            var parser =
                from a in Parse.Sequence(0x01, 0x01, 0x01).Length(2)
                from b in Parse.Byte(0x02).Once()
                select a.Concat(b);

            AssertHelpers.FailAt(parser, new byte[] { 0x01, 0x01, 0x01, 0xFF, 0x02 }, 2);
        }
        public void AcceptsBytesWithLength()
        {
            var parser =
                from a in Parse.Byte(0x01).Length(2).Once()
                from b in Parse.Byte(0x02).Once()
                select a.Concat(b);

            AssertHelpers.Success(parser, new byte[] { 0x01, 0xFF, 0x02 }, new byte[] { 0x01, 0x02 });
        }
        public void ParserWithXManyFailsWithWrongLastElement()
        {
            var parser =
                from a in Parse.Byte(0x01).Once()
                from b in Parse.Byte(0x02).Once()
                select a.Concat(b);

            AssertHelpers.FailAt(parser.Many().End(), new byte[5] {
                0x01, 0x02, 0x01, 0x02, 0x03
            }, 4);
        }
 public void ParsesEmtpyInputWithMany()
 {
     AssertHelpers.Success(Parse.Byte(0x01).Many(), new byte[0], new byte[0]);
 }
Exemple #10
0
        public void ConcatsResults()
        {
            var parser = Parse.Byte(0x01).Once().Then(a => Parse.Byte(0x02).Once().Select(b => a.Concat(b)));

            AssertHelpers.Success(parser, new byte[] { 0x01, 0x02 }, new byte[] { 0x01, 0x02 });
        }
Exemple #11
0
 public void ManyFailsWithWrongLastElement()
 {
     AssertHelpers.FailAt(Parse.Byte(0x01).Many().End(), new byte[3] {
         0x01, 0x01, 0x02
     }, 2);
 }
 //String
 public static byte ToByte(string data)
 {
     return(Parse.Byte(data));
 }