From fccfa225ec3ad427892013b292abe6b64be7097a Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Sat, 23 Nov 2024 17:47:14 -0300 Subject: [PATCH] Allow specifying encoding of source file content Fixes #1194 --- .../PublicAPI.Unshipped.txt | 2 ++ .../SourceFileCollection.cs | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/PublicAPI.Unshipped.txt b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/PublicAPI.Unshipped.txt index 668589bf7..952651b32 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/PublicAPI.Unshipped.txt +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/PublicAPI.Unshipped.txt @@ -224,7 +224,9 @@ Microsoft.CodeAnalysis.Testing.SolutionState.WithProcessedMarkup(Microsoft.CodeA Microsoft.CodeAnalysis.Testing.SourceFileCollection Microsoft.CodeAnalysis.Testing.SourceFileCollection.Add((System.Type sourceGeneratorType, string filename, Microsoft.CodeAnalysis.Text.SourceText content) file) -> void Microsoft.CodeAnalysis.Testing.SourceFileCollection.Add((System.Type sourceGeneratorType, string filename, string content) file) -> void +Microsoft.CodeAnalysis.Testing.SourceFileCollection.Add((System.Type sourceGeneratorType, string filename, string content, System.Text.Encoding encoding) file) -> void Microsoft.CodeAnalysis.Testing.SourceFileCollection.Add((string filename, string content) file) -> void +Microsoft.CodeAnalysis.Testing.SourceFileCollection.Add((string filename, string content, System.Text.Encoding encoding) file) -> void Microsoft.CodeAnalysis.Testing.SourceFileCollection.SourceFileCollection() -> void Microsoft.CodeAnalysis.Testing.SourceFileList Microsoft.CodeAnalysis.Testing.SourceFileList.Add(Microsoft.CodeAnalysis.Text.SourceText content) -> void diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/SourceFileCollection.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/SourceFileCollection.cs index a4d69e536..fd6d5a813 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/SourceFileCollection.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/SourceFileCollection.cs @@ -18,9 +18,19 @@ public void Add((string filename, string content) file) Add((file.filename, SourceText.From(file.content))); } + public void Add((string filename, string content, Encoding encoding) file) + { + Add((file.filename, SourceText.From(file.content, file.encoding))); + } + public void Add((Type sourceGeneratorType, string filename, string content) file) { - var contentWithEncoding = SourceText.From(file.content, Encoding.UTF8); + Add((file.sourceGeneratorType, file.filename, file.content, Encoding.UTF8)); + } + + public void Add((Type sourceGeneratorType, string filename, string content, Encoding encoding) file) + { + var contentWithEncoding = SourceText.From(file.content, file.encoding); Add((file.sourceGeneratorType, file.filename, contentWithEncoding)); }