2
0

SixelEncoderTests.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Color = Terminal.Gui.Color;
  7. namespace UnitTests.Drawing;
  8. public class SixelEncoderTests
  9. {
  10. [Fact]
  11. public void EncodeSixel_RedSquare12x12_ReturnsExpectedSixel ()
  12. {
  13. var expected = "\u001bP" + // Start sixel sequence
  14. "0;0;0" + // Defaults for aspect ratio and grid size
  15. "q" + // Signals beginning of sixel image data
  16. "\"1;1;3;2" + // no scaling factors (1x1) and filling 3 runes horizontally and 2 vertically
  17. "#0;2;100;0;0" + // Red color definition in the format "#<index>;<type>;<R>;<G>;<B>" - 2 means RGB. The values range 0 to 100
  18. "~~~~$-" + // First 6 rows of red pixels
  19. "~~~~$-" + // Next 6 rows of red pixels
  20. "\u001b\\"; // End sixel sequence
  21. // Arrange: Create a 12x12 bitmap filled with red
  22. var pixels = new Color [12, 12];
  23. for (int x = 0; x < 12; x++)
  24. {
  25. for (int y = 0; y < 12; y++)
  26. {
  27. pixels [x, y] = new Color(255,0,0);
  28. }
  29. }
  30. // Act: Encode the image
  31. var encoder = new SixelEncoder (); // Assuming SixelEncoder is the class that contains the EncodeSixel method
  32. string result = encoder.EncodeSixel (pixels);
  33. Assert.Equal (expected, result);
  34. }
  35. }