示例#1
0
        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);
                }
        }
示例#2
0
        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);
                }
        }
示例#3
0
        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);
                }
        }
示例#4
0
        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]);
                }
        }
示例#5
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]);
                }
        }
示例#6
0
        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]);
                }
        }