public void Regress_Mutation_1AShouldBeStripped()
        {
            Stream stream = StreamHelpers.StringToStream("x\x1Ay");
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get the last character (which should be 'y' and not 0x1A).
            Assert.AreEqual('y', s.GetAt(1));
        }
        public void Regress_Mutation_LastCharacterShouldBeNewLine()
        {
            Stream stream = StreamHelpers.StringToStream("A");
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get the last character (which should be the appended newLine).
            Assert.AreEqual('\xd', s.GetAt(1));
        }
        public void Regress_Mutation_BackingUpMoreThanOnePageWorks()
        {
            Stream stream = StreamHelpers.StringToStream("A" + new String('b', StreamMappedString.DefaultPageSize * 4));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get the last character...
            s.GetAt(StreamMappedString.DefaultPageSize * 4);

            // ...now get the first character.
            Assert.AreEqual('A', s.GetAt(0));
        }
        public void Regress_Mutation_RetrievingFromLastPageWorks()
        {
            Stream stream = StreamHelpers.StringToStream("A" + new String('b', StreamMappedString.DefaultPageSize));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get the last character...
            s.GetAt(StreamMappedString.DefaultPageSize);

            // ...now get the first character (which should be saved on lastPage).
            Assert.AreEqual('A', s.GetAt(0));
        }
        public void Regress_Mutation_ForceANSIWorks_RelatedTo172107()
        {
            // Can't embed the 'Ã' directly because the string is Unicode already and the Unicode<-->ANSI transform
            // isn't bidirectional.
            MemoryStream sourcesStream = (MemoryStream)StreamHelpers.StringToStream("namespace d?a { class Class {} }");

            // Instead, directly write the ANSI character into the memory buffer.
            sourcesStream.Seek(11, SeekOrigin.Begin);
            sourcesStream.WriteByte(0xc3);    // Plug the 'Ã' in 
            sourcesStream.Seek(0, SeekOrigin.Begin);

            // Should not throw an exception because we force ANSI.
            StreamMappedString s = new StreamMappedString(sourcesStream, /* forceANSI */ true);
            s.GetAt(11);
        }
        public void Regress_Mutation_ReadingCharactersForwardOnlyShouldCauseNoAdditionalResets()
        {
            RestartCountingStream stream = new RestartCountingStream(StreamHelpers.StringToStream("abcdefg"));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get a few characters.
            s.GetAt(0);
            s.GetAt(1);
            s.GetAt(2);
            s.GetAt(3);
            s.GetAt(4);

            // There should be exactly one reset for this.
            Assert.AreEqual(0, stream.ResetCount);
        }
        public void Regress_Mutation_RequestPageWellPastEnd()
        {
            Stream stream = StreamHelpers.StringToStream(new String('x', StreamMappedString.DefaultPageSize * 2));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Read something way past the end. This should result in a range exception.
            s.GetAt(1000000);
        }
        public void Regress_Mutation_FirstCharacterOnPagePastEndDoesntExist()
        {
            Stream stream = StreamHelpers.StringToStream("abc");
            StreamMappedString s = new StreamMappedString(stream, false, 256);

            s.GetAt(256);
        }
        public void Regress_Codereview_RequestPageWellPastEnd()
        {
            Stream stream = StreamHelpers.StringToStream("x");
            StreamMappedString s = new StreamMappedString(stream, false);

            // Read something way past the end. This should result in a range exception.
            s.GetAt(1000000);
        }
Exemplo n.º 10
0
        public void Regress_Mutation_SubstringReadPastEndThrowsException()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                Stream stream = StreamHelpers.StringToStream("abcdefg");
                StreamMappedString s = new StreamMappedString(stream, false);

                Assert.Equal(String.Empty, s.Substring(1, 30));
            }
           );
        }
Exemplo n.º 11
0
        public void Regress_Mutation_NewLineGetsAppendedAcrossPageBoundaries()
        {
            Stream stream = StreamHelpers.StringToStream(new String('x', StreamMappedString.DefaultPageSize));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get the last character (which should be '\xd').
            Assert.AreEqual('\xd', s.GetAt(StreamMappedString.DefaultPageSize));
        }
Exemplo n.º 12
0
        public void Regress_Mutation_FirstCharacterOnPagePastEndDoesntExist()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                Stream stream = StreamHelpers.StringToStream("abc");
                StreamMappedString s = new StreamMappedString(stream, false, 256);

                s.GetAt(256);
            }
           );
        }
Exemplo n.º 13
0
        public void Regress_Mutation_UnicodeIsDetected()
        {
            Stream stream = StreamHelpers.StringToStream("\u00C3ngelo's Steak House", System.Text.Encoding.UTF32);
            StreamMappedString s = new StreamMappedString(stream, false);

            // This won't read correctly with ANSI encoding.
            Assert.AreEqual('\u00C3', s.GetAt(0));
        }
Exemplo n.º 14
0
        public void Regress_Mutation_SubstringOnLastPageWorks()
        {
            Stream stream = StreamHelpers.StringToStream("abcdefg" + new String('x', StreamMappedString.DefaultPageSize));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Move to the second page
            s.GetAt(StreamMappedString.DefaultPageSize);

            // Get a string from the firstPage
            Assert.AreEqual("abc", s.Substring(0, 3));
        }
Exemplo n.º 15
0
        public void Regress_Mutation_SubstringReadPastEndThrowsException()
        {
            Stream stream = StreamHelpers.StringToStream("abcdefg");
            StreamMappedString s = new StreamMappedString(stream, false);

            Assert.AreEqual(String.Empty, s.Substring(1, 30));
        }
Exemplo n.º 16
0
        public void Regress_Mutation_SubstringWorksFromPriorPage()
        {
            Stream stream = StreamHelpers.StringToStream("abcxdef");
            StreamMappedString s = new StreamMappedString(stream, false, 7);

            // Move to the last page
            s.GetAt(7);

            // And then extract a string from the beginning page.
            Assert.AreEqual("abcxdef", s.Substring(0, 7));
        }
Exemplo n.º 17
0
        public void Regress_Mutation_SubstringWorksWithPageSizeOne()
        {
            Stream stream = StreamHelpers.StringToStream("abcdefg");
            StreamMappedString s = new StreamMappedString(stream, false, /* pageSize */ 1);

            Assert.AreEqual("bcd", s.Substring(1, 3));
        }
 internal TokenCharReader(Stream binaryStream, bool forceANSI)
 {
     this.Reset();
     this.sources = new StreamMappedString(binaryStream, forceANSI);
 }
Exemplo n.º 19
0
        public void Regress_Mutation_IsPastEndWorks()
        {
            RestartCountingStream stream = new RestartCountingStream(StreamHelpers.StringToStream("a"));
            StreamMappedString s = new StreamMappedString(stream, false);

            // There's only one character, so IsPastEnd(2) should be true.
            Assert.IsTrue(s.IsPastEnd(2)); // <-- 2 required because of extra \xd added.
        }
Exemplo n.º 20
0
        public void Regress_Mutation_MinimizePagesAllocated()
        {
            Stream stream = StreamHelpers.StringToStream("a" + new String('x', StreamMappedString.DefaultPageSize * 2));
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get a few characters.
            s.GetAt(0);
            s.GetAt(StreamMappedString.DefaultPageSize);
            s.GetAt(StreamMappedString.DefaultPageSize * 2);

            // Even though three pages were read, only two allocations should have occurred.
            Assert.AreEqual(2, s.PagesAllocated);
        }
Exemplo n.º 21
0
        public void Regress_Mutation_MultiplePagesOf1AShouldBeStripped()
        {
            Stream stream = StreamHelpers.StringToStream(new String('\x1a', StreamMappedString.DefaultPageSize * 2) + "x");
            StreamMappedString s = new StreamMappedString(stream, false);

            // Get the last character (which should be 'x' and not 0x1A).
            Assert.AreEqual('x', s.GetAt(0));
        }
Exemplo n.º 22
0
        public void Regress_Mutation_1DNotAppendedIfAlreadyThere()
        {
            RestartCountingStream stream = new RestartCountingStream(StreamHelpers.StringToStream("\xd"));
            StreamMappedString s = new StreamMappedString(stream, false);

            // There's only one \x1d so IsPastEnd(1) should be true.
            Assert.IsTrue(s.IsPastEnd(1));
        }
Exemplo n.º 23
0
 internal TokenCharReader(Stream binaryStream, bool forceANSI)
 {
     Reset();
     _sources = new StreamMappedString(binaryStream, forceANSI);
 }
Exemplo n.º 24
0
        public void Regress_Mutation_SubstringWorks()
        {
            Stream stream = StreamHelpers.StringToStream("abcdefg");
            StreamMappedString s = new StreamMappedString(stream, false);

            Assert.Equal("bcd", s.Substring(1, 3));
        }