public void IncrementTests() { Cursor c = new Cursor(); Assert.AreEqual(0, c.Offset); Assert.AreEqual(0, c.Line); Assert.AreEqual(0, c.LinePos); c++; Assert.AreEqual(1, c.Offset); Assert.AreEqual(0, c.Line); Assert.AreEqual(1, c.LinePos); c++; Assert.AreEqual(2, c.Offset); Assert.AreEqual(0, c.Line); Assert.AreEqual(2, c.LinePos); c = c.Newline(); Assert.AreEqual(3, c.Offset); Assert.AreEqual(1, c.Line); Assert.AreEqual(0, c.LinePos); c++; Assert.AreEqual(4, c.Offset); Assert.AreEqual(1, c.Line); Assert.AreEqual(1, c.LinePos); c = c + 2; Assert.AreEqual(6, c.Offset); Assert.AreEqual(1, c.Line); Assert.AreEqual(3, c.LinePos); }
/// <summary> /// Validates that a newline occurs at cursor and advances cursor. /// </summary> /// <param name="input">input characters.</param> /// <param name="cursor">Reference to the cursor.</param> public static void ExpectSkipLineTerminator(char[] input, ref Cursor cursor) { char ch = PeekExpectChar(input, cursor, LineTerminatorChars); // If we got carriage return, see if there is a linefeed... if ((ch == '\r') && input.Length > (cursor + 1) && (input[cursor + 1] == '\n')) { // ... there is, skip it too... cursor = cursor.Newline(2); } else cursor = cursor.Newline(); }