public void WhenNewWithNullArgument_ExpectArgumentNullException() { // When creating a new StringTextSource with a null argument // Then an ArgumentNullException is thrown StringTextSource sut; Assert.Throws <ArgumentNullException>(() => sut = new StringTextSource((string)null)); }
public void WhenReadingEndOfSource_ExpectMinusOne() { // Given that the text source has been initialized with an string // When Read is called // Then -1 is returned var sut = new StringTextSource(""); var read = sut.Read(); Assert.Equal(-1, read); }
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 WhenReadWithEmptyBuffer_ExpectArgumentNullException() { // Given that the text source has been initialized with a non-empty string // When Read is called with a buffer that is a null reference // Then an ArgumentNullException is thrown var sut = new StringTextSource(Sentence); int read; Assert.Throws <ArgumentNullException>(() => read = sut.Read(null, 0, Sentence.Length)); }
public void WhenReadWithCountBeyondBufferLength_ExpectArgumentOutOfRangeException() { // Given that the text source has been initialized with a non-empty string // When Read is called with a count that exceeds the buffer length // Then an ArgumentOutOfRangeException is thrown var sut = new StringTextSource(Sentence); var buffer = new char[Sentence.Length]; int read; Assert.Throws <ArgumentOutOfRangeException>(() => read = sut.Read(buffer, 0, buffer.Length + 1)); }
public void WhenReadWithNegativeOffset_ExpectArgumentOutOfRangeException() { // Given that the text source has been initialized with a non-empty string // When Read is called with a negative offset // Then an ArgumentOutOfRangeException is thrown var sut = new StringTextSource(Sentence); var buffer = new char[Sentence.Length]; int read; Assert.Throws <ArgumentOutOfRangeException>(() => read = sut.Read(buffer, -1, buffer.Length)); }
public void NegativeOffset(long offset) { // Given that there is a text source // and the text length is 3 // When Seek is called with a negative offset // Then an ArgumentOutOfRangeException is thrown using (var sut = new StringTextSource("abc")) { Assert.Throws <ArgumentOutOfRangeException>(() => sut.Seek(offset)); } }
public void SeekWithoutRecording() { // Given that there is a text source // and the text length is 10 // When reading 1 character // and seeking to offset 0 // Then an exception is thrown using (var sut = new StringTextSource("1234567890")) { sut.Read(new char[2], 0, 2); Assert.Throws <ArgumentOutOfRangeException>(() => sut.Seek(0)); } }
public void SimpleForwardSeek() { // Given that there is a text source // and the text length is 3 // When Seek is called // and the seek offset is 2 // Then the current offset becomes 2 using (var sut = new StringTextSource("abc")) { sut.Seek(2); Assert.Equal(2, sut.Offset); } }
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); }
public void WhenNewWithEmptyString_ExpectObjectIsCreated() { // When creating a new StringTextSource with an empty string // Then no exception is thrown var sut = new StringTextSource(""); }