zefyr

node_test.dart 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2018, the Zefyr project authors. Please see the AUTHORS file
  2. // for details. All rights reserved. Use of this source code is governed by a
  3. // BSD-style license that can be found in the LICENSE file.
  4. import 'package:notus/notus.dart';
  5. import 'package:test/test.dart';
  6. void main() {
  7. group('$Node', () {
  8. RootNode root;
  9. setUp(() {
  10. root = RootNode();
  11. });
  12. test('mounted', () {
  13. final line = LineNode();
  14. final text = TextNode();
  15. expect(text.mounted, isFalse);
  16. line.add(text);
  17. expect(text.mounted, isTrue);
  18. });
  19. test('offset', () {
  20. root.insert(0, 'First line\nSecond line', null);
  21. expect(root.children.first.offset, 0);
  22. expect(root.children.elementAt(1).offset, 11);
  23. });
  24. test('documentOffset', () {
  25. root.insert(0, 'First line\nSecond line', null);
  26. LineNode line = root.children.last;
  27. TextNode text = line.first;
  28. expect(line.documentOffset, 11);
  29. expect(text.documentOffset, 11);
  30. });
  31. test('containsOffset', () {
  32. root.insert(0, 'First line\nSecond line', null);
  33. LineNode line = root.children.last;
  34. TextNode text = line.first;
  35. expect(line.containsOffset(10), isFalse);
  36. expect(line.containsOffset(12), isTrue);
  37. expect(text.containsOffset(10), isFalse);
  38. expect(text.containsOffset(12), isTrue);
  39. });
  40. });
  41. }