Exemplo n.º 1
0
        public static void Shrink_LeaveAtLeast_0(string expected, string html)
        {
            // Arrange
            ShrinkHelper.LeaveAtLeast = 0;
            var buffer = Encoding.UTF8.GetBytes(html);

            // Act
            var length = ShrinkHelper.Shrink(buffer, 0, buffer.Length);

            // Assert
            Assert.Equal(expected, Encoding.UTF8.GetString(buffer, 0, length));
        }
Exemplo n.º 2
0
        public static void Shrink1(string html)
        {
            // Arrange
            ShrinkHelper.LeaveAtLeast = 1;

            // Act
            for (int i = 0; i < 100; i++)
            {
                var buffer = Encoding.UTF8.GetBytes(html.Repeat(1000));
                var length = ShrinkHelper.Shrink(buffer, 0, buffer.Length);
            }

            // Assert
        }
Exemplo n.º 3
0
        public static void IgnoreCurrent_HasNoMatch_NotInsideTag()
        {
            // Arrange
            var state = new ShrinkState()
            {
                InsideTag   = false,
                IgnoreCount = 10,
                Current     = NotMatch
            };

            // Act
            var result = ShrinkHelper.IgnoreCurrent(Match, state);

            // Assert
            Assert.False(result);
            Assert.False(state.InsideTag);
            Assert.Equal(10, state.IgnoreCount);
            Assert.Equal(NotMatch, state.Current);
        }
Exemplo n.º 4
0
        public static void IgnoreCurrent_HasMatch()
        {
            // Arrange
            var state = new ShrinkState()
            {
                InsideTag   = g_random.NextBoolean(),
                IgnoreCount = g_random.NextInt(0, 4),
                Current     = Match[0]
            };

            // Act
            var result = ShrinkHelper.IgnoreCurrent(Match, state);

            // Assert
            Assert.False(result);
            Assert.True(state.InsideTag);
            Assert.Equal(0, state.IgnoreCount);
            Assert.Equal(Match[0], state.Current);
        }
Exemplo n.º 5
0
        public static void IgnoreCurrent_InsideTag_HasNoIgnoreMatch()
        {
            // Arrange
            var state = new ShrinkState()
            {
                InsideTag   = true,
                IgnoreCount = 4,
                Current     = NotMatch
            };

            // Act
            var result = ShrinkHelper.IgnoreCurrent(Match, state);

            // Assert
            Assert.False(result);
            Assert.False(state.InsideTag);
            Assert.Equal(4, state.IgnoreCount);
            Assert.Equal(NotMatch, state.Current);
        }
Exemplo n.º 6
0
        public static void IgnoreCurrent_InsideTag_HasIgnoreMatch_AtLeast_One()
        {
            // Arrange
            var state = new ShrinkState()
            {
                InsideTag   = true,
                IgnoreCount = 4,
                Current     = IgnoreMatch
            };

            // Act
            var result = ShrinkHelper.IgnoreCurrent(Match, state);

            // Assert
            Assert.True(result);
            Assert.True(state.InsideTag);
            Assert.Equal(5, state.IgnoreCount);
            Assert.Equal(IgnoreMatch, state.Current);
        }
Exemplo n.º 7
0
        public static void IgnoreCurrent_InsideTag_HasIgnoreMatch_FirstTime()
        {
            // Arrange
            ShrinkHelper.LeaveAtLeast = 1;
            var state = new ShrinkState()
            {
                InsideTag   = true,
                IgnoreCount = 0,
                Current     = IgnoreMatch
            };

            // Act
            var result = ShrinkHelper.IgnoreCurrent(Match, state);

            // Assert
            Assert.False(result);
            Assert.True(state.InsideTag);
            Assert.Equal(1, state.IgnoreCount);
            Assert.Equal(IgnoreMatch, state.Current);
        }
Exemplo n.º 8
0
            public override void Write(byte[] buffer, int offset, int count)
            {
                var length = ShrinkHelper.Shrink(buffer, offset, count);

                base.Write(buffer, offset, length);
            }