|
| 1 | +using System.Windows.Media; |
| 2 | +using DiffViewer.Models; |
| 3 | +using DiffViewer.Rendering; |
| 4 | +using FluentAssertions; |
| 5 | +using Xunit; |
| 6 | +using DiffSide = DiffViewer.Rendering.DiffSide; |
| 7 | + |
| 8 | +namespace DiffViewer.Tests.Rendering; |
| 9 | + |
| 10 | +public sealed class LineBackgroundBrushSelectorTests |
| 11 | +{ |
| 12 | + private static readonly DiffColorScheme Scheme = DiffColorScheme.Classic; |
| 13 | + |
| 14 | + [Fact] |
| 15 | + public void Pick_LeftDeleted_ReturnsStrongRemovedBrush() |
| 16 | + { |
| 17 | + // The whole point of the strong-when-no-spans rule: a Deleted |
| 18 | + // line on the left side has, by DiffHighlightMap contract, no |
| 19 | + // intra-line spans -- so the brush must be strong, not soft. |
| 20 | + var brush = LineBackgroundBrushSelector.Pick(DiffSide.Left, DiffLineKind.Deleted, Scheme); |
| 21 | + |
| 22 | + brush.Should().BeSameAs(Scheme.RemovedIntraLineBackground); |
| 23 | + brush.Should().NotBeSameAs(Scheme.RemovedLineBackground); |
| 24 | + } |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public void Pick_RightInserted_ReturnsStrongAddedBrush() |
| 28 | + { |
| 29 | + var brush = LineBackgroundBrushSelector.Pick(DiffSide.Right, DiffLineKind.Inserted, Scheme); |
| 30 | + |
| 31 | + brush.Should().BeSameAs(Scheme.AddedIntraLineBackground); |
| 32 | + brush.Should().NotBeSameAs(Scheme.AddedLineBackground); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void Pick_InlineDeleted_ReturnsStrongRemovedBrush() |
| 37 | + { |
| 38 | + var brush = LineBackgroundBrushSelector.Pick(DiffSide.Inline, DiffLineKind.Deleted, Scheme); |
| 39 | + |
| 40 | + brush.Should().BeSameAs(Scheme.RemovedIntraLineBackground); |
| 41 | + } |
| 42 | + |
| 43 | + [Fact] |
| 44 | + public void Pick_InlineInserted_ReturnsStrongAddedBrush() |
| 45 | + { |
| 46 | + var brush = LineBackgroundBrushSelector.Pick(DiffSide.Inline, DiffLineKind.Inserted, Scheme); |
| 47 | + |
| 48 | + brush.Should().BeSameAs(Scheme.AddedIntraLineBackground); |
| 49 | + } |
| 50 | + |
| 51 | + [Theory] |
| 52 | + [InlineData(DiffSide.Left)] |
| 53 | + [InlineData(DiffSide.Right)] |
| 54 | + [InlineData(DiffSide.Inline)] |
| 55 | + public void Pick_Modified_ReturnsSoftModifiedBrush(DiffSide side) |
| 56 | + { |
| 57 | + // Modified means DiffHighlightMap also attached intra-line spans; |
| 58 | + // the IntraLineColorizer overlays the strong red/green spans on |
| 59 | + // top of the soft yellow background, so the soft brush is the |
| 60 | + // correct base layer. |
| 61 | + var brush = LineBackgroundBrushSelector.Pick(side, DiffLineKind.Modified, Scheme); |
| 62 | + |
| 63 | + brush.Should().BeSameAs(Scheme.ModifiedLineBackground); |
| 64 | + } |
| 65 | + |
| 66 | + [Theory] |
| 67 | + [InlineData(DiffSide.Left, DiffLineKind.Context)] |
| 68 | + [InlineData(DiffSide.Right, DiffLineKind.Context)] |
| 69 | + [InlineData(DiffSide.Inline, DiffLineKind.Context)] |
| 70 | + [InlineData(DiffSide.Left, DiffLineKind.Inserted)] // wrong side |
| 71 | + [InlineData(DiffSide.Right, DiffLineKind.Deleted)] // wrong side |
| 72 | + public void Pick_NonTintedCases_ReturnsTransparent(DiffSide side, DiffLineKind kind) |
| 73 | + { |
| 74 | + var brush = LineBackgroundBrushSelector.Pick(side, kind, Scheme); |
| 75 | + |
| 76 | + brush.Should().BeSameAs(Brushes.Transparent); |
| 77 | + } |
| 78 | + |
| 79 | + [Fact] |
| 80 | + public void Pick_NullScheme_ThrowsArgumentNullException() |
| 81 | + { |
| 82 | + var act = () => LineBackgroundBrushSelector.Pick(DiffSide.Left, DiffLineKind.Deleted, null!); |
| 83 | + |
| 84 | + act.Should().Throw<ArgumentNullException>(); |
| 85 | + } |
| 86 | +} |
0 commit comments