Example #1
0
        public void TestResetOnANTLRStringStream()
        {
            ANTLRStringStream stream = new ANTLRStringStream("One\r\nTwo");

            Assert.AreEqual(0, stream.Index);
            Assert.AreEqual(0, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Consume();                           // O
            stream.Consume();                           // n

            Assert.AreEqual('e', stream.LA(1));
            Assert.AreEqual(2, stream.Index);

            stream.Reset();
            Assert.AreEqual('O', stream.LA(1));
            Assert.AreEqual(0, stream.Index);
            Assert.AreEqual(0, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);
            stream.Consume();                           // O

            Assert.AreEqual('n', stream.LA(1));
            Assert.AreEqual(1, stream.Index);
            Assert.AreEqual(1, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);
            stream.Consume();                           // n

            Assert.AreEqual('e', stream.LA(1));
            Assert.AreEqual(2, stream.Index);
            Assert.AreEqual(2, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);
            stream.Consume();                           // e
        }
Example #2
0
        public void TestConsumeOnANTLRStringStream()
        {
            ANTLRStringStream stream = new ANTLRStringStream("One\r\nTwo");

            Assert.AreEqual(0, stream.Index);
            Assert.AreEqual(0, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Consume();                           // O
            Assert.AreEqual(1, stream.Index);
            Assert.AreEqual(1, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Consume();                           // n
            Assert.AreEqual(2, stream.Index);
            Assert.AreEqual(2, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Consume();                           // e
            Assert.AreEqual(3, stream.Index);
            Assert.AreEqual(3, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Consume();                           // \r
            Assert.AreEqual(4, stream.Index);
            Assert.AreEqual(4, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Consume();                           // \n
            Assert.AreEqual(5, stream.Index);
            Assert.AreEqual(0, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);

            stream.Consume();                           // T
            Assert.AreEqual(6, stream.Index);
            Assert.AreEqual(1, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);

            stream.Consume();                           // w
            Assert.AreEqual(7, stream.Index);
            Assert.AreEqual(2, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);

            stream.Consume();                           // o
            Assert.AreEqual(8, stream.Index);
            Assert.AreEqual(3, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);

            stream.Consume();                           // EOF
            Assert.AreEqual(8, stream.Index);
            Assert.AreEqual(3, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);

            stream.Consume();                           // EOF
            Assert.AreEqual(8, stream.Index);
            Assert.AreEqual(3, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);
        }
Example #3
0
        public void TestSubstringOnANTLRStringStream()
        {
            ANTLRStringStream stream = new ANTLRStringStream("One\r\nTwo\r\nThree");

            Assert.AreEqual("Two", stream.Substring(5, 7));
            Assert.AreEqual("One", stream.Substring(0, 2));
            Assert.AreEqual("Three", stream.Substring(10, 14));

            stream.Consume();

            Assert.AreEqual("Two", stream.Substring(5, 7));
            Assert.AreEqual("One", stream.Substring(0, 2));
            Assert.AreEqual("Three", stream.Substring(10, 14));
        }
Example #4
0
 public void Consume()
 {
     stream.Consume();
 }
		public void TestSubstringOnANTLRStringStream()
		{
			ANTLRStringStream stream = new ANTLRStringStream("One\r\nTwo\r\nThree");

			Assert.AreEqual("Two", stream.Substring(5, 7));
			Assert.AreEqual("One", stream.Substring(0, 2));
			Assert.AreEqual("Three", stream.Substring(10, 14));

			stream.Consume();

			Assert.AreEqual("Two", stream.Substring(5, 7));
			Assert.AreEqual("One", stream.Substring(0, 2));
			Assert.AreEqual("Three", stream.Substring(10, 14));
		}
		public void TestResetOnANTLRStringStream()
		{
			ANTLRStringStream stream = new ANTLRStringStream("One\r\nTwo");
			Assert.AreEqual(0, stream.Index());
			Assert.AreEqual(0, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Consume();		// O
			stream.Consume();		// n

			Assert.AreEqual('e', stream.LA(1));
			Assert.AreEqual(2, stream.Index());

			stream.Reset();
			Assert.AreEqual('O', stream.LA(1));
			Assert.AreEqual(0, stream.Index());
			Assert.AreEqual(0, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);
			stream.Consume();		// O

			Assert.AreEqual('n', stream.LA(1));
			Assert.AreEqual(1, stream.Index());
			Assert.AreEqual(1, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);
			stream.Consume();		// n

			Assert.AreEqual('e', stream.LA(1));
			Assert.AreEqual(2, stream.Index());
			Assert.AreEqual(2, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);
			stream.Consume();		// e
		}
		public void TestConsumeOnANTLRStringStream()
		{
			ANTLRStringStream stream = new ANTLRStringStream("One\r\nTwo");
			Assert.AreEqual(0, stream.Index());
			Assert.AreEqual(0, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Consume();		// O
			Assert.AreEqual(1, stream.Index());
			Assert.AreEqual(1, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Consume();		// n
			Assert.AreEqual(2, stream.Index());
			Assert.AreEqual(2, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Consume();		// e
			Assert.AreEqual(3, stream.Index());
			Assert.AreEqual(3, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Consume();		// \r
			Assert.AreEqual(4, stream.Index());
			Assert.AreEqual(4, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Consume();		// \n
			Assert.AreEqual(5, stream.Index());
			Assert.AreEqual(0, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);

			stream.Consume();		// T
			Assert.AreEqual(6, stream.Index());
			Assert.AreEqual(1, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);

			stream.Consume();		// w
			Assert.AreEqual(7, stream.Index());
			Assert.AreEqual(2, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);

			stream.Consume();		// o
			Assert.AreEqual(8, stream.Index());
			Assert.AreEqual(3, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);

			stream.Consume();		// EOF
			Assert.AreEqual(8, stream.Index());
			Assert.AreEqual(3, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);

			stream.Consume();		// EOF
			Assert.AreEqual(8, stream.Index());
			Assert.AreEqual(3, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);
		}