コード例 #1
0
        public void EmptyStream()
        {
            // Arrange
            var emptyByteArray = new byte[0];
            var needle         = "needle";

            using (var memStream = new MemoryStream(emptyByteArray))
                using (var sStream = new SearchableStringStream(memStream))
                {
                    sStream.Seek(0, SeekOrigin.End);
                    // Act
                    var foundPositions = sStream.IndexOfAllBackwards(needle);

                    // Assert
                    Assert.AreEqual(0, foundPositions.Length);
                }
        }
コード例 #2
0
        public void NotInStream()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e");
            var needle            = "needle";

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var sStream = new SearchableStringStream(memStream))
                {
                    sStream.Seek(0, SeekOrigin.End);

                    // Act
                    var foundPositions = sStream.IndexOfAllBackwards(needle);

                    // Assert
                    Assert.AreEqual(0, foundPositions.Length);
                }
        }
コード例 #3
0
        public void SingleOccuranceAtEnd()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("haystack with a needle");
            var needle            = "needle";

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var sStream = new SearchableStringStream(memStream))
                {
                    sStream.Seek(0, SeekOrigin.End);
                    // Act
                    var foundPositions = sStream.IndexOfAllBackwards(needle);

                    // Assert
                    Assert.AreEqual(1, foundPositions.Length);
                    Assert.AreEqual(16, foundPositions[0]);
                }
        }
コード例 #4
0
        public void MultipleOccuranceSelectTwo()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This hay stack has a needle here and another needle here and another needle here");
            var needle            = "needle";

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var sStream = new SearchableStringStream(memStream))
                {
                    sStream.Seek(0, SeekOrigin.End);
                    // Act
                    var foundPositions = sStream.IndexOfAllBackwards(needle, 2);

                    // Assert
                    Assert.AreEqual(2, foundPositions.Length);
                    Assert.AreEqual(45, foundPositions[1]);
                    Assert.AreEqual(69, foundPositions[0]);
                }
        }