Skip to content

Commit f121ba8

Browse files
committed
fix tests: use constructor-injected settings in derived indenter
1 parent 6597353 commit f121ba8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Rubberduck.SmartIndenter/Indenter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public Indenter(IVBE vbe, Func<IIndenterSettings> settings)
1616
_settings = settings;
1717
}
1818

19+
protected override Func<IIndenterSettings> Settings => _settings;
20+
1921
/// <summary>
2022
/// Indents the procedure selected in the ActiveCodePane. If more than one is selected, the first is indented.
2123
/// </summary>

Rubberduck.SmartIndenter/SimpleIndenter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Rubberduck.SmartIndenter
99
/// </summary>
1010
public class SimpleIndenter : ISimpleIndenter
1111
{
12+
protected virtual Func<IIndenterSettings> Settings { get; }
13+
1214
/// <summary>
1315
/// Indents the code contained in the passed string. NOTE: In Rubberduck this overload should only be used on procedures or modules.
1416
/// </summary>
@@ -17,23 +19,23 @@ public class SimpleIndenter : ISimpleIndenter
1719
/// </remarks>
1820
/// <param name="code">The code block to indent</param>
1921
/// <returns>Indented code lines</returns>
20-
public IEnumerable<string> Indent(string code, IIndenterSettings settings = null) => Indent(code.Replace("\r", string.Empty).Split('\n'), false, settings);
22+
public IEnumerable<string> Indent(string code, IIndenterSettings settings = null) => Indent(code.Replace("\r", string.Empty).Split('\n'), false, settings ?? Settings?.Invoke());
2123

2224
/// <summary>
2325
/// Indents a range of code lines. NOTE: If inserting procedures, use the forceTrailingNewLines overload to preserve vertical spacing in the module.
2426
/// Do not call directly on selections. Use Indent(IVBComponent, Selection) instead.
2527
/// </summary>
2628
/// <param name="codeLines">Code lines to indent</param>
2729
/// <returns>Indented code lines</returns>
28-
public IEnumerable<string> Indent(IEnumerable<string> codeLines, IIndenterSettings settings = null) => Indent(codeLines, false, settings);
30+
public IEnumerable<string> Indent(IEnumerable<string> codeLines, IIndenterSettings settings = null) => Indent(codeLines, false, settings ?? Settings?.Invoke());
2931

3032
/// <summary>
3133
/// Indents a range of code lines. Do not call directly on selections. Use Indent(IVBComponent, Selection) instead.
3234
/// </summary>
3335
/// <param name="codeLines">Code lines to indent</param>
3436
/// <param name="forceTrailingNewLines">If true adds a number of blank lines after the last procedure based on VerticallySpaceProcedures settings</param>
3537
/// <returns>Indented code lines</returns>
36-
public IEnumerable<string> Indent(IEnumerable<string> codeLines, bool forceTrailingNewLines, IIndenterSettings settings = null) => Indent(codeLines, forceTrailingNewLines, false, settings);
38+
public IEnumerable<string> Indent(IEnumerable<string> codeLines, bool forceTrailingNewLines, IIndenterSettings settings = null) => Indent(codeLines, forceTrailingNewLines, false, settings ?? Settings?.Invoke());
3739

3840
protected IEnumerable<string> Indent(IEnumerable<string> codeLines, bool forceTrailingNewLines, bool procedure, IIndenterSettings settings)
3941
{

0 commit comments

Comments
 (0)