| 1 | using CascadeIDE.Features.Chat; |
| 2 | using CascadeIDE.Services.Intercom; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class SlashCommandPreviewEvaluatorTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void Unknown_intercom_command_is_error() |
| 11 | { |
| 12 | var preview = SlashCommandPreviewEvaluator.Evaluate("/intercom test"); |
| 13 | Assert.Equal(SlashCommandPreviewKind.Error, preview.Kind); |
| 14 | Assert.Contains("Нет такой команды", preview.Text, StringComparison.OrdinalIgnoreCase); |
| 15 | } |
| 16 | |
| 17 | [Fact] |
| 18 | public void Message_select_without_args_is_incomplete() |
| 19 | { |
| 20 | var preview = SlashCommandPreviewEvaluator.Evaluate("/intercom message select"); |
| 21 | Assert.Equal(SlashCommandPreviewKind.Incomplete, preview.Kind); |
| 22 | Assert.Contains("диапазон", preview.Text, StringComparison.OrdinalIgnoreCase); |
| 23 | } |
| 24 | |
| 25 | [Fact] |
| 26 | public void Message_select_with_range_is_ok() |
| 27 | { |
| 28 | var preview = SlashCommandPreviewEvaluator.Evaluate("/intercom message select 5 7"); |
| 29 | Assert.Equal(SlashCommandPreviewKind.Ok, preview.Kind); |
| 30 | Assert.Contains("Сообщения", preview.Text); |
| 31 | } |
| 32 | |
| 33 | [Fact] |
| 34 | public void Typo_in_command_is_error() |
| 35 | { |
| 36 | var preview = SlashCommandPreviewEvaluator.Evaluate("/intercom mesage select 5?7"); |
| 37 | Assert.Equal(SlashCommandPreviewKind.Error, preview.Kind); |
| 38 | } |
| 39 | |
| 40 | [Fact] |
| 41 | public void Invalid_range_syntax_is_error() |
| 42 | { |
| 43 | var preview = SlashCommandPreviewEvaluator.Evaluate("/intercom message select [99;1]"); |
| 44 | Assert.Equal(SlashCommandPreviewKind.Error, preview.Kind); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void AnchorPeek_invalid_id_is_error() |
| 49 | { |
| 50 | var preview = SlashCommandPreviewEvaluator.Evaluate("/anchor peek zz"); |
| 51 | Assert.Equal(SlashCommandPreviewKind.Error, preview.Kind); |
| 52 | } |
| 53 | |
| 54 | [Fact] |
| 55 | public void AnchorPeek_without_id_is_incomplete() |
| 56 | { |
| 57 | var preview = SlashCommandPreviewEvaluator.Evaluate("/anchor peek"); |
| 58 | Assert.Equal(SlashCommandPreviewKind.Incomplete, preview.Kind); |
| 59 | } |
| 60 | |
| 61 | [Fact] |
| 62 | public void AnchorPeek_resolved_anchor_is_ok() |
| 63 | { |
| 64 | var preview = SlashCommandPreviewEvaluator.Evaluate( |
| 65 | "/anchor peek abcd1234", |
| 66 | static (string _, out SlashCommandPreviewResult result) => |
| 67 | { |
| 68 | result = new( |
| 69 | "a:abcd1234 Foo resolved", |
| 70 | SlashCommandPreviewKind.Ok); |
| 71 | return true; |
| 72 | }); |
| 73 | Assert.Equal(SlashCommandPreviewKind.Ok, preview.Kind); |
| 74 | } |
| 75 | |
| 76 | [Fact] |
| 77 | public void MapResolveOutcome_member_not_found_is_incomplete() |
| 78 | { |
| 79 | Assert.Equal( |
| 80 | SlashCommandPreviewKind.Incomplete, |
| 81 | SlashCommandPreviewEvaluator.MapResolveOutcome(IntercomAttachmentRevealPlan.OutcomeMemberNotFound)); |
| 82 | } |
| 83 | } |
| 84 | |