Example #1
0
        public void MoveNextLineReturnsLine()
        {
            string text = "This is a line \\ \r\nAnd this is next";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text), new string[] { }, false);

            Assert.AreEqual("This", parser.PeekNextToken());
            Assert.AreEqual("This is a line \\ ", parser.MoveToNextLine());
            Assert.AreEqual("And", parser.PeekNextToken());
        }
Example #2
0
        public void PeekIsRepeatable()
        {
            string text = "&& ||";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text),
                                                                   new string[] { "&&", "||" }, true);

            Assert.AreEqual("&&", parser.PeekNextToken());
            Assert.AreEqual("&&", parser.PeekNextToken());
            Assert.AreEqual("&&", parser.PeekNextToken());
        }
Example #3
0
        public void NewlineIsConsumed()
        {
            string text = "else\r\n" +
                          "}\r\n}";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text),
                                                                   new string[] { }, true);

            Assert.AreEqual("else", parser.PeekNextToken());
            Assert.AreEqual("else", parser.NextToken());
            Assert.AreEqual("}", parser.PeekNextToken());
            Assert.AreEqual("}", parser.NextToken());
            Assert.AreEqual("}", parser.PeekNextToken());
            Assert.AreEqual("}", parser.NextToken());
        }
Example #4
0
        public void WhiteSpacesAreConsumed()
        {
            string text = "&& \r\n text ::{";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text),
                                                                   new string[] { "&&", "::", "{", " " }, true);

            Assert.AreEqual("&&", parser.PeekNextToken());
            Assert.AreEqual("&&", parser.NextToken());
            Assert.AreEqual("text", parser.PeekNextToken());
            Assert.AreEqual("text", parser.NextToken());
            Assert.AreEqual("::", parser.PeekNextToken());
            Assert.AreEqual("::", parser.NextToken());
            Assert.AreEqual("{", parser.PeekNextToken());
            Assert.AreEqual("{", parser.NextToken());
        }
Example #5
0
        public void EmptyStringThrows()
        {
            string text = "";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text),
                                                                   new string[] { }, true);

            parser.PeekNextToken();
        }
Example #6
0
        public void OneTokenOnly()
        {
            string text = "text";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text),
                                                                   new string[] { }, true);

            Assert.AreEqual("text", parser.PeekNextToken());
            Assert.AreEqual("text", parser.NextToken());
        }
Example #7
0
        public void MoveToNextLine()
        {
            string text = "&& || somecrap \r\n" +
                          "text";

            LookAheadTokenParser parser = new LookAheadTokenParser(TestUtil.GetTextStream(text),
                                                                   new string[] { "&&", "||" }, true);

            Assert.AreEqual("&&", parser.NextToken());
            Assert.AreEqual("||", parser.NextToken());

            parser.MoveToNextLine();

            Assert.AreEqual("text", parser.PeekNextToken());
        }