From c8ef9fadca9eb1769b16959bb5868b1e3335a676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Szab=C3=B3?= Date: Fri, 9 Feb 2024 20:27:10 +0100 Subject: [PATCH] Store the provided values for custom Fakes to allow inspection and testing --- .../CodeAnalysis/Fakes/AdditionalText.cs | 7 +++++-- .../Fakes/AnalyzerConfigOptionsProvider.cs | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Analyzers.Testing/CodeAnalysis/Fakes/AdditionalText.cs b/src/Analyzers.Testing/CodeAnalysis/Fakes/AdditionalText.cs index 02e4fbb..9fd43c8 100644 --- a/src/Analyzers.Testing/CodeAnalysis/Fakes/AdditionalText.cs +++ b/src/Analyzers.Testing/CodeAnalysis/Fakes/AdditionalText.cs @@ -12,9 +12,12 @@ public AdditionalText(string path, string text) : this(path, SourceText.From(tex /// The "path" for the text file. Doesn't necessarily point to a valid location. public override string Path => path; - + + /// Retrieves the text stored with this instance. + public SourceText? Text => text; + /// Return the wrapped text of the current fake. /// The cancellation token. Unused. /// The source text that was referenced during construction of this instance. - public override SourceText? GetText(CancellationToken cancellationToken = default) => text; + public override SourceText? GetText(CancellationToken cancellationToken = default) => Text; } \ No newline at end of file diff --git a/src/Analyzers.Testing/CodeAnalysis/Fakes/AnalyzerConfigOptionsProvider.cs b/src/Analyzers.Testing/CodeAnalysis/Fakes/AnalyzerConfigOptionsProvider.cs index 96031c7..bcad028 100644 --- a/src/Analyzers.Testing/CodeAnalysis/Fakes/AnalyzerConfigOptionsProvider.cs +++ b/src/Analyzers.Testing/CodeAnalysis/Fakes/AnalyzerConfigOptionsProvider.cs @@ -14,12 +14,18 @@ public class AnalyzerConfigOptionsProvider( /// The global options, as they are available from the options provided during construction. public override AnalyzerConfigOptions GlobalOptions => globalOptions; + /// The lookup options for each additional syntax tree. + public Dictionary OptionsForSyntaxTrees { get; } = optionsForSyntaxTrees; + + /// The lookup options for each additional text file. + public Dictionary OptionsForAdditionalTexts { get; } = optionsForAdditionalTexts; + /// Gets the , and any additional options specific to . /// The syntax tree to look up additional options for. /// The , and any additional options specific to . public override AnalyzerConfigOptions GetOptions(SyntaxTree key) { - if (optionsForSyntaxTrees.TryGetValue(key, out var value)) + if (OptionsForSyntaxTrees.TryGetValue(key, out var value)) return new(new Dictionary(GlobalOptions.Values.Concat(value.Values))); return GlobalOptions; } @@ -27,7 +33,7 @@ public override AnalyzerConfigOptions GetOptions(SyntaxTree key) /// public override AnalyzerConfigOptions GetOptions(Microsoft.CodeAnalysis.AdditionalText key) { - if (optionsForAdditionalTexts.TryGetValue(key, out var value)) + if (OptionsForAdditionalTexts.TryGetValue(key, out var value)) return new(new Dictionary(GlobalOptions.Values.Concat(value.Values))); return GlobalOptions; }