Skip to content

Commit

Permalink
Store the provided values for custom Fakes to allow inspection and te…
Browse files Browse the repository at this point in the history
…sting
  • Loading branch information
yugabe committed Feb 9, 2024
1 parent 07b71b4 commit c8ef9fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/Analyzers.Testing/CodeAnalysis/Fakes/AdditionalText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public AdditionalText(string path, string text) : this(path, SourceText.From(tex

/// <summary>The "path" for the text file. Doesn't necessarily point to a valid location.</summary>
public override string Path => path;


/// <summary>Retrieves the text stored with this instance.</summary>
public SourceText? Text => text;

/// <summary>Return the wrapped text of the current fake.</summary>
/// <param name="cancellationToken">The cancellation token. Unused.</param>
/// <returns>The source text that was referenced during construction of this instance.</returns>
public override SourceText? GetText(CancellationToken cancellationToken = default) => text;
public override SourceText? GetText(CancellationToken cancellationToken = default) => Text;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ public class AnalyzerConfigOptionsProvider(
/// <summary>The global options, as they are available from the options provided during construction.</summary>
public override AnalyzerConfigOptions GlobalOptions => globalOptions;

/// <summary>The lookup options for each additional syntax tree.</summary>
public Dictionary<SyntaxTree, AnalyzerConfigOptions> OptionsForSyntaxTrees { get; } = optionsForSyntaxTrees;

/// <summary>The lookup options for each additional text file.</summary>
public Dictionary<Microsoft.CodeAnalysis.AdditionalText, AnalyzerConfigOptions> OptionsForAdditionalTexts { get; } = optionsForAdditionalTexts;

/// <summary>Gets the <see cref="GlobalOptions"/>, and any additional options specific to <paramref name="key"/>.</summary>
/// <param name="key">The syntax tree to look up additional options for.</param>
/// <returns>The <see cref="GlobalOptions"/>, and any additional options specific to <paramref name="key"/>.</returns>
public override AnalyzerConfigOptions GetOptions(SyntaxTree key)
{
if (optionsForSyntaxTrees.TryGetValue(key, out var value))
if (OptionsForSyntaxTrees.TryGetValue(key, out var value))
return new(new Dictionary<string, string?>(GlobalOptions.Values.Concat(value.Values)));
return GlobalOptions;
}

/// <inheritdoc cref="GetOptions(SyntaxTree)"/>
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<string, string?>(GlobalOptions.Values.Concat(value.Values)));
return GlobalOptions;
}
Expand Down

0 comments on commit c8ef9fa

Please sign in to comment.