Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b804a09

Browse files
authored
Nano adjustment of console encoding (#19519)
Add an optional extended description…
1 parent 236c0b9 commit b804a09

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/System.Console/tests/ConsoleEncoding.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ public void TestEncoding(string inputString)
7878
}
7979
}
8080

81+
[Fact]
82+
public void TestValidEncodings()
83+
{
84+
Action<Encoding> check = encoding =>
85+
{
86+
Console.OutputEncoding = encoding;
87+
Assert.Equal(encoding, Console.OutputEncoding);
88+
Console.InputEncoding = encoding;
89+
Assert.Equal(encoding, Console.InputEncoding);
90+
};
91+
92+
// These seem to always be available
93+
check(Encoding.UTF8);
94+
check(Encoding.Unicode);
95+
96+
// On full Windows, ASCII is available also
97+
if (!PlatformDetection.IsWindowsNanoServer)
98+
{
99+
check(Encoding.ASCII);
100+
}
101+
102+
}
103+
81104
public class NonexistentCodePageEncoding : Encoding
82105
{
83106
public override int CodePage => int.MinValue;
@@ -104,8 +127,8 @@ public void InputEncoding_SetWithInInitialized_ResetsIn()
104127
Assert.Same(inReader, Console.In);
105128

106129
// Change the InputEncoding
107-
Console.InputEncoding = Encoding.ASCII;
108-
Assert.Equal(Encoding.ASCII, Console.InputEncoding);
130+
Console.InputEncoding = Encoding.Unicode; // Not ASCII: not supported by Windows Nano
131+
Assert.Equal(Encoding.Unicode, Console.InputEncoding);
109132

110133
if (PlatformDetection.IsWindows)
111134
{
@@ -152,8 +175,8 @@ public void OutputEncoding_SetWithErrorAndOutputInitialized_ResetsErrorAndOutput
152175
Assert.Same(outWriter, Console.Out);
153176

154177
// Change the OutputEncoding
155-
Console.OutputEncoding = Encoding.ASCII;
156-
Assert.Equal(Encoding.ASCII, Console.OutputEncoding);
178+
Console.OutputEncoding = Encoding.Unicode; // Not ASCII: not supported by Windows Nano
179+
Assert.Equal(Encoding.Unicode, Console.OutputEncoding);
157180

158181
Assert.NotSame(errorWriter, Console.Error);
159182
Assert.NotSame(outWriter, Console.Out);

0 commit comments

Comments
 (0)