operation_test.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'dart:collection';
  2. import 'package:flowy_editor/document/node.dart';
  3. import 'package:flutter_test/flutter_test.dart';
  4. import 'package:flowy_editor/operation/operation.dart';
  5. void main() {
  6. group('transform path', () {
  7. test('transform path changed', () {
  8. expect(transformPath([0, 1], [0, 1]), [0, 2]);
  9. expect(transformPath([0, 1], [0, 2]), [0, 3]);
  10. expect(transformPath([0, 1], [0, 2, 7, 8, 9]), [0, 3, 7, 8, 9]);
  11. expect(transformPath([0, 1, 2], [0, 0, 7, 8, 9]), [0, 0, 7, 8, 9]);
  12. });
  13. test("transform path not changed", () {
  14. expect(transformPath([0, 1, 2], [0, 0, 7, 8, 9]), [0, 0, 7, 8, 9]);
  15. expect(transformPath([0, 1, 2], [0, 1]), [0, 1]);
  16. });
  17. test("transform path delta", () {
  18. expect(transformPath([0, 1], [0, 1], 5), [0, 6]);
  19. });
  20. });
  21. group('transform operation', () {
  22. test('insert + insert', () {
  23. final t = transformOperation(
  24. InsertOperation(path: [
  25. 0,
  26. 1
  27. ], value: Node(type: "node", attributes: {}, children: LinkedList())),
  28. InsertOperation(
  29. path: [0, 1],
  30. value:
  31. Node(type: "node", attributes: {}, children: LinkedList())));
  32. expect(t.path, [0, 2]);
  33. });
  34. test('delete + delete', () {
  35. final t = transformOperation(
  36. DeleteOperation(
  37. path: [0, 1],
  38. removedValue:
  39. Node(type: "node", attributes: {}, children: LinkedList())),
  40. DeleteOperation(
  41. path: [0, 2],
  42. removedValue:
  43. Node(type: "node", attributes: {}, children: LinkedList())));
  44. expect(t.path, [0, 1]);
  45. });
  46. });
  47. }