Esempio n. 1
0
        public void ReadSuccess(string input)
        {
            var grammar = new CoreGrammar();

            grammar.Initialize();
            var sut = grammar.Rule("LWSP");

            using (var scanner = new TextScanner(new StringTextSource(input)))
            {
                var result = sut.Read(scanner);
                Assert.Equal(input, result.Text);
            }
        }
Esempio n. 2
0
        public void CanReadUppercaseAsciiLetters(string input)
        {
            var grammar = new CoreGrammar();

            grammar.Initialize();
            var sut = grammar.Rule("ALPHA");

            using (var scanner = new TextScanner(new StringTextSource(input)))
            {
                var result = sut.Read(scanner);
                Assert.Equal(input, result.Text);
            }
        }
Esempio n. 3
0
        public void ReadSuccess(byte input, byte expected)
        {
            var grammar = new CoreGrammar();

            grammar.Initialize();
            var sut = grammar.Rule <Octet>("OCTET");

            using (var stream = new MemoryStream(new[] { input }))
                using (var scanner = new TextScanner(new StreamTextSource(stream)))
                {
                    var result = sut.Read(scanner);
                    Assert.Equal(expected, result.Value);
                }
        }
Esempio n. 4
0
        public void CannotReadNegativeOne()
        {
            var input   = "-1";
            var grammar = new CoreGrammar();

            grammar.Initialize();
            var sut = grammar.Rule("BIT");

            using (var scanner = new TextScanner(new StringTextSource(input)))
            {
                var result = sut.Read(scanner);
                Assert.Null(result);
            }
        }
Esempio n. 5
0
        public void CanReadZero()
        {
            var input   = "0";
            var grammar = new CoreGrammar();

            grammar.Initialize();
            var sut = grammar.Rule("BIT");

            using (var scanner = new TextScanner(new StringTextSource(input)))
            {
                var result = sut.Read(scanner);
                Assert.Equal(input, result.Text);
            }
        }
Esempio n. 6
0
        public void CannotReadPureText()
        {
            // Pretend that we are reading text from a piece of paper instead of from computer memory
            // I call this pure text: the text source is not binary encoded
            // The OCTET rule should not be used with pure text sources, because that just makes no sense
            // For that reason, I changed the OCTET lexer to read nothing unless the text source implements IBinaryDataSource
            var grammar = new CoreGrammar();

            grammar.Initialize();
            var sut = grammar.Rule("OCTET");

            using (var scanner = new TextScanner(new StringTextSource("System.String")))
            {
                var result = sut.Read(scanner);
                Assert.Null(result);
            }
        }