forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodingCodePages.netcoreapp.cs
More file actions
67 lines (58 loc) · 2.41 KB
/
Copy pathEncodingCodePages.netcoreapp.cs
File metadata and controls
67 lines (58 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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.
using Microsoft.DotNet.RemoteExecutor;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Xunit;
namespace System.Text.Tests
{
public partial class EncodingTest : IClassFixture<CultureSetup>
{
private class EncodingInformation
{
public EncodingInformation(int codePage, string name)
{
CodePage = codePage;
Name = name;
}
public int CodePage { get; }
public string Name { get; }
}
private static EncodingInformation [] s_defaultEncoding = new EncodingInformation []
{
new EncodingInformation(1200, "utf-16"),
new EncodingInformation(1201, "utf-16BE"),
new EncodingInformation(12000, "utf-32"),
new EncodingInformation(12001, "utf-32BE"),
new EncodingInformation(20127, "us-ascii"),
new EncodingInformation(28591, "iso-8859-1"),
new EncodingInformation(65001, "utf-8")
};
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void TestGetEncodings()
{
RemoteExecutor.Invoke(() => {
EncodingInfo [] list = Encoding.GetEncodings();
foreach (EncodingInformation eInfo in s_defaultEncoding)
{
Assert.NotNull(list.FirstOrDefault(o => o.CodePage == eInfo.CodePage && o.Name == eInfo.Name));
}
}).Dispose();
}
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void TestGetEncodingsWithProvider()
{
RemoteExecutor.Invoke(() => {
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
foreach (EncodingInfo ei in Encoding.GetEncodings())
{
Encoding encoding = ei.GetEncoding();
Assert.Equal(ei.CodePage, encoding.CodePage);
Assert.True(ei.Name.Equals(encoding.WebName, StringComparison.OrdinalIgnoreCase), $"Encodinginfo.Name `{ei.Name}` != Encoding.WebName `{encoding.WebName}`");
}
}).Dispose();
}
}
}