public void TestResetOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] buffer = encoding.GetBytes("One\r\nTwo"); MemoryStream grammarStream = new MemoryStream(buffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, encoding); Assert.AreEqual(0, inputStream.Index); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // O inputStream.Consume(); // n Assert.AreEqual('e', inputStream.LA(1)); Assert.AreEqual(2, inputStream.Index); inputStream.Reset(); Assert.AreEqual('O', inputStream.LA(1)); Assert.AreEqual(0, inputStream.Index); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // O Assert.AreEqual('n', inputStream.LA(1)); Assert.AreEqual(1, inputStream.Index); Assert.AreEqual(1, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // n Assert.AreEqual('e', inputStream.LA(1)); Assert.AreEqual(2, inputStream.Index); Assert.AreEqual(2, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // e }
public void TestConsumeAndIndexOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] grammarStrBuffer = encoding.GetBytes(grammarStr); MemoryStream grammarStream = new MemoryStream(grammarStrBuffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode); Assert.AreEqual(0, inputStream.Index); inputStream.Consume(); Assert.AreEqual(1, inputStream.Index); inputStream.Consume(); Assert.AreEqual(2, inputStream.Index); while (inputStream.Index < inputStream.Count) { inputStream.Consume(); } Assert.AreEqual(inputStream.Index, inputStream.Count); }
public void TestConsumeAllCharactersInAnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] grammarStrBuffer = encoding.GetBytes(grammarStr); MemoryStream grammarStream = new MemoryStream(grammarStrBuffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode); while (inputStream.Index < inputStream.Count) { Console.Out.Write((char)inputStream.LA(1)); inputStream.Consume(); } Assert.AreEqual(inputStream.Index, inputStream.Count); }
public void TestSubstringOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] buffer = encoding.GetBytes("One\r\nTwo\r\nThree"); MemoryStream grammarStream = new MemoryStream(buffer); ANTLRInputStream stream = new ANTLRInputStream(grammarStream, encoding); 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 TestConsumeOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] buffer = encoding.GetBytes("One\r\nTwo"); MemoryStream grammarStream = new MemoryStream(buffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode); Assert.AreEqual(0, inputStream.Index); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // O Assert.AreEqual(1, inputStream.Index); Assert.AreEqual(1, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // n Assert.AreEqual(2, inputStream.Index); Assert.AreEqual(2, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // e Assert.AreEqual(3, inputStream.Index); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // \r Assert.AreEqual(4, inputStream.Index); Assert.AreEqual(4, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // \n Assert.AreEqual(5, inputStream.Index); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // T Assert.AreEqual(6, inputStream.Index); Assert.AreEqual(1, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // w Assert.AreEqual(7, inputStream.Index); Assert.AreEqual(2, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // o Assert.AreEqual(8, inputStream.Index); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // EOF Assert.AreEqual(8, inputStream.Index); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // EOF Assert.AreEqual(8, inputStream.Index); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); }
public void TestConsumeAndIndexOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] grammarStrBuffer = encoding.GetBytes(grammarStr); MemoryStream grammarStream = new MemoryStream(grammarStrBuffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode); Assert.AreEqual(0, inputStream.Index()); inputStream.Consume(); Assert.AreEqual(1, inputStream.Index()); inputStream.Consume(); Assert.AreEqual(2, inputStream.Index()); while (inputStream.Index() < inputStream.Size()) { inputStream.Consume(); } Assert.AreEqual(inputStream.Index(), inputStream.Size()); }
public void TestResetOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] buffer = encoding.GetBytes("One\r\nTwo"); MemoryStream grammarStream = new MemoryStream(buffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, encoding); Assert.AreEqual(0, inputStream.Index()); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // O inputStream.Consume(); // n Assert.AreEqual('e', inputStream.LA(1)); Assert.AreEqual(2, inputStream.Index()); inputStream.Reset(); Assert.AreEqual('O', inputStream.LA(1)); Assert.AreEqual(0, inputStream.Index()); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // O Assert.AreEqual('n', inputStream.LA(1)); Assert.AreEqual(1, inputStream.Index()); Assert.AreEqual(1, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // n Assert.AreEqual('e', inputStream.LA(1)); Assert.AreEqual(2, inputStream.Index()); Assert.AreEqual(2, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // e }
public void TestConsumeOnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] buffer = encoding.GetBytes("One\r\nTwo"); MemoryStream grammarStream = new MemoryStream(buffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode); Assert.AreEqual(0, inputStream.Index()); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // O Assert.AreEqual(1, inputStream.Index()); Assert.AreEqual(1, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // n Assert.AreEqual(2, inputStream.Index()); Assert.AreEqual(2, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // e Assert.AreEqual(3, inputStream.Index()); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // \r Assert.AreEqual(4, inputStream.Index()); Assert.AreEqual(4, inputStream.CharPositionInLine); Assert.AreEqual(1, inputStream.Line); inputStream.Consume(); // \n Assert.AreEqual(5, inputStream.Index()); Assert.AreEqual(0, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // T Assert.AreEqual(6, inputStream.Index()); Assert.AreEqual(1, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // w Assert.AreEqual(7, inputStream.Index()); Assert.AreEqual(2, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // o Assert.AreEqual(8, inputStream.Index()); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // EOF Assert.AreEqual(8, inputStream.Index()); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); inputStream.Consume(); // EOF Assert.AreEqual(8, inputStream.Index()); Assert.AreEqual(3, inputStream.CharPositionInLine); Assert.AreEqual(2, inputStream.Line); }
public void TestConsumeAllCharactersInAnANTLRInputStream() { Encoding encoding = Encoding.Unicode; byte[] grammarStrBuffer = encoding.GetBytes(grammarStr); MemoryStream grammarStream = new MemoryStream(grammarStrBuffer); ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode); while (inputStream.Index() < inputStream.Size()) { Console.Out.Write((char)inputStream.LA(1)); inputStream.Consume(); } Assert.AreEqual(inputStream.Index(), inputStream.Size()); }