Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertReadTextAsInputStream(java.io.File file, String text) throws java.io.IOException
        private void AssertReadTextAsInputStream(File file, string text)
        {
            using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                AssertReadText(Readables.Wrap(stream, file.Path, Charset.defaultCharset(), file.length()), text);
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExtractOnlyLine() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldExtractOnlyLine()
        {
            // given
            string       firstLine = "characters of only line";
            CharReadable reader    = Readables.Wrap(firstLine);

            // when
            char[] firstLineCharacters = Readables.ExtractFirstLineFrom(reader);
            int    readAfterwards      = reader.Read(new char[1], 0, 1);

            // then
            assertArrayEquals(firstLine.ToCharArray(), firstLineCharacters);
            assertEquals(-1, readAfterwards);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldFailIfNoNewlineInChunk() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldFailIfNoNewlineInChunk()
        {
            // GIVEN
            CharReadable reader = Readables.Wrap("1234567\n89012345678901234");

            // (next chunks):                                   ^
            // (actual chunks):                             ^
            using (ClosestNewLineChunker source = new ClosestNewLineChunker(reader, 12))
            {
                // WHEN
                Source_Chunk chunk = source.NewChunk();
                assertTrue(source.NextChunk(chunk));
                assertArrayEquals("1234567\n".ToCharArray(), CharactersOf(chunk));
                assertThrows(typeof(System.InvalidOperationException), () => assertFalse(source.NextChunk(chunk)));
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExtractFirstLine() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldExtractFirstLine()
        {
            // given
            string       firstLine  = "characters of first line";
            string       secondLine = "here on the second line";
            CharReadable reader     = Readables.Wrap(firstLine + "\n" + secondLine);

            // when
            char[] firstLineCharacters  = Readables.ExtractFirstLineFrom(reader);
            char[] secondLineCharacters = new char[secondLine.Length];
            reader.Read(secondLineCharacters, 0, secondLineCharacters.Length);

            // then
            assertArrayEquals(firstLine.ToCharArray(), firstLineCharacters);
            assertArrayEquals(secondLine.ToCharArray(), secondLineCharacters);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBackUpChunkToClosestNewline() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldBackUpChunkToClosestNewline()
        {
            // GIVEN
            CharReadable reader = Readables.Wrap("1234567\n8901234\n5678901234");

            // (next chunks):                                   ^            ^
            // (actual chunks):                             ^        ^
            using (ClosestNewLineChunker source = new ClosestNewLineChunker(reader, 12))
            {
                // WHEN
                Source_Chunk chunk = source.NewChunk();
                assertTrue(source.NextChunk(chunk));
                assertArrayEquals("1234567\n".ToCharArray(), CharactersOf(chunk));
                assertTrue(source.NextChunk(chunk));
                assertArrayEquals("8901234\n".ToCharArray(), CharactersOf(chunk));
                assertTrue(source.NextChunk(chunk));
                assertArrayEquals("5678901234".ToCharArray(), CharactersOf(chunk));

                // THEN
                assertFalse(source.NextChunk(chunk));
            }
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackPosition() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTrackPosition()
        {
            // GIVEN
            string data = "1234567890";
            //                 ^   ^
            CharReadable        reader = Readables.Wrap(data);
            SectionedCharBuffer buffer = new SectionedCharBuffer(4);

            // WHEN
            int expected = 0;

            do
            {
                buffer    = reader.Read(buffer, buffer.Front());
                expected += buffer.Available();

                // THEN
                assertEquals(expected, reader.Position());
            } while (buffer.HasAvailable());

            // and THEN
            assertEquals(data.ToCharArray().length, expected);
        }
Esempio n. 7
0
 internal TrackingReader(int length)
 {
     this.Bytes  = length * 2;
     this.Actual = Readables.Wrap(new CharArrayReader(Chars(0, length)), length * 2);
 }