Skip to content

Commit

Permalink
CoreFx #22406 Span based APIs - Text Reader Writer
Browse files Browse the repository at this point in the history
  • Loading branch information
WinCPP committed Sep 7, 2017
1 parent e150f00 commit 21121a7
Show file tree
Hide file tree
Showing 14 changed files with 1,258 additions and 67 deletions.
53 changes: 27 additions & 26 deletions src/System.IO/tests/StreamReader/StreamReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,33 @@ protected virtual Stream GetLargeStream()

protected Tuple<char[], StreamReader> GetCharArrayStream()
{
var chArr = new char[]{
char.MinValue
,char.MaxValue
,'\t'
,' '
,'$'
,'@'
,'#'
,'\0'
,'\v'
,'\''
,'\u3190'
,'\uC3A0'
,'A'
,'5'
,'\r'
,'\uFE70'
,'-'
,';'
,'\r'
,'\n'
,'T'
,'3'
,'\n'
,'K'
,'\u00E6'
var chArr = new char[]
{
char.MinValue,
char.MaxValue,
'\t',
' ',
'$',
'@',
'#',
'\0',
'\v',
'\'',
'\u3190',
'\uC3A0',
'A',
'5',
'\r',
'\uFE70',
'-',
';',
'\r',
'\n',
'T',
'3',
'\n',
'K',
'\u00E6'
};
var ms = CreateStream();
var sw = new StreamWriter(ms);
Expand Down
41 changes: 21 additions & 20 deletions src/System.IO/tests/StreamWriter/StreamWriter.WriteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,27 @@ public void WriteChars()

private static char[] setupArray()
{
return new char[]{
char.MinValue
,char.MaxValue
,'\t'
,' '
,'$'
,'@'
,'#'
,'\0'
,'\v'
,'\''
,'\u3190'
,'\uC3A0'
,'A'
,'5'
,'\uFE70'
,'-'
,';'
,'\u00E6'
};
return new char[]
{
char.MinValue,
char.MaxValue,
'\t',
' ',
'$',
'@',
'#',
'\0',
'\v',
'\'',
'\u3190',
'\uC3A0',
'A',
'5',
'\uFE70',
'-',
';',
'\u00E6'
};
}

[Fact]
Expand Down
41 changes: 21 additions & 20 deletions src/System.IO/tests/StringWriter/StringWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@ public class StringWriterTests

private static char[] getCharArray()
{
return new char[]{
char.MinValue
,char.MaxValue
,'\t'
,' '
,'$'
,'@'
,'#'
,'\0'
,'\v'
,'\''
,'\u3190'
,'\uC3A0'
,'A'
,'5'
,'\uFE70'
,'-'
,';'
,'\u00E6'
};
return new char[]
{
char.MinValue,
char.MaxValue,
'\t',
' ',
'$',
'@',
'#',
'\0',
'\v',
'\'',
'\u3190',
'\uC3A0',
'A',
'5',
'\uFE70',
'-',
';',
'\u00E6'
};
}

private static StringBuilder getSb()
Expand Down
6 changes: 6 additions & 0 deletions src/System.IO/tests/System.IO.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<Compile Include="$(CommonTestPath)\System\IO\WrappedMemoryStream.cs">
<Link>Common\System\IO\WrappedMemoryStream.cs</Link>
</Compile>
<Compile Include="TextReader\CharArrayTextReader.cs" />
<Compile Include="TextReader\TextReaderTests.cs" />
<Compile Include="TextReader\TextReaderTests.netcoreapp.cs" Condition="'$(TargetGroup)' == 'netcoreapp'" />
<Compile Include="TextWriter\CharArrayTextWriter.cs" />
<Compile Include="TextWriter\TextWriterTests.cs" />
<Compile Include="TextWriter\TextWriterTests.netcoreapp.cs" Condition="'$(TargetGroup)' == 'netcoreapp'" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
Expand Down
37 changes: 37 additions & 0 deletions src/System.IO/tests/TextReader/CharArrayTextReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.IO.Tests
{
public class CharArrayTextReader : TextReader
{
private readonly char[] _charBuffer;
private int _charPos = 0;

public bool EndOfStream => _charPos >= _charBuffer.Length;

public CharArrayTextReader(char[] data)
{
_charBuffer = data;
}

public override int Peek()
{
if (_charPos == _charBuffer.Length)
{
return -1;
}
return _charBuffer[_charPos];
}

public override int Read()
{
if (_charPos == _charBuffer.Length)
{
return -1;
}
return _charBuffer[_charPos++];
}
}
}
Loading

0 comments on commit 21121a7

Please sign in to comment.