public void Reset_Case3() { // Arrange var r = new ResettableReader(new StringReader("0123456789X")); // Act // Assert Repeats(r.Read, 2); Assert.That((char)r.Peek(), Is.EqualTo('2')); r.Mark(); // 01[2]3456789X Repeats(r.Read, 2); Assert.That((char)r.Peek(), Is.EqualTo('4')); r.Reset(false); Assert.That((char)r.Peek(), Is.EqualTo('2')); Repeats(r.Read, 2); Assert.That((char)r.Peek(), Is.EqualTo('4')); r.Reset(false); Assert.That((char)r.Peek(), Is.EqualTo('2')); Repeats(r.Read, 2); Assert.That((char)r.Peek(), Is.EqualTo('4')); Repeats(r.Read, 2); Assert.That((char)r.Peek(), Is.EqualTo('6')); r.Reset(false); Assert.That((char)r.Peek(), Is.EqualTo('2')); }
public void Reset_Case1(string text, int willMarkOn, int willResetOn, int willBreakOn) { // Arrange var r = new ResettableReader(new StringReader(text)); var markedChar = '\u0000'; while (!r.EndOfFile) { if (willMarkOn == r.Position.Index) { markedChar = (char)r.Peek(); r.Mark(); } if (willResetOn == r.Position.Index) { // Act r.Reset(false); // Assert Assert.That(r.Position.Index, Is.EqualTo(willMarkOn)); Assert.That(r.Peek(), Is.EqualTo(markedChar)); if (--willBreakOn < 1) { break; } } r.Read(); } }
public void Unmark_Case4() { // Arrange var r = new ResettableReader(new StringReader("0123456789X")); // Act // Assert Repeats(r.Read, 2); Assert.That(r.Peek(), Is.EqualTo('2')); r.Mark(); Repeats(r.Read, 2); Assert.That(r.Peek(), Is.EqualTo('4')); r.Mark(); Repeats(r.Read, 2); Assert.That(r.Peek(), Is.EqualTo('6')); r.Unmark(); r.Unmark(); r.Mark(); Repeats(r.Read, 2); Assert.That(r.Peek(), Is.EqualTo('8')); r.Reset(false); Assert.That(r.Peek(), Is.EqualTo('6')); Assert.That(ReadsAll(r), Is.EqualTo("6789X")); }
public void Unmark_Case1() { // Arrange var r = new ResettableReader(new StringReader("0123456789X")); Repeats(r.Read, 3); r.Mark(); // Act // Assert r.Unmark(); r.Unmark(); }
public void Mark_Case1(string text, int willMarkOn, int readCountAfterMark) { // Arrange var r = new ResettableReader(new StringReader(text)); Repeats(r.Read, willMarkOn); // Act r.Mark(); // Assert Repeats(r.Read, readCountAfterMark); r.Reset(false); Assert.That(r.Peek(), Is.EqualTo(willMarkOn < text.Length ? text[willMarkOn] : -1)); }
public void Capture_Case2(string text, int willMarkOn, int readCountAfterMark) { // Arrange var r = new ResettableReader(new StringReader(text)); Repeats(r.Read, willMarkOn); r.Mark(); Repeats(r.Read, readCountAfterMark); // Act var cap = r.Capture(false); // Assert Assert.That(cap, Is.EqualTo(text.Substring(willMarkOn, readCountAfterMark))); Assert.That(r.Position.Index, Is.EqualTo(willMarkOn + readCountAfterMark)); r.Reset(false); Assert.That(r.Position.Index, Is.EqualTo(willMarkOn)); }
Reader(TextReader reader, bool callStack, Action <string> logAppender) { _inner = new ResettableReader(reader); Context = new Context(this, callStack, logAppender); }