public void NullNeedle() { // Arrange var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e"); using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPosition = searchableStringStream.IndexOfAll(null); } }
public void NotInStream() { // Arrange var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e"); var needleByteArray = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPositions = searchableStringStream.IndexOfAll(needleByteArray); // Assert Assert.AreEqual(0, foundPositions.Length); } }
public void EmptyStream() { // Arrange var emptyByteArray = new byte[0]; var needleByteArray = "needle"; using (var memStream = new MemoryStream(emptyByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPositions = searchableStringStream.IndexOfAll(needleByteArray); // Assert Assert.AreEqual(0, foundPositions.Length); } }
public void SingleOccuranceAtBeginning() { // Arrange var haystackByteArray = Encoding.ASCII.GetBytes("needle in a haystack"); var needleByteArray = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPositions = searchableStringStream.IndexOfAll(needleByteArray); // Assert Assert.AreEqual(1, foundPositions.Length); Assert.AreEqual(0, foundPositions[0]); } }
public void MultipleOccuranceSelectTwo_Unicode() { // Arrange var haystackByteArray = Encoding.Unicode.GetBytes("This hay stack has a needle here and another needle here and another needle here"); var needleByteArray = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream, Encoding.Unicode)) { // Act var foundPositions = searchableStringStream.IndexOfAll(needleByteArray, 2); // Assert Assert.AreEqual(2, foundPositions.Length); Assert.AreEqual(42, foundPositions[0]); Assert.AreEqual(90, foundPositions[1]); } }
public void MultipleOccurance_UTF8() { // Arrange var haystackByteArray = Encoding.UTF8.GetBytes("This hay stack has a needle here and another needle here and another needle here"); var needleByteArray = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream, Encoding.UTF8)) { // Act var foundPositions = searchableStringStream.IndexOfAll(needleByteArray); // Assert Assert.AreEqual(3, foundPositions.Length); Assert.AreEqual(21, foundPositions[0]); Assert.AreEqual(45, foundPositions[1]); Assert.AreEqual(69, foundPositions[2]); } }