Exemplo n.º 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 searchableStringString = new SearchableStringStream(memStream))
                {
                    // Act
                    var foundPosition = searchableStringString.IndexOf(null);
                }
        }
Exemplo n.º 2
0
        public void SingleOccuranceAtBeginning()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("needle in a haystack");
            var needle            = "needle";

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var searchableStringStream = new SearchableStringStream(memStream))
                {
                    // Act
                    var foundPosition = searchableStringStream.IndexOf(needle);

                    // Assert
                    Assert.AreEqual(0, foundPosition);
                }
        }
Exemplo n.º 3
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 searchableStringStream = new SearchableStringStream(memStream))
                {
                    // Act
                    var foundPosition = searchableStringStream.IndexOf(needle);

                    // Assert
                    Assert.AreEqual(-1, foundPosition);
                }
        }
Exemplo n.º 4
0
        public void EmptyStream()
        {
            // Arrange
            var emptyByteArray = new byte[0];
            var needle         = "needle";

            using (var memStream = new MemoryStream(emptyByteArray))
                using (var searchableStringStream = new SearchableStringStream(memStream))
                {
                    // Act
                    var foundPosition = searchableStringStream.IndexOf(needle);

                    // Assert
                    Assert.AreEqual(-1, foundPosition);
                }
        }
Exemplo n.º 5
0
        public void MultipleOccurance_Unicode()
        {
            // Arrange
            var haystackByteArray = Encoding.Unicode.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 searchableStringStream = new SearchableStringStream(memStream, Encoding.Unicode))
                {
                    // Act
                    var foundPosition = searchableStringStream.IndexOf(needle);

                    // Assert
                    Assert.AreEqual(42, foundPosition);
                }
        }