EscSeqReqTests.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. namespace Terminal.Gui.InputTests;
  2. public class EscSeqReqTests
  3. {
  4. [Fact]
  5. public void Add_Tests ()
  6. {
  7. var escSeqReq = new EscSeqRequests ();
  8. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  9. Assert.Single (escSeqReq.Statuses);
  10. Assert.Equal ("t", escSeqReq.Statuses [^1].AnsiRequest.Terminator);
  11. Assert.Equal (1, escSeqReq.Statuses [^1].NumRequests);
  12. Assert.Equal (1, escSeqReq.Statuses [^1].NumOutstanding);
  13. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  14. Assert.Single (escSeqReq.Statuses);
  15. Assert.Equal ("t", escSeqReq.Statuses [^1].AnsiRequest.Terminator);
  16. Assert.Equal (2, escSeqReq.Statuses [^1].NumRequests);
  17. Assert.Equal (2, escSeqReq.Statuses [^1].NumOutstanding);
  18. escSeqReq = new ();
  19. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  20. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  21. Assert.Single (escSeqReq.Statuses);
  22. Assert.Equal ("t", escSeqReq.Statuses [^1].AnsiRequest.Terminator);
  23. Assert.Equal (2, escSeqReq.Statuses [^1].NumRequests);
  24. Assert.Equal (2, escSeqReq.Statuses [^1].NumOutstanding);
  25. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  26. Assert.Single (escSeqReq.Statuses);
  27. Assert.Equal ("t", escSeqReq.Statuses [^1].AnsiRequest.Terminator);
  28. Assert.Equal (3, escSeqReq.Statuses [^1].NumRequests);
  29. Assert.Equal (3, escSeqReq.Statuses [^1].NumOutstanding);
  30. }
  31. [Fact]
  32. public void Constructor_Defaults ()
  33. {
  34. var escSeqReq = new EscSeqRequests ();
  35. Assert.NotNull (escSeqReq.Statuses);
  36. Assert.Empty (escSeqReq.Statuses);
  37. }
  38. [Fact]
  39. public void Remove_Tests ()
  40. {
  41. var escSeqReq = new EscSeqRequests ();
  42. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  43. escSeqReq.HasResponse ("t", out EscSeqReqStatus seqReqStatus);
  44. escSeqReq.Remove (seqReqStatus);
  45. Assert.Empty (escSeqReq.Statuses);
  46. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  47. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  48. escSeqReq.HasResponse ("t", out seqReqStatus);
  49. escSeqReq.Remove (seqReqStatus);
  50. Assert.Single (escSeqReq.Statuses);
  51. Assert.Equal ("t", escSeqReq.Statuses [^1].AnsiRequest.Terminator);
  52. Assert.Equal (2, escSeqReq.Statuses [^1].NumRequests);
  53. Assert.Equal (1, escSeqReq.Statuses [^1].NumOutstanding);
  54. escSeqReq.HasResponse ("t", out seqReqStatus);
  55. escSeqReq.Remove (seqReqStatus);
  56. Assert.Empty (escSeqReq.Statuses);
  57. }
  58. [Fact]
  59. public void Requested_Tests ()
  60. {
  61. var escSeqReq = new EscSeqRequests ();
  62. Assert.False (escSeqReq.HasResponse ("t", out EscSeqReqStatus seqReqStatus));
  63. Assert.Null (seqReqStatus);
  64. escSeqReq.Add (new () { Request = "", Terminator = "t" });
  65. Assert.False (escSeqReq.HasResponse ("r", out seqReqStatus));
  66. Assert.Null (seqReqStatus);
  67. Assert.True (escSeqReq.HasResponse ("t", out seqReqStatus));
  68. Assert.NotNull (seqReqStatus);
  69. }
  70. }