| 1 | using CascadeIDE.Features.Shell.Application; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class CommandPaletteSelectionProjectionTests |
| 7 | { |
| 8 | [Theory] |
| 9 | [InlineData(1, 5, 3, 4)] |
| 10 | [InlineData(4, 5, 5, 0)] |
| 11 | [InlineData(0, 5, -1, 4)] |
| 12 | public void Circular_move_wraps(int current, int count, int delta, int expect) |
| 13 | { |
| 14 | Assert.True(CommandPaletteSelectionProjection.TryMoveCircular(current, delta, count, out var next)); |
| 15 | Assert.Equal(expect, next); |
| 16 | } |
| 17 | |
| 18 | [Fact] |
| 19 | public void Circular_empty_list_noop() |
| 20 | { |
| 21 | Assert.False(CommandPaletteSelectionProjection.TryMoveCircular(0, 1, 0, out var next)); |
| 22 | Assert.Equal(0, next); |
| 23 | } |
| 24 | |
| 25 | [Fact] |
| 26 | public void Page_move_clamped() |
| 27 | { |
| 28 | Assert.True(CommandPaletteSelectionProjection.TryPageMove(1, 1, 8, 10, out var n)); |
| 29 | Assert.Equal(9, n); |
| 30 | Assert.True(CommandPaletteSelectionProjection.TryPageMove(9, 1, 8, 10, out n)); |
| 31 | Assert.Equal(9, n); |
| 32 | } |
| 33 | |
| 34 | [Theory] |
| 35 | [InlineData(0, -1)] |
| 36 | [InlineData(1, 0)] |
| 37 | [InlineData(3, 0)] |
| 38 | public void Initial_index_first_or_negative(int count, int expect) => |
| 39 | Assert.Equal(expect, CommandPaletteSelectionProjection.InitialSelectedIndex(count)); |
| 40 | |
| 41 | [Theory] |
| 42 | [InlineData(10, 3, 2)] |
| 43 | [InlineData(10, 0, -1)] |
| 44 | [InlineData(2, 2, 1)] |
| 45 | public void Clamp_when_index_oob(int selected, int count, int expect) => |
| 46 | Assert.Equal(expect, CommandPaletteSelectionProjection.ClampUpperOrKeep(selected, count)); |
| 47 | |
| 48 | [Fact] |
| 49 | public void Page_move_zero_step_fails() |
| 50 | { |
| 51 | Assert.False(CommandPaletteSelectionProjection.TryPageMove(3, 0, 8, 10, out var n)); |
| 52 | Assert.Equal(3, n); |
| 53 | } |
| 54 | } |
| 55 | |