buffer_line_test.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import 'package:flutter_test/flutter_test.dart';
  2. import 'package:xterm/buffer/line/line.dart';
  3. import 'package:xterm/terminal/cursor.dart';
  4. void main() {
  5. group("BufferLine Tests", () {
  6. test("creation test", () {
  7. final line = BufferLine();
  8. expect(line, isNotNull);
  9. });
  10. test("set isWrapped", () {
  11. final line = BufferLine(isWrapped: false);
  12. expect(line.isWrapped, isFalse);
  13. line.isWrapped = true;
  14. expect(line.isWrapped, isTrue);
  15. line.isWrapped = false;
  16. expect(line.isWrapped, isFalse);
  17. });
  18. test("ensure() works", () {
  19. final line = BufferLine(length: 10);
  20. expect(() => line.cellSetContent(1000, 65), throwsRangeError);
  21. line.ensure(1000);
  22. line.cellSetContent(1000, 65);
  23. });
  24. test("insert() works", () {
  25. final line = BufferLine(length: 10);
  26. line.cellSetContent(0, 65);
  27. line.cellSetContent(1, 66);
  28. line.cellSetContent(2, 67);
  29. line.insert(1);
  30. final result = [
  31. line.cellGetContent(0),
  32. line.cellGetContent(1),
  33. line.cellGetContent(2),
  34. line.cellGetContent(3),
  35. ];
  36. expect(result, equals([65, 0, 66, 67]));
  37. });
  38. test("insertN() works", () {
  39. final line = BufferLine(length: 10);
  40. line.cellSetContent(0, 65);
  41. line.cellSetContent(1, 66);
  42. line.cellSetContent(2, 67);
  43. line.insertN(1, 2);
  44. final result = [
  45. line.cellGetContent(0),
  46. line.cellGetContent(1),
  47. line.cellGetContent(2),
  48. line.cellGetContent(3),
  49. line.cellGetContent(4),
  50. ];
  51. expect(result, equals([65, 0, 0, 66, 67]));
  52. });
  53. test("removeN() works", () {
  54. final line = BufferLine(length: 10);
  55. line.cellSetContent(0, 65);
  56. line.cellSetContent(1, 66);
  57. line.cellSetContent(2, 67);
  58. line.cellSetContent(3, 68);
  59. line.cellSetContent(4, 69);
  60. line.removeN(1, 2);
  61. final result = [
  62. line.cellGetContent(0),
  63. line.cellGetContent(1),
  64. line.cellGetContent(2),
  65. line.cellGetContent(3),
  66. line.cellGetContent(4),
  67. ];
  68. expect(result, equals([65, 68, 69, 0, 0]));
  69. });
  70. test("clear() works", () {
  71. final line = BufferLine(length: 10);
  72. line.cellSetContent(1, 65);
  73. line.cellSetContent(2, 66);
  74. line.cellSetContent(3, 67);
  75. line.cellSetContent(4, 68);
  76. line.cellSetContent(5, 69);
  77. line.clear();
  78. final result = [
  79. line.cellGetContent(1),
  80. line.cellGetContent(2),
  81. line.cellGetContent(3),
  82. line.cellGetContent(4),
  83. line.cellGetContent(5),
  84. ];
  85. expect(result, equals([0, 0, 0, 0, 0]));
  86. });
  87. test("cellInitialize() works", () {
  88. final line = BufferLine(length: 10);
  89. line.cellInitialize(
  90. 0,
  91. content: 0x01,
  92. width: 0x02,
  93. cursor: Cursor(fg: 0x03, bg: 0x04, flags: 0x05),
  94. );
  95. final result = [
  96. line.cellGetContent(0),
  97. line.cellGetWidth(0),
  98. line.cellGetFgColor(0),
  99. line.cellGetBgColor(0),
  100. line.cellGetFlags(0),
  101. ];
  102. expect(result, equals([0x01, 0x02, 0x03, 0x04, 0x05]));
  103. });
  104. test("cellHasContent() works", () {
  105. final line = BufferLine(length: 10);
  106. line.cellSetContent(0, 0x01);
  107. expect(line.cellHasContent(0), isTrue);
  108. line.cellSetContent(0, 0x00);
  109. expect(line.cellHasContent(0), isFalse);
  110. });
  111. test("cellGetContent() and cellSetContent() works", () {
  112. final line = BufferLine(length: 10);
  113. final content = 0x01;
  114. line.cellSetContent(0, content);
  115. expect(line.cellGetContent(0), equals(content));
  116. });
  117. test("cellGetFgColor() and cellSetFgColor() works", () {
  118. final line = BufferLine(length: 10);
  119. final content = 0x01;
  120. line.cellSetFgColor(0, content);
  121. expect(line.cellGetFgColor(0), equals(content));
  122. });
  123. test("cellGetBgColor() and cellSetBgColor() works", () {
  124. final line = BufferLine(length: 10);
  125. final content = 0x01;
  126. line.cellSetBgColor(0, content);
  127. expect(line.cellGetBgColor(0), equals(content));
  128. });
  129. test("cellHasFlag() and cellSetFlag() works", () {
  130. final line = BufferLine(length: 10);
  131. final flag = 0x03;
  132. line.cellSetFlag(0, flag);
  133. expect(line.cellHasFlag(0, flag), isTrue);
  134. });
  135. test("cellGetFlags() and cellSetFlags() works", () {
  136. final line = BufferLine(length: 10);
  137. final content = 0x01;
  138. line.cellSetFlags(0, content);
  139. expect(line.cellGetFlags(0), equals(content));
  140. });
  141. test("cellGetWidth() and cellSetWidth() works", () {
  142. final line = BufferLine(length: 10);
  143. final content = 0x01;
  144. line.cellSetWidth(0, content);
  145. expect(line.cellGetWidth(0), equals(content));
  146. });
  147. test("getTrimmedLength() works", () {
  148. final line = BufferLine(length: 10);
  149. expect(line.getTrimmedLength(), equals(0));
  150. line.cellSetContent(5, 0x01);
  151. expect(line.getTrimmedLength(), equals(5));
  152. line.clear();
  153. expect(line.getTrimmedLength(), equals(0));
  154. });
  155. test("copyCellsFrom() works", () {
  156. final line1 = BufferLine(length: 10);
  157. final line2 = BufferLine(length: 10);
  158. line1.cellSetContent(0, 123);
  159. line1.cellSetContent(1, 124);
  160. line1.cellSetContent(2, 125);
  161. line2.copyCellsFrom(line1, 1, 3, 2);
  162. expect(line2.cellGetContent(2), equals(0));
  163. expect(line2.cellGetContent(3), equals(124));
  164. expect(line2.cellGetContent(4), equals(125));
  165. expect(line2.cellGetContent(5), equals(0));
  166. });
  167. test("removeRange() works", () {
  168. final line = BufferLine(length: 10);
  169. line.cellSetContent(0, 65);
  170. line.cellSetContent(1, 66);
  171. line.cellSetContent(2, 67);
  172. line.cellSetContent(3, 68);
  173. line.cellSetContent(4, 69);
  174. line.removeRange(1, 3);
  175. final result = [
  176. line.cellGetContent(0),
  177. line.cellGetContent(1),
  178. line.cellGetContent(2),
  179. line.cellGetContent(3),
  180. line.cellGetContent(4),
  181. ];
  182. expect(result, equals([65, 68, 69, 0, 0]));
  183. });
  184. test("clearRange() works", () {
  185. final line = BufferLine(length: 10);
  186. line.cellSetContent(0, 65);
  187. line.cellSetContent(1, 66);
  188. line.cellSetContent(2, 67);
  189. line.cellSetContent(3, 68);
  190. line.cellSetContent(4, 69);
  191. line.clearRange(1, 3);
  192. final result = [
  193. line.cellGetContent(0),
  194. line.cellGetContent(1),
  195. line.cellGetContent(2),
  196. line.cellGetContent(3),
  197. line.cellGetContent(4),
  198. ];
  199. expect(result, equals([65, 0, 0, 68, 69]));
  200. });
  201. });
  202. }