public void SimplePeek(string data) { var sut = new StringTextSource(data); var result = (char)sut.Peek(); Assert.Equal(data, char.ToString(result)); Assert.Equal(0, sut.Offset); Assert.Equal(1, sut.Line); Assert.Equal(1, sut.Column); }
public void WhenRead_ExpectCharacterIsReturnedAndConsumed() { // Given that there is text to be read // When Read is called // Then the next available character is returned // And the character is consumed using (var sut = new StringTextSource("abc")) { var read = (char)sut.Read(); Assert.Equal('a', read); // Verify behavior by peeking at the next character var peek = (char)sut.Peek(); Assert.NotEqual('a', peek); } }
public void WhenReadWithBuffer_ExpectTextIsReturnedAndConsumed() { // Given that there is text to be read // When Read is called // Then the buffer contains the text // And the text is consumed using (var sut = new StringTextSource(Sentence)) { var buffer = new char[Sentence.Length]; var len = sut.Read(buffer, 0, buffer.Length); Assert.Equal(buffer.Length, len); Assert.Equal(Sentence.ToCharArray(), buffer); // Verify behavior by peeking at the next character Assert.Equal(-1, sut.Peek()); } }
public void WhenReadWithBufferBiggerThanTextSource_ExpectResultLessThanBufferSize() { // Given that there is text to be read // When Read is called with a buffer // And the buffer length is larger than the length of the text // Then the buffer contains the text // And the returned length is less than the length of the buffer // And the text is consumed using (var sut = new StringTextSource(Sentence)) { var buffer = new char[Sentence.Length * 2]; var len = sut.Read(buffer, 0, buffer.Length); Assert.Equal(Sentence.Length, len); Assert.Equal(Sentence.ToCharArray(), buffer.Take(len)); // Verify behavior by peeking at the next character Assert.Equal(-1, sut.Peek()); } }
public void EmptyData() { // Given that there is a text source // and the text length is 0 // and the current offset is 0 // and the current line is 1 // and the current column is 1 // When Peek is called // Then the result is -1 // and the current offset is 0 // and the current line is 1 // and the current column is 1 var sut = new StringTextSource(""); Assert.Equal(-1, sut.Peek()); Assert.Equal(0, sut.Offset); Assert.Equal(1, sut.Line); Assert.Equal(1, sut.Column); }