Browse Source

Added pedantic to Notus and fixed lint warnings

Anatoly Pulyaevskiy 5 years ago
parent
commit
c021f294e2

+ 1
- 19
packages/notus/analysis_options.yaml View File

1
-analyzer:
2
-  strong-mode:
3
-    implicit-dynamic: false
4
-
5
-# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
6
-linter:
7
-  rules:
8
-    - avoid_init_to_null
9
-    - cancel_subscriptions
10
-    - close_sinks
11
-    - directives_ordering
12
-    - hash_and_equals
13
-    - iterable_contains_unrelated_type
14
-    - list_remove_unrelated_type
15
-    - prefer_final_fields
16
-    - prefer_is_not_empty
17
-    - test_types_in_equals
18
-    - unrelated_type_equality_checks
19
-    - valid_regexps
1
+include: package:pedantic/analysis_options.yaml

+ 2
- 2
packages/notus/example/main.dart View File

5
 import 'package:notus/notus.dart';
5
 import 'package:notus/notus.dart';
6
 
6
 
7
 void main() {
7
 void main() {
8
-  final doc = new NotusDocument();
8
+  final doc = NotusDocument();
9
   // Modify this document with insert, delete and format operations
9
   // Modify this document with insert, delete and format operations
10
   doc.insert(
10
   doc.insert(
11
       0, 'Notus package provides rich text document model for Zefyr editor');
11
       0, 'Notus package provides rich text document model for Zefyr editor');
17
   doc.collectStyle(1, 0); // returned style would include "bold" and "h1".
17
   doc.collectStyle(1, 0); // returned style would include "bold" and "h1".
18
 
18
 
19
   // Listen to all changes applied to this document.
19
   // Listen to all changes applied to this document.
20
-  doc.changes.listen((change){
20
+  doc.changes.listen((change) {
21
     print(change);
21
     print(change);
22
   });
22
   });
23
 
23
 

+ 1
- 1
packages/notus/lib/convert.dart View File

10
 export 'src/convert/markdown.dart';
10
 export 'src/convert/markdown.dart';
11
 
11
 
12
 /// Markdown codec for Notus documents.
12
 /// Markdown codec for Notus documents.
13
-const NotusMarkdownCodec notusMarkdown = const NotusMarkdownCodec();
13
+const NotusMarkdownCodec notusMarkdown = NotusMarkdownCodec();

+ 12
- 12
packages/notus/lib/src/convert/markdown.dart View File

12
 
12
 
13
   @override
13
   @override
14
   Converter<String, Delta> get decoder =>
14
   Converter<String, Delta> get decoder =>
15
-      throw new UnimplementedError('Decoding is not implemented yet.');
15
+      throw UnimplementedError('Decoding is not implemented yet.');
16
 
16
 
17
   @override
17
   @override
18
-  Converter<Delta, String> get encoder => new _NotusMarkdownEncoder();
18
+  Converter<Delta, String> get encoder => _NotusMarkdownEncoder();
19
 }
19
 }
20
 
20
 
21
 class _NotusMarkdownEncoder extends Converter<Delta, String> {
21
 class _NotusMarkdownEncoder extends Converter<Delta, String> {
29
 
29
 
30
   @override
30
   @override
31
   String convert(Delta input) {
31
   String convert(Delta input) {
32
-    final iterator = new DeltaIterator(input);
33
-    final buffer = new StringBuffer();
34
-    final lineBuffer = new StringBuffer();
32
+    final iterator = DeltaIterator(input);
33
+    final buffer = StringBuffer();
34
+    final lineBuffer = StringBuffer();
35
     NotusAttribute<String> currentBlockStyle;
35
     NotusAttribute<String> currentBlockStyle;
36
-    NotusStyle currentInlineStyle = new NotusStyle();
36
+    NotusStyle currentInlineStyle = NotusStyle();
37
     List<String> currentBlockLines = [];
37
     List<String> currentBlockLines = [];
38
 
38
 
39
     void _handleBlock(NotusAttribute<String> blockStyle) {
39
     void _handleBlock(NotusAttribute<String> blockStyle) {
86
       if (lf == -1) {
86
       if (lf == -1) {
87
         _handleSpan(op.data, op.attributes);
87
         _handleSpan(op.data, op.attributes);
88
       } else {
88
       } else {
89
-        StringBuffer span = new StringBuffer();
89
+        StringBuffer span = StringBuffer();
90
         for (var i = 0; i < op.data.length; i++) {
90
         for (var i = 0; i < op.data.length; i++) {
91
           if (op.data.codeUnitAt(i) == 0x0A) {
91
           if (op.data.codeUnitAt(i) == 0x0A) {
92
             if (span.isNotEmpty) {
92
             if (span.isNotEmpty) {
112
   }
112
   }
113
 
113
 
114
   String _writeLine(String text, NotusStyle style) {
114
   String _writeLine(String text, NotusStyle style) {
115
-    StringBuffer buffer = new StringBuffer();
115
+    StringBuffer buffer = StringBuffer();
116
     if (style.contains(NotusAttribute.heading)) {
116
     if (style.contains(NotusAttribute.heading)) {
117
       _writeAttribute(buffer, style.get<int>(NotusAttribute.heading));
117
       _writeAttribute(buffer, style.get<int>(NotusAttribute.heading));
118
     }
118
     }
157
   }
157
   }
158
 
158
 
159
   void _writeAttribute(StringBuffer buffer, NotusAttribute attribute,
159
   void _writeAttribute(StringBuffer buffer, NotusAttribute attribute,
160
-      {bool close: false}) {
160
+      {bool close = false}) {
161
     if (attribute == NotusAttribute.bold) {
161
     if (attribute == NotusAttribute.bold) {
162
       _writeBoldTag(buffer);
162
       _writeBoldTag(buffer);
163
     } else if (attribute == NotusAttribute.italic) {
163
     } else if (attribute == NotusAttribute.italic) {
169
     } else if (attribute.key == NotusAttribute.block.key) {
169
     } else if (attribute.key == NotusAttribute.block.key) {
170
       _writeBlockTag(buffer, attribute as NotusAttribute<String>, close: close);
170
       _writeBlockTag(buffer, attribute as NotusAttribute<String>, close: close);
171
     } else {
171
     } else {
172
-      throw new ArgumentError('Cannot handle $attribute');
172
+      throw ArgumentError('Cannot handle $attribute');
173
     }
173
     }
174
   }
174
   }
175
 
175
 
182
   }
182
   }
183
 
183
 
184
   void _writeLinkTag(StringBuffer buffer, NotusAttribute<String> link,
184
   void _writeLinkTag(StringBuffer buffer, NotusAttribute<String> link,
185
-      {bool close: false}) {
185
+      {bool close = false}) {
186
     if (close) {
186
     if (close) {
187
       buffer.write('](${link.value})');
187
       buffer.write('](${link.value})');
188
     } else {
188
     } else {
196
   }
196
   }
197
 
197
 
198
   void _writeBlockTag(StringBuffer buffer, NotusAttribute<String> block,
198
   void _writeBlockTag(StringBuffer buffer, NotusAttribute<String> block,
199
-      {bool close: false}) {
199
+      {bool close = false}) {
200
     if (block == NotusAttribute.code) {
200
     if (block == NotusAttribute.code) {
201
       if (close) {
201
       if (close) {
202
         buffer.write('\n```');
202
         buffer.write('\n```');

+ 9
- 9
packages/notus/lib/src/document.dart View File

40
   /// Creates new empty Notus document.
40
   /// Creates new empty Notus document.
41
   NotusDocument()
41
   NotusDocument()
42
       : _heuristics = NotusHeuristics.fallback,
42
       : _heuristics = NotusHeuristics.fallback,
43
-        _delta = new Delta()..insert('\n') {
43
+        _delta = Delta()..insert('\n') {
44
     _loadDocument(_delta);
44
     _loadDocument(_delta);
45
   }
45
   }
46
 
46
 
61
 
61
 
62
   /// The root node of this document tree.
62
   /// The root node of this document tree.
63
   RootNode get root => _root;
63
   RootNode get root => _root;
64
-  final RootNode _root = new RootNode();
64
+  final RootNode _root = RootNode();
65
 
65
 
66
   /// Length of this document.
66
   /// Length of this document.
67
   int get length => _root.length;
67
   int get length => _root.length;
70
   Stream<NotusChange> get changes => _controller.stream;
70
   Stream<NotusChange> get changes => _controller.stream;
71
 
71
 
72
   final StreamController<NotusChange> _controller =
72
   final StreamController<NotusChange> _controller =
73
-      new StreamController.broadcast();
73
+      StreamController.broadcast();
74
 
74
 
75
   /// Returns contents of this document as [Delta].
75
   /// Returns contents of this document as [Delta].
76
-  Delta toDelta() => new Delta.from(_delta);
76
+  Delta toDelta() => Delta.from(_delta);
77
   Delta _delta;
77
   Delta _delta;
78
 
78
 
79
   /// Returns plain text representation of this document.
79
   /// Returns plain text representation of this document.
104
     assert(index >= 0);
104
     assert(index >= 0);
105
     assert(text.isNotEmpty);
105
     assert(text.isNotEmpty);
106
     text = _sanitizeString(text);
106
     text = _sanitizeString(text);
107
-    if (text.isEmpty) return new Delta();
107
+    if (text.isEmpty) return Delta();
108
     final change = _heuristics.applyInsertRules(this, index, text);
108
     final change = _heuristics.applyInsertRules(this, index, text);
109
     compose(change, ChangeSource.local);
109
     compose(change, ChangeSource.local);
110
     return change;
110
     return change;
136
   Delta replace(int index, int length, String text) {
136
   Delta replace(int index, int length, String text) {
137
     assert(index >= 0 && (text.isNotEmpty || length > 0),
137
     assert(index >= 0 && (text.isNotEmpty || length > 0),
138
         'With index $index, length $length and text "$text"');
138
         'With index $index, length $length and text "$text"');
139
-    Delta delta = new Delta();
139
+    Delta delta = Delta();
140
     // We have to compose before applying delete rules
140
     // We have to compose before applying delete rules
141
     // Otherwise delete would be operating on stale document snapshot.
141
     // Otherwise delete would be operating on stale document snapshot.
142
     if (text.isNotEmpty) {
142
     if (text.isNotEmpty) {
239
     _delta = _delta.compose(change);
239
     _delta = _delta.compose(change);
240
 
240
 
241
     if (_delta != _root.toDelta()) {
241
     if (_delta != _root.toDelta()) {
242
-      throw new StateError('Compose produced inconsistent results. '
242
+      throw StateError('Compose produced inconsistent results. '
243
           'This is likely due to a bug in the library. Tried to compose change $change from $source.');
243
           'This is likely due to a bug in the library. Tried to compose change $change from $source.');
244
     }
244
     }
245
-    _controller.add(new NotusChange(before, change, source));
245
+    _controller.add(NotusChange(before, change, source));
246
   }
246
   }
247
 
247
 
248
   //
248
   //
279
       if (op.isInsert) {
279
       if (op.isInsert) {
280
         _root.insert(offset, op.data, style);
280
         _root.insert(offset, op.data, style);
281
       } else {
281
       } else {
282
-        throw new ArgumentError.value(doc,
282
+        throw ArgumentError.value(doc,
283
             "Document Delta can only contain insert operations but ${op.key} found.");
283
             "Document Delta can only contain insert operations but ${op.key} found.");
284
       }
284
       }
285
       offset += op.length;
285
       offset += op.length;

+ 39
- 34
packages/notus/lib/src/document/attributes.dart View File

40
 
40
 
41
   final String key;
41
   final String key;
42
   final NotusAttributeScope scope;
42
   final NotusAttributeScope scope;
43
-  NotusAttribute<T> get unset => new NotusAttribute<T>._(key, scope, null);
43
+  NotusAttribute<T> get unset => NotusAttribute<T>._(key, scope, null);
44
   NotusAttribute<T> withValue(T value) =>
44
   NotusAttribute<T> withValue(T value) =>
45
-      new NotusAttribute<T>._(key, scope, value);
45
+      NotusAttribute<T>._(key, scope, value);
46
 }
46
 }
47
 
47
 
48
 /// Style attribute applicable to a segment of a Notus document.
48
 /// Style attribute applicable to a segment of a Notus document.
82
   // Inline attributes
82
   // Inline attributes
83
 
83
 
84
   /// Bold style attribute.
84
   /// Bold style attribute.
85
-  static const bold = const _BoldAttribute();
85
+  static const bold = _BoldAttribute();
86
 
86
 
87
   /// Italic style attribute.
87
   /// Italic style attribute.
88
-  static const italic = const _ItalicAttribute();
88
+  static const italic = _ItalicAttribute();
89
 
89
 
90
   /// Link style attribute.
90
   /// Link style attribute.
91
-  static const link = const LinkAttributeBuilder._();
91
+  // ignore: const_eval_throws_exception
92
+  static const link = LinkAttributeBuilder._();
92
 
93
 
93
   // Line attributes
94
   // Line attributes
94
 
95
 
95
   /// Heading style attribute.
96
   /// Heading style attribute.
96
-  static const heading = const HeadingAttributeBuilder._();
97
+  // ignore: const_eval_throws_exception
98
+  static const heading = HeadingAttributeBuilder._();
97
 
99
 
98
   /// Alias for [NotusAttribute.heading.level1].
100
   /// Alias for [NotusAttribute.heading.level1].
99
   static NotusAttribute<int> get h1 => heading.level1;
101
   static NotusAttribute<int> get h1 => heading.level1;
105
   static NotusAttribute<int> get h3 => heading.level3;
107
   static NotusAttribute<int> get h3 => heading.level3;
106
 
108
 
107
   /// Block attribute
109
   /// Block attribute
108
-  static const block = const BlockAttributeBuilder._();
110
+  // ignore: const_eval_throws_exception
111
+  static const block = BlockAttributeBuilder._();
109
 
112
 
110
   /// Alias for [NotusAttribute.block.bulletList].
113
   /// Alias for [NotusAttribute.block.bulletList].
111
   static NotusAttribute<String> get ul => block.bulletList;
114
   static NotusAttribute<String> get ul => block.bulletList;
120
   static NotusAttribute<String> get code => block.code;
123
   static NotusAttribute<String> get code => block.code;
121
 
124
 
122
   /// Embed style attribute.
125
   /// Embed style attribute.
123
-  static const embed = const EmbedAttributeBuilder._();
126
+  // ignore: const_eval_throws_exception
127
+  static const embed = EmbedAttributeBuilder._();
124
 
128
 
125
   static NotusAttribute _fromKeyValue(String key, dynamic value) {
129
   static NotusAttribute _fromKeyValue(String key, dynamic value) {
126
-    if (!_registry.containsKey(key))
127
-      throw new ArgumentError.value(
130
+    if (!_registry.containsKey(key)) {
131
+      throw ArgumentError.value(
128
           key, 'No attribute with key "$key" registered.');
132
           key, 'No attribute with key "$key" registered.');
133
+    }
129
     final builder = _registry[key];
134
     final builder = _registry[key];
130
     return builder.withValue(value);
135
     return builder.withValue(value);
131
   }
136
   }
154
   ///
159
   ///
155
   /// When composed into a rich text document, unset attributes remove
160
   /// When composed into a rich text document, unset attributes remove
156
   /// associated style.
161
   /// associated style.
157
-  NotusAttribute<T> get unset => new NotusAttribute<T>._(key, scope, null);
162
+  NotusAttribute<T> get unset => NotusAttribute<T>._(key, scope, null);
158
 
163
 
159
   /// Returns `true` if this attribute is an unset attribute.
164
   /// Returns `true` if this attribute is an unset attribute.
160
   bool get isUnset => value == null;
165
   bool get isUnset => value == null;
163
   bool get isInline => scope == NotusAttributeScope.inline;
168
   bool get isInline => scope == NotusAttributeScope.inline;
164
 
169
 
165
   NotusAttribute<T> withValue(T value) =>
170
   NotusAttribute<T> withValue(T value) =>
166
-      new NotusAttribute<T>._(key, scope, value);
171
+      NotusAttribute<T>._(key, scope, value);
167
 
172
 
168
   @override
173
   @override
169
   bool operator ==(Object other) {
174
   bool operator ==(Object other) {
191
   final Map<String, NotusAttribute> _data;
196
   final Map<String, NotusAttribute> _data;
192
 
197
 
193
   static NotusStyle fromJson(Map<String, dynamic> data) {
198
   static NotusStyle fromJson(Map<String, dynamic> data) {
194
-    if (data == null) return new NotusStyle();
199
+    if (data == null) return NotusStyle();
195
 
200
 
196
     final result = data.map((String key, dynamic value) {
201
     final result = data.map((String key, dynamic value) {
197
       var attr = NotusAttribute._fromKeyValue(key, value);
202
       var attr = NotusAttribute._fromKeyValue(key, value);
198
-      return new MapEntry<String, NotusAttribute>(key, attr);
203
+      return MapEntry<String, NotusAttribute>(key, attr);
199
     });
204
     });
200
-    return new NotusStyle._(result);
205
+    return NotusStyle._(result);
201
   }
206
   }
202
 
207
 
203
-  NotusStyle() : _data = new Map<String, NotusAttribute>();
208
+  NotusStyle() : _data = Map<String, NotusAttribute>();
204
 
209
 
205
   /// Returns `true` if this attribute set is empty.
210
   /// Returns `true` if this attribute set is empty.
206
   bool get isEmpty => _data.isEmpty;
211
   bool get isEmpty => _data.isEmpty;
246
 
251
 
247
   /// Puts [attribute] into this attribute set and returns result as a new set.
252
   /// Puts [attribute] into this attribute set and returns result as a new set.
248
   NotusStyle put(NotusAttribute attribute) {
253
   NotusStyle put(NotusAttribute attribute) {
249
-    final result = new Map<String, NotusAttribute>.from(_data);
254
+    final result = Map<String, NotusAttribute>.from(_data);
250
     result[attribute.key] = attribute;
255
     result[attribute.key] = attribute;
251
-    return new NotusStyle._(result);
256
+    return NotusStyle._(result);
252
   }
257
   }
253
 
258
 
254
   /// Merges this attribute set with [attribute] and returns result as a new
259
   /// Merges this attribute set with [attribute] and returns result as a new
260
   /// See also [put] method which does not perform compaction and allows
265
   /// See also [put] method which does not perform compaction and allows
261
   /// constructing styles with "unset" values.
266
   /// constructing styles with "unset" values.
262
   NotusStyle merge(NotusAttribute attribute) {
267
   NotusStyle merge(NotusAttribute attribute) {
263
-    final merged = new Map<String, NotusAttribute>.from(_data);
268
+    final merged = Map<String, NotusAttribute>.from(_data);
264
     if (attribute.isUnset) {
269
     if (attribute.isUnset) {
265
       merged.remove(attribute.key);
270
       merged.remove(attribute.key);
266
     } else {
271
     } else {
267
       merged[attribute.key] = attribute;
272
       merged[attribute.key] = attribute;
268
     }
273
     }
269
-    return new NotusStyle._(merged);
274
+    return NotusStyle._(merged);
270
   }
275
   }
271
 
276
 
272
   /// Merges all attributes from [other] into this style and returns result
277
   /// Merges all attributes from [other] into this style and returns result
273
   /// as a new instance of [NotusStyle].
278
   /// as a new instance of [NotusStyle].
274
   NotusStyle mergeAll(NotusStyle other) {
279
   NotusStyle mergeAll(NotusStyle other) {
275
-    var result = new NotusStyle._(_data);
280
+    var result = NotusStyle._(_data);
276
     for (var value in other.values) {
281
     for (var value in other.values) {
277
       result = result.merge(value);
282
       result = result.merge(value);
278
     }
283
     }
282
   /// Removes [attributes] from this style and returns new instance of
287
   /// Removes [attributes] from this style and returns new instance of
283
   /// [NotusStyle] containing result.
288
   /// [NotusStyle] containing result.
284
   NotusStyle removeAll(Iterable<NotusAttribute> attributes) {
289
   NotusStyle removeAll(Iterable<NotusAttribute> attributes) {
285
-    final merged = new Map<String, NotusAttribute>.from(_data);
290
+    final merged = Map<String, NotusAttribute>.from(_data);
286
     attributes.map((item) => item.key).forEach(merged.remove);
291
     attributes.map((item) => item.key).forEach(merged.remove);
287
-    return new NotusStyle._(merged);
292
+    return NotusStyle._(merged);
288
   }
293
   }
289
 
294
 
290
   /// Returns JSON-serializable representation of this style.
295
   /// Returns JSON-serializable representation of this style.
291
   Map<String, dynamic> toJson() => _data.isEmpty
296
   Map<String, dynamic> toJson() => _data.isEmpty
292
       ? null
297
       ? null
293
       : _data.map<String, dynamic>((String _, NotusAttribute value) =>
298
       : _data.map<String, dynamic>((String _, NotusAttribute value) =>
294
-          new MapEntry<String, dynamic>(value.key, value.value));
299
+          MapEntry<String, dynamic>(value.key, value.value));
295
 
300
 
296
   @override
301
   @override
297
   bool operator ==(Object other) {
302
   bool operator ==(Object other) {
332
 
337
 
333
   /// Creates a link attribute with specified link [value].
338
   /// Creates a link attribute with specified link [value].
334
   NotusAttribute<String> fromString(String value) =>
339
   NotusAttribute<String> fromString(String value) =>
335
-      new NotusAttribute<String>._(key, scope, value);
340
+      NotusAttribute<String>._(key, scope, value);
336
 }
341
 }
337
 
342
 
338
 /// Builder for heading attribute styles.
343
 /// Builder for heading attribute styles.
345
       : super._(_kHeading, NotusAttributeScope.line);
350
       : super._(_kHeading, NotusAttributeScope.line);
346
 
351
 
347
   /// Level 1 heading, equivalent of `H1` in HTML.
352
   /// Level 1 heading, equivalent of `H1` in HTML.
348
-  NotusAttribute<int> get level1 => new NotusAttribute<int>._(key, scope, 1);
353
+  NotusAttribute<int> get level1 => NotusAttribute<int>._(key, scope, 1);
349
 
354
 
350
   /// Level 2 heading, equivalent of `H2` in HTML.
355
   /// Level 2 heading, equivalent of `H2` in HTML.
351
-  NotusAttribute<int> get level2 => new NotusAttribute<int>._(key, scope, 2);
356
+  NotusAttribute<int> get level2 => NotusAttribute<int>._(key, scope, 2);
352
 
357
 
353
   /// Level 3 heading, equivalent of `H3` in HTML.
358
   /// Level 3 heading, equivalent of `H3` in HTML.
354
-  NotusAttribute<int> get level3 => new NotusAttribute<int>._(key, scope, 3);
359
+  NotusAttribute<int> get level3 => NotusAttribute<int>._(key, scope, 3);
355
 }
360
 }
356
 
361
 
357
 /// Builder for block attribute styles (number/bullet lists, code and quote).
362
 /// Builder for block attribute styles (number/bullet lists, code and quote).
364
 
369
 
365
   /// Formats a block of lines as a bullet list.
370
   /// Formats a block of lines as a bullet list.
366
   NotusAttribute<String> get bulletList =>
371
   NotusAttribute<String> get bulletList =>
367
-      new NotusAttribute<String>._(key, scope, 'ul');
372
+      NotusAttribute<String>._(key, scope, 'ul');
368
 
373
 
369
   /// Formats a block of lines as a number list.
374
   /// Formats a block of lines as a number list.
370
   NotusAttribute<String> get numberList =>
375
   NotusAttribute<String> get numberList =>
371
-      new NotusAttribute<String>._(key, scope, 'ol');
376
+      NotusAttribute<String>._(key, scope, 'ol');
372
 
377
 
373
   /// Formats a block of lines as a code snippet, using monospace font.
378
   /// Formats a block of lines as a code snippet, using monospace font.
374
   NotusAttribute<String> get code =>
379
   NotusAttribute<String> get code =>
375
-      new NotusAttribute<String>._(key, scope, 'code');
380
+      NotusAttribute<String>._(key, scope, 'code');
376
 
381
 
377
   /// Formats a block of lines as a quote.
382
   /// Formats a block of lines as a quote.
378
   NotusAttribute<String> get quote =>
383
   NotusAttribute<String> get quote =>
379
-      new NotusAttribute<String>._(key, scope, 'quote');
384
+      NotusAttribute<String>._(key, scope, 'quote');
380
 }
385
 }
381
 
386
 
382
 class EmbedAttributeBuilder
387
 class EmbedAttributeBuilder
401
 enum EmbedType { horizontalRule, image }
406
 enum EmbedType { horizontalRule, image }
402
 
407
 
403
 class EmbedAttribute extends NotusAttribute<Map<String, dynamic>> {
408
 class EmbedAttribute extends NotusAttribute<Map<String, dynamic>> {
404
-  static const _kValueEquality = const MapEquality<String, dynamic>();
409
+  static const _kValueEquality = MapEquality<String, dynamic>();
405
   static const _kEmbed = 'embed';
410
   static const _kEmbed = 'embed';
406
   static const _kHorizontalRuleEmbed = 'hr';
411
   static const _kHorizontalRuleEmbed = 'hr';
407
   static const _kImageEmbed = 'image';
412
   static const _kImageEmbed = 'image';
424
   }
429
   }
425
 
430
 
426
   @override
431
   @override
427
-  NotusAttribute<Map<String, dynamic>> get unset => new EmbedAttribute._(null);
432
+  NotusAttribute<Map<String, dynamic>> get unset => EmbedAttribute._(null);
428
 
433
 
429
   @override
434
   @override
430
   bool operator ==(other) {
435
   bool operator ==(other) {

+ 4
- 4
packages/notus/lib/src/document/block.dart View File

16
     implements StyledNode {
16
     implements StyledNode {
17
   /// Creates new unmounted [BlockNode] with the same attributes.
17
   /// Creates new unmounted [BlockNode] with the same attributes.
18
   BlockNode clone() {
18
   BlockNode clone() {
19
-    final node = new BlockNode();
19
+    final node = BlockNode();
20
     node.applyStyle(style);
20
     node.applyStyle(style);
21
     return node;
21
     return node;
22
   }
22
   }
49
   }
49
   }
50
 
50
 
51
   @override
51
   @override
52
-  LineNode get defaultChild => new LineNode();
52
+  LineNode get defaultChild => LineNode();
53
 
53
 
54
   @override
54
   @override
55
   Delta toDelta() {
55
   Delta toDelta() {
56
     // Line nodes take care of incorporating block style into their delta.
56
     // Line nodes take care of incorporating block style into their delta.
57
     return children
57
     return children
58
         .map((child) => child.toDelta())
58
         .map((child) => child.toDelta())
59
-        .fold(new Delta(), (a, b) => a.concat(b));
59
+        .fold(Delta(), (a, b) => a.concat(b));
60
   }
60
   }
61
 
61
 
62
   @override
62
   @override
63
   String toString() {
63
   String toString() {
64
     final block = style.value(NotusAttribute.block);
64
     final block = style.value(NotusAttribute.block);
65
-    final buffer = new StringBuffer('§ {$block}\n');
65
+    final buffer = StringBuffer('§ {$block}\n');
66
     for (var child in children) {
66
     for (var child in children) {
67
       final tree = child.isLast ? '└' : '├';
67
       final tree = child.isLast ? '└' : '├';
68
       buffer.write('  $tree $child');
68
       buffer.write('  $tree $child');

+ 7
- 7
packages/notus/lib/src/document/leaf.dart View File

22
     LeafNode node;
22
     LeafNode node;
23
     if (value == kZeroWidthSpace) {
23
     if (value == kZeroWidthSpace) {
24
       // Zero-width space is reserved for embed nodes.
24
       // Zero-width space is reserved for embed nodes.
25
-      node = new EmbedNode();
25
+      node = EmbedNode();
26
     } else {
26
     } else {
27
       assert(
27
       assert(
28
           !value.contains(kZeroWidthSpace),
28
           !value.contains(kZeroWidthSpace),
29
           'Zero-width space is reserved for embed leaf nodes and cannot be used '
29
           'Zero-width space is reserved for embed leaf nodes and cannot be used '
30
           'inside regular text nodes.');
30
           'inside regular text nodes.');
31
-      node = new TextNode(value);
31
+      node = TextNode(value);
32
     }
32
     }
33
     return node;
33
     return node;
34
   }
34
   }
56
 
56
 
57
     String text = _value;
57
     String text = _value;
58
     _value = text.substring(0, index);
58
     _value = text.substring(0, index);
59
-    final split = new LeafNode(text.substring(index));
59
+    final split = LeafNode(text.substring(index));
60
     split.applyStyle(style);
60
     split.applyStyle(style);
61
     insertAfter(split);
61
     insertAfter(split);
62
     return split;
62
     return split;
131
 
131
 
132
   @override
132
   @override
133
   Delta toDelta() {
133
   Delta toDelta() {
134
-    return new Delta()..insert(_value, style.toJson());
134
+    return Delta()..insert(_value, style.toJson());
135
   }
135
   }
136
 
136
 
137
   @override
137
   @override
141
   void insert(int index, String value, NotusStyle style) {
141
   void insert(int index, String value, NotusStyle style) {
142
     assert(index >= 0 && (index <= length), 'Index: $index, Length: $length.');
142
     assert(index >= 0 && (index <= length), 'Index: $index, Length: $length.');
143
     assert(value.isNotEmpty);
143
     assert(value.isNotEmpty);
144
-    final node = new LeafNode(value);
144
+    final node = LeafNode(value);
145
     if (index == length) {
145
     if (index == length) {
146
       insertAfter(node);
146
       insertAfter(node);
147
     } else {
147
     } else {
231
   TextNode([String content = '']) : super._(content);
231
   TextNode([String content = '']) : super._(content);
232
 }
232
 }
233
 
233
 
234
-final kZeroWidthSpace = new String.fromCharCode(0x200b);
234
+final kZeroWidthSpace = String.fromCharCode(0x200b);
235
 
235
 
236
 /// An embed node inside of a line in a Notus document.
236
 /// An embed node inside of a line in a Notus document.
237
 ///
237
 ///
248
 /// applying "bold" style to an image gives no effect, while adding a "link" to
248
 /// applying "bold" style to an image gives no effect, while adding a "link" to
249
 /// an image actually makes the image react to user's action.
249
 /// an image actually makes the image react to user's action.
250
 class EmbedNode extends LeafNode {
250
 class EmbedNode extends LeafNode {
251
-  static final kPlainTextPlaceholder = new String.fromCharCode(0x200b);
251
+  static final kPlainTextPlaceholder = String.fromCharCode(0x200b);
252
 
252
 
253
   EmbedNode() : super._(kPlainTextPlaceholder);
253
   EmbedNode() : super._(kPlainTextPlaceholder);
254
 }
254
 }

+ 13
- 11
packages/notus/lib/src/document/line.dart View File

38
             ? (parent.next as BlockNode).first
38
             ? (parent.next as BlockNode).first
39
             : parent.next;
39
             : parent.next;
40
         return line;
40
         return line;
41
-      } else
41
+      } else {
42
         return null;
42
         return null;
43
+      }
43
     } else {
44
     } else {
44
       LineNode line = (next is BlockNode) ? (next as BlockNode).first : next;
45
       LineNode line = (next is BlockNode) ? (next as BlockNode).first : next;
45
       return line;
46
       return line;
48
 
49
 
49
   /// Creates new empty [LineNode] with the same style.
50
   /// Creates new empty [LineNode] with the same style.
50
   LineNode clone() {
51
   LineNode clone() {
51
-    final node = new LineNode();
52
+    final node = LineNode();
52
     node.applyStyle(style);
53
     node.applyStyle(style);
53
     return node;
54
     return node;
54
   }
55
   }
107
   NotusStyle collectStyle(int offset, int length) {
108
   NotusStyle collectStyle(int offset, int length) {
108
     int local = math.min(this.length - offset, length);
109
     int local = math.min(this.length - offset, length);
109
 
110
 
110
-    NotusStyle result = new NotusStyle();
111
-    Set<NotusAttribute> excluded = new Set();
111
+    NotusStyle result = NotusStyle();
112
+    Set<NotusAttribute> excluded = Set();
112
 
113
 
113
     void _handle(NotusStyle style) {
114
     void _handle(NotusStyle style) {
114
       if (result.isEmpty) {
115
       if (result.isEmpty) {
153
   }
154
   }
154
 
155
 
155
   @override
156
   @override
156
-  LeafNode get defaultChild => new TextNode();
157
+  LeafNode get defaultChild => TextNode();
157
 
158
 
158
   // TODO: should be able to cache length and invalidate on any child-related operation
159
   // TODO: should be able to cache length and invalidate on any child-related operation
159
   @override
160
   @override
163
   Delta toDelta() {
164
   Delta toDelta() {
164
     final Delta delta = children
165
     final Delta delta = children
165
         .map((text) => text.toDelta())
166
         .map((text) => text.toDelta())
166
-        .fold(new Delta(), (a, b) => a.concat(b));
167
+        .fold(Delta(), (a, b) => a.concat(b));
167
     var attributes = style;
168
     var attributes = style;
168
     if (parent is BlockNode) {
169
     if (parent is BlockNode) {
169
       BlockNode block = parent;
170
       BlockNode block = parent;
293
     if (newStyle == null || newStyle.isEmpty) return;
294
     if (newStyle == null || newStyle.isEmpty) return;
294
 
295
 
295
     applyStyle(newStyle);
296
     applyStyle(newStyle);
296
-    if (!newStyle.contains(NotusAttribute.block))
297
-      return; // no block-level changes
297
+    if (!newStyle.contains(NotusAttribute.block)) {
298
+      return;
299
+    } // no block-level changes
298
 
300
 
299
     final blockStyle = newStyle.get(NotusAttribute.block);
301
     final blockStyle = newStyle.get(NotusAttribute.block);
300
     if (parent is BlockNode) {
302
     if (parent is BlockNode) {
303
         unwrap();
305
         unwrap();
304
       } else if (blockStyle != parentStyle) {
306
       } else if (blockStyle != parentStyle) {
305
         unwrap();
307
         unwrap();
306
-        BlockNode block = new BlockNode();
308
+        BlockNode block = BlockNode();
307
         block.applyAttribute(blockStyle);
309
         block.applyAttribute(blockStyle);
308
         wrap(block);
310
         wrap(block);
309
         block.optimize();
311
         block.optimize();
310
       } // else the same style, no-op.
312
       } // else the same style, no-op.
311
     } else if (blockStyle != NotusAttribute.block.unset) {
313
     } else if (blockStyle != NotusAttribute.block.unset) {
312
       // Only wrap with a new block if this is not an unset
314
       // Only wrap with a new block if this is not an unset
313
-      BlockNode block = new BlockNode();
315
+      BlockNode block = BlockNode();
314
       block.applyAttribute(blockStyle);
316
       block.applyAttribute(blockStyle);
315
       wrap(block);
317
       wrap(block);
316
       block.optimize();
318
       block.optimize();
323
     if (text.isEmpty) return;
325
     if (text.isEmpty) return;
324
 
326
 
325
     if (isEmpty) {
327
     if (isEmpty) {
326
-      final child = new LeafNode(text);
328
+      final child = LeafNode(text);
327
       add(child);
329
       add(child);
328
       child.formatAndOptimize(style);
330
       child.formatAndOptimize(style);
329
     } else {
331
     } else {

+ 8
- 8
packages/notus/lib/src/document/node.dart View File

136
 /// Most of the operation handling logic is implemented by [LineNode] and
136
 /// Most of the operation handling logic is implemented by [LineNode] and
137
 /// [TextNode].
137
 /// [TextNode].
138
 abstract class ContainerNode<T extends Node> extends Node {
138
 abstract class ContainerNode<T extends Node> extends Node {
139
-  final LinkedList<Node> _children = new LinkedList<Node>();
139
+  final LinkedList<Node> _children = LinkedList<Node>();
140
 
140
 
141
   /// List of children.
141
   /// List of children.
142
   LinkedList<Node> get children => _children;
142
   LinkedList<Node> get children => _children;
207
   /// [LookupResult.offset] is set to relative offset within returned child node
207
   /// [LookupResult.offset] is set to relative offset within returned child node
208
   /// which points at the same character position in the document as the
208
   /// which points at the same character position in the document as the
209
   /// original [offset].
209
   /// original [offset].
210
-  LookupResult lookup(int offset, {bool inclusive: false}) {
210
+  LookupResult lookup(int offset, {bool inclusive = false}) {
211
     assert(offset >= 0 && offset <= this.length);
211
     assert(offset >= 0 && offset <= this.length);
212
 
212
 
213
     for (Node node in children) {
213
     for (Node node in children) {
214
       final int length = node.length;
214
       final int length = node.length;
215
       if (offset < length || (inclusive && offset == length && (node.isLast))) {
215
       if (offset < length || (inclusive && offset == length && (node.isLast))) {
216
-        return new LookupResult(node, offset);
216
+        return LookupResult(node, offset);
217
       }
217
       }
218
       offset -= length;
218
       offset -= length;
219
     }
219
     }
220
-    return new LookupResult(null, 0);
220
+    return LookupResult(null, 0);
221
   }
221
   }
222
 
222
 
223
   //
223
   //
275
 abstract class StyledNodeMixin implements StyledNode {
275
 abstract class StyledNodeMixin implements StyledNode {
276
   @override
276
   @override
277
   NotusStyle get style => _style;
277
   NotusStyle get style => _style;
278
-  NotusStyle _style = new NotusStyle();
278
+  NotusStyle _style = NotusStyle();
279
 
279
 
280
   /// Applies style [attribute] to this node.
280
   /// Applies style [attribute] to this node.
281
   void applyAttribute(NotusAttribute attribute) {
281
   void applyAttribute(NotusAttribute attribute) {
291
 
291
 
292
   /// Clears style of this node.
292
   /// Clears style of this node.
293
   void clearStyle() {
293
   void clearStyle() {
294
-    _style = new NotusStyle();
294
+    _style = NotusStyle();
295
   }
295
   }
296
 }
296
 }
297
 
297
 
298
 /// Root node of document tree.
298
 /// Root node of document tree.
299
 class RootNode extends ContainerNode<ContainerNode<Node>> {
299
 class RootNode extends ContainerNode<ContainerNode<Node>> {
300
   @override
300
   @override
301
-  ContainerNode<Node> get defaultChild => new LineNode();
301
+  ContainerNode<Node> get defaultChild => LineNode();
302
 
302
 
303
   @override
303
   @override
304
   void optimize() {/* no-op */}
304
   void optimize() {/* no-op */}
306
   @override
306
   @override
307
   Delta toDelta() => children
307
   Delta toDelta() => children
308
       .map((child) => child.toDelta())
308
       .map((child) => child.toDelta())
309
-      .fold(new Delta(), (a, b) => a.concat(b));
309
+      .fold(Delta(), (a, b) => a.concat(b));
310
 }
310
 }

+ 3
- 6
packages/notus/lib/src/heuristics.dart View File

62
       final result = rule.apply(delta, index, insert);
62
       final result = rule.apply(delta, index, insert);
63
       if (result != null) return result..trim();
63
       if (result != null) return result..trim();
64
     }
64
     }
65
-    throw new StateError(
66
-        'Failed to apply insert heuristic rules: none applied.');
65
+    throw StateError('Failed to apply insert heuristic rules: none applied.');
67
   }
66
   }
68
 
67
 
69
   /// Applies heuristic rules to specified format operation based on current
68
   /// Applies heuristic rules to specified format operation based on current
75
       final result = rule.apply(delta, index, length, value);
74
       final result = rule.apply(delta, index, length, value);
76
       if (result != null) return result..trim();
75
       if (result != null) return result..trim();
77
     }
76
     }
78
-    throw new StateError(
79
-        'Failed to apply format heuristic rules: none applied.');
77
+    throw StateError('Failed to apply format heuristic rules: none applied.');
80
   }
78
   }
81
 
79
 
82
   /// Applies heuristic rules to specified delete operation based on current
80
   /// Applies heuristic rules to specified delete operation based on current
87
       final result = rule.apply(delta, index, length);
85
       final result = rule.apply(delta, index, length);
88
       if (result != null) return result..trim();
86
       if (result != null) return result..trim();
89
     }
87
     }
90
-    throw new StateError(
91
-        'Failed to apply delete heuristic rules: none applied.');
88
+    throw StateError('Failed to apply delete heuristic rules: none applied.');
92
   }
89
   }
93
 }
90
 }

+ 7
- 7
packages/notus/lib/src/heuristics/delete_rules.dart View File

22
 
22
 
23
   @override
23
   @override
24
   Delta apply(Delta document, int index, int length) {
24
   Delta apply(Delta document, int index, int length) {
25
-    return new Delta()
25
+    return Delta()
26
       ..retain(index)
26
       ..retain(index)
27
       ..delete(length);
27
       ..delete(length);
28
   }
28
   }
39
 
39
 
40
   @override
40
   @override
41
   Delta apply(Delta document, int index, int length) {
41
   Delta apply(Delta document, int index, int length) {
42
-    DeltaIterator iter = new DeltaIterator(document);
42
+    DeltaIterator iter = DeltaIterator(document);
43
     iter.skip(index);
43
     iter.skip(index);
44
     final target = iter.next(1);
44
     final target = iter.next(1);
45
     if (target.data != '\n') return null;
45
     if (target.data != '\n') return null;
46
     iter.skip(length - 1);
46
     iter.skip(length - 1);
47
-    final Delta result = new Delta()
47
+    final Delta result = Delta()
48
       ..retain(index)
48
       ..retain(index)
49
       ..delete(length);
49
       ..delete(length);
50
 
50
 
69
 
69
 
70
   Map<String, dynamic> _unsetAttributes(Map<String, dynamic> attributes) {
70
   Map<String, dynamic> _unsetAttributes(Map<String, dynamic> attributes) {
71
     if (attributes == null) return null;
71
     if (attributes == null) return null;
72
-    return attributes.map<String, dynamic>((String key, dynamic value) =>
73
-        new MapEntry<String, dynamic>(key, null));
72
+    return attributes.map<String, dynamic>(
73
+        (String key, dynamic value) => MapEntry<String, dynamic>(key, null));
74
   }
74
   }
75
 }
75
 }
76
 
76
 
80
 
80
 
81
   @override
81
   @override
82
   Delta apply(Delta document, int index, int length) {
82
   Delta apply(Delta document, int index, int length) {
83
-    DeltaIterator iter = new DeltaIterator(document);
83
+    DeltaIterator iter = DeltaIterator(document);
84
 
84
 
85
     // First, check if line-break deleted after an embed.
85
     // First, check if line-break deleted after an embed.
86
     Operation op = iter.skip(index);
86
     Operation op = iter.skip(index);
123
     }
123
     }
124
 
124
 
125
     if (foundEmbed) {
125
     if (foundEmbed) {
126
-      return new Delta()
126
+      return Delta()
127
         ..retain(index + indexDelta)
127
         ..retain(index + indexDelta)
128
         ..delete(length + lengthDelta);
128
         ..delete(length + lengthDelta);
129
     }
129
     }

+ 11
- 11
packages/notus/lib/src/heuristics/format_rules.dart View File

24
   Delta apply(Delta document, int index, int length, NotusAttribute attribute) {
24
   Delta apply(Delta document, int index, int length, NotusAttribute attribute) {
25
     if (attribute.scope != NotusAttributeScope.line) return null;
25
     if (attribute.scope != NotusAttributeScope.line) return null;
26
 
26
 
27
-    Delta result = new Delta()..retain(index);
28
-    final iter = new DeltaIterator(document);
27
+    Delta result = Delta()..retain(index);
28
+    final iter = DeltaIterator(document);
29
     iter.skip(index);
29
     iter.skip(index);
30
 
30
 
31
     // Apply line styles to all line-break characters within range of this
31
     // Apply line styles to all line-break characters within range of this
56
   }
56
   }
57
 
57
 
58
   Delta _applyAttribute(String text, NotusAttribute attribute) {
58
   Delta _applyAttribute(String text, NotusAttribute attribute) {
59
-    final result = new Delta();
59
+    final result = Delta();
60
     int offset = 0;
60
     int offset = 0;
61
     int lf = text.indexOf('\n');
61
     int lf = text.indexOf('\n');
62
     while (lf >= 0) {
62
     while (lf >= 0) {
79
   Delta apply(Delta document, int index, int length, NotusAttribute attribute) {
79
   Delta apply(Delta document, int index, int length, NotusAttribute attribute) {
80
     if (attribute.scope != NotusAttributeScope.inline) return null;
80
     if (attribute.scope != NotusAttributeScope.inline) return null;
81
 
81
 
82
-    Delta result = new Delta()..retain(index);
83
-    final iter = new DeltaIterator(document);
82
+    Delta result = Delta()..retain(index);
83
+    final iter = DeltaIterator(document);
84
     iter.skip(index);
84
     iter.skip(index);
85
 
85
 
86
     // Apply inline styles to all non-line-break characters within range of this
86
     // Apply inline styles to all non-line-break characters within range of this
122
     // edge cases.
122
     // edge cases.
123
     if (length != 0) return null;
123
     if (length != 0) return null;
124
 
124
 
125
-    Delta result = new Delta();
126
-    final iter = new DeltaIterator(document);
125
+    Delta result = Delta();
126
+    final iter = DeltaIterator(document);
127
     final before = iter.skip(index);
127
     final before = iter.skip(index);
128
     final after = iter.next();
128
     final after = iter.next();
129
     int startIndex = index;
129
     int startIndex = index;
157
 
157
 
158
     if (length == 1 && embed.isUnset) {
158
     if (length == 1 && embed.isUnset) {
159
       // Remove the embed.
159
       // Remove the embed.
160
-      return new Delta()
160
+      return Delta()
161
         ..retain(index)
161
         ..retain(index)
162
         ..delete(length);
162
         ..delete(length);
163
     } else {
163
     } else {
171
 
171
 
172
   Delta _insertEmbed(
172
   Delta _insertEmbed(
173
       Delta document, int index, int length, EmbedAttribute embed) {
173
       Delta document, int index, int length, EmbedAttribute embed) {
174
-    Delta result = new Delta()..retain(index);
175
-    final iter = new DeltaIterator(document);
174
+    Delta result = Delta()..retain(index);
175
+    final iter = DeltaIterator(document);
176
     final previous = iter.skip(index);
176
     final previous = iter.skip(index);
177
     iter.skip(length); // ignore deleted part.
177
     iter.skip(length); // ignore deleted part.
178
     final target = iter.next();
178
     final target = iter.next();
200
 
200
 
201
   Map<String, dynamic> _getLineStyle(
201
   Map<String, dynamic> _getLineStyle(
202
       DeltaIterator iterator, Operation current) {
202
       DeltaIterator iterator, Operation current) {
203
-    if (current.data.indexOf('\n') >= 0) {
203
+    if (current.data.contains('\n')) {
204
       return current.attributes;
204
       return current.attributes;
205
     }
205
     }
206
     // Continue looking for line-break.
206
     // Continue looking for line-break.

+ 18
- 18
packages/notus/lib/src/heuristics/insert_rules.dart View File

21
 
21
 
22
   @override
22
   @override
23
   Delta apply(Delta document, int index, String text) {
23
   Delta apply(Delta document, int index, String text) {
24
-    return new Delta()
24
+    return Delta()
25
       ..retain(index)
25
       ..retain(index)
26
       ..insert(text);
26
       ..insert(text);
27
   }
27
   }
43
   Delta apply(Delta document, int index, String text) {
43
   Delta apply(Delta document, int index, String text) {
44
     if (text != '\n') return null;
44
     if (text != '\n') return null;
45
 
45
 
46
-    DeltaIterator iter = new DeltaIterator(document);
46
+    DeltaIterator iter = DeltaIterator(document);
47
     final before = iter.skip(index);
47
     final before = iter.skip(index);
48
     final after = iter.next();
48
     final after = iter.next();
49
     if (isEdgeLineSplit(before, after)) return null;
49
     if (isEdgeLineSplit(before, after)) return null;
50
-    Delta result = new Delta()..retain(index);
51
-    if (after.data.indexOf('\n') >= 0) {
50
+    Delta result = Delta()..retain(index);
51
+    if (after.data.contains('\n')) {
52
       // It is not allowed to combine line and inline styles in insert
52
       // It is not allowed to combine line and inline styles in insert
53
       // operation containing line-break together with other characters.
53
       // operation containing line-break together with other characters.
54
       // The only scenario we get such operation is when the text is plain.
54
       // The only scenario we get such operation is when the text is plain.
82
   Delta apply(Delta document, int index, String text) {
82
   Delta apply(Delta document, int index, String text) {
83
     if (text != '\n') return null;
83
     if (text != '\n') return null;
84
 
84
 
85
-    DeltaIterator iter = new DeltaIterator(document);
85
+    DeltaIterator iter = DeltaIterator(document);
86
     iter.skip(index);
86
     iter.skip(index);
87
     final target = iter.next();
87
     final target = iter.next();
88
 
88
 
92
           target.attributes.containsKey(NotusAttribute.heading.key)) {
92
           target.attributes.containsKey(NotusAttribute.heading.key)) {
93
         resetStyle = NotusAttribute.heading.unset.toJson();
93
         resetStyle = NotusAttribute.heading.unset.toJson();
94
       }
94
       }
95
-      return new Delta()
95
+      return Delta()
96
         ..retain(index)
96
         ..retain(index)
97
         ..insert('\n', target.attributes)
97
         ..insert('\n', target.attributes)
98
         ..retain(1, resetStyle)
98
         ..retain(1, resetStyle)
117
   Delta apply(Delta document, int index, String text) {
117
   Delta apply(Delta document, int index, String text) {
118
     if (text != '\n') return null;
118
     if (text != '\n') return null;
119
 
119
 
120
-    DeltaIterator iter = new DeltaIterator(document);
120
+    DeltaIterator iter = DeltaIterator(document);
121
     final previous = iter.skip(index);
121
     final previous = iter.skip(index);
122
     final target = iter.next();
122
     final target = iter.next();
123
     final isInBlock = target.isNotPlain &&
123
     final isInBlock = target.isNotPlain &&
129
       var attributes =
129
       var attributes =
130
           target.attributes != null ? target.attributes : <String, dynamic>{};
130
           target.attributes != null ? target.attributes : <String, dynamic>{};
131
       attributes.addAll(NotusAttribute.block.unset.toJson());
131
       attributes.addAll(NotusAttribute.block.unset.toJson());
132
-      return new Delta()..retain(index)..retain(1, attributes);
132
+      return Delta()..retain(index)..retain(1, attributes);
133
     }
133
     }
134
     return null;
134
     return null;
135
   }
135
   }
144
     // This rule is only applicable to characters other than line-break.
144
     // This rule is only applicable to characters other than line-break.
145
     if (text.contains('\n')) return null;
145
     if (text.contains('\n')) return null;
146
 
146
 
147
-    DeltaIterator iter = new DeltaIterator(document);
147
+    DeltaIterator iter = DeltaIterator(document);
148
     final previous = iter.skip(index);
148
     final previous = iter.skip(index);
149
     // If there is a line-break in previous chunk, there should be no inline
149
     // If there is a line-break in previous chunk, there should be no inline
150
     // styles. Also if there is no previous operation we are at the beginning
150
     // styles. Also if there is no previous operation we are at the beginning
155
     final hasLink =
155
     final hasLink =
156
         (attributes != null && attributes.containsKey(NotusAttribute.link.key));
156
         (attributes != null && attributes.containsKey(NotusAttribute.link.key));
157
     if (!hasLink) {
157
     if (!hasLink) {
158
-      return new Delta()
158
+      return Delta()
159
         ..retain(index)
159
         ..retain(index)
160
         ..insert(text, attributes);
160
         ..insert(text, attributes);
161
     }
161
     }
164
     // Link style should NOT be preserved on the boundaries.
164
     // Link style should NOT be preserved on the boundaries.
165
     var noLinkAttributes = previous.attributes;
165
     var noLinkAttributes = previous.attributes;
166
     noLinkAttributes.remove(NotusAttribute.link.key);
166
     noLinkAttributes.remove(NotusAttribute.link.key);
167
-    final noLinkResult = new Delta()
167
+    final noLinkResult = Delta()
168
       ..retain(index)
168
       ..retain(index)
169
       ..insert(text, noLinkAttributes.isEmpty ? null : noLinkAttributes);
169
       ..insert(text, noLinkAttributes.isEmpty ? null : noLinkAttributes);
170
     final next = iter.next();
170
     final next = iter.next();
180
     // We must make sure links are identical in previous and next operations.
180
     // We must make sure links are identical in previous and next operations.
181
     if (attributes[NotusAttribute.link.key] ==
181
     if (attributes[NotusAttribute.link.key] ==
182
         nextAttributes[NotusAttribute.link.key]) {
182
         nextAttributes[NotusAttribute.link.key]) {
183
-      return new Delta()
183
+      return Delta()
184
         ..retain(index)
184
         ..retain(index)
185
         ..insert(text, attributes);
185
         ..insert(text, attributes);
186
     } else {
186
     } else {
200
     // everything else.
200
     // everything else.
201
     if (text != ' ') return null;
201
     if (text != ' ') return null;
202
 
202
 
203
-    DeltaIterator iter = new DeltaIterator(document);
203
+    DeltaIterator iter = DeltaIterator(document);
204
     final previous = iter.skip(index);
204
     final previous = iter.skip(index);
205
     // No previous operation means no link.
205
     // No previous operation means no link.
206
     if (previous == null) return null;
206
     if (previous == null) return null;
220
 
220
 
221
       attributes
221
       attributes
222
           .addAll(NotusAttribute.link.fromString(link.toString()).toJson());
222
           .addAll(NotusAttribute.link.fromString(link.toString()).toJson());
223
-      return new Delta()
223
+      return Delta()
224
         ..retain(index - candidate.length)
224
         ..retain(index - candidate.length)
225
         ..retain(candidate.length, attributes)
225
         ..retain(candidate.length, attributes)
226
         ..insert(text, previous.attributes);
226
         ..insert(text, previous.attributes);
239
 
239
 
240
   @override
240
   @override
241
   Delta apply(Delta document, int index, String text) {
241
   Delta apply(Delta document, int index, String text) {
242
-    DeltaIterator iter = new DeltaIterator(document);
242
+    DeltaIterator iter = DeltaIterator(document);
243
     final previous = iter.skip(index);
243
     final previous = iter.skip(index);
244
     final target = iter.next();
244
     final target = iter.next();
245
     final beforeEmbed = target.data == EmbedNode.kPlainTextPlaceholder;
245
     final beforeEmbed = target.data == EmbedNode.kPlainTextPlaceholder;
246
     final afterEmbed = previous?.data == EmbedNode.kPlainTextPlaceholder;
246
     final afterEmbed = previous?.data == EmbedNode.kPlainTextPlaceholder;
247
     if (beforeEmbed || afterEmbed) {
247
     if (beforeEmbed || afterEmbed) {
248
-      final delta = new Delta()..retain(index);
248
+      final delta = Delta()..retain(index);
249
       if (beforeEmbed && !text.endsWith('\n')) {
249
       if (beforeEmbed && !text.endsWith('\n')) {
250
         return delta..insert(text)..insert('\n');
250
         return delta..insert(text)..insert('\n');
251
       }
251
       }
276
       return null;
276
       return null;
277
     }
277
     }
278
 
278
 
279
-    DeltaIterator iter = new DeltaIterator(document);
279
+    DeltaIterator iter = DeltaIterator(document);
280
     iter.skip(index);
280
     iter.skip(index);
281
 
281
 
282
     // Look for next line-break.
282
     // Look for next line-break.
305
     }
305
     }
306
 
306
 
307
     final lines = text.split('\n');
307
     final lines = text.split('\n');
308
-    Delta result = new Delta()..retain(index);
308
+    Delta result = Delta()..retain(index);
309
     for (int i = 0; i < lines.length; i++) {
309
     for (int i = 0; i < lines.length; i++) {
310
       final line = lines[i];
310
       final line = lines[i];
311
       if (line.isNotEmpty) {
311
       if (line.isNotEmpty) {

+ 1
- 0
packages/notus/pubspec.yaml View File

14
   quiver_hashcode: ^2.0.0
14
   quiver_hashcode: ^2.0.0
15
 
15
 
16
 dev_dependencies:
16
 dev_dependencies:
17
+  pedantic: ^1.0.0
17
   test: ^1.0.0
18
   test: ^1.0.0
18
   test_coverage: ^0.2.1
19
   test_coverage: ^0.2.1

+ 9
- 13
packages/notus/test/convert/markdown_test.dart View File

19
 
19
 
20
   group('$NotusMarkdownCodec.encode', () {
20
   group('$NotusMarkdownCodec.encode', () {
21
     test('split adjacent paragraphs', () {
21
     test('split adjacent paragraphs', () {
22
-      final delta = new Delta()..insert('First line\nSecond line\n');
22
+      final delta = Delta()..insert('First line\nSecond line\n');
23
       final result = notusMarkdown.encode(delta);
23
       final result = notusMarkdown.encode(delta);
24
       expect(result, 'First line\n\nSecond line\n\n');
24
       expect(result, 'First line\n\nSecond line\n\n');
25
     });
25
     });
26
 
26
 
27
     test('bold italic', () {
27
     test('bold italic', () {
28
       runFor(NotusAttribute<bool> attribute, String expected) {
28
       runFor(NotusAttribute<bool> attribute, String expected) {
29
-        final delta = new Delta()
29
+        final delta = Delta()
30
           ..insert('This ')
30
           ..insert('This ')
31
           ..insert('house', attribute.toJson())
31
           ..insert('house', attribute.toJson())
32
           ..insert(' is a ')
32
           ..insert(' is a ')
44
     test('intersecting inline styles', () {
44
     test('intersecting inline styles', () {
45
       final b = NotusAttribute.bold.toJson();
45
       final b = NotusAttribute.bold.toJson();
46
       final i = NotusAttribute.italic.toJson();
46
       final i = NotusAttribute.italic.toJson();
47
-      final bi = new Map<String, dynamic>.from(b);
47
+      final bi = Map<String, dynamic>.from(b);
48
       bi.addAll(i);
48
       bi.addAll(i);
49
 
49
 
50
-      final delta = new Delta()
50
+      final delta = Delta()
51
         ..insert('This ')
51
         ..insert('This ')
52
         ..insert('house', b)
52
         ..insert('house', b)
53
         ..insert(' is a ', bi)
53
         ..insert(' is a ', bi)
61
     test('normalize inline styles', () {
61
     test('normalize inline styles', () {
62
       final b = NotusAttribute.bold.toJson();
62
       final b = NotusAttribute.bold.toJson();
63
       final i = NotusAttribute.italic.toJson();
63
       final i = NotusAttribute.italic.toJson();
64
-      final delta = new Delta()
64
+      final delta = Delta()
65
         ..insert('This')
65
         ..insert('This')
66
         ..insert(' house ', b)
66
         ..insert(' house ', b)
67
         ..insert('is a')
67
         ..insert('is a')
75
     test('links', () {
75
     test('links', () {
76
       final b = NotusAttribute.bold.toJson();
76
       final b = NotusAttribute.bold.toJson();
77
       final link = NotusAttribute.link.fromString('https://github.com');
77
       final link = NotusAttribute.link.fromString('https://github.com');
78
-      final delta = new Delta()
78
+      final delta = Delta()
79
         ..insert('This')
79
         ..insert('This')
80
         ..insert(' house ', b)
80
         ..insert(' house ', b)
81
         ..insert('is a')
81
         ..insert('is a')
88
 
88
 
89
     test('heading styles', () {
89
     test('heading styles', () {
90
       runFor(NotusAttribute<int> attribute, String source, String expected) {
90
       runFor(NotusAttribute<int> attribute, String source, String expected) {
91
-        final delta = new Delta()
92
-          ..insert(source)
93
-          ..insert('\n', attribute.toJson());
91
+        final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
94
         final result = notusMarkdown.encode(delta);
92
         final result = notusMarkdown.encode(delta);
95
         expect(result, expected);
93
         expect(result, expected);
96
       }
94
       }
102
 
100
 
103
     test('block styles', () {
101
     test('block styles', () {
104
       runFor(NotusAttribute<String> attribute, String source, String expected) {
102
       runFor(NotusAttribute<String> attribute, String source, String expected) {
105
-        final delta = new Delta()
106
-          ..insert(source)
107
-          ..insert('\n', attribute.toJson());
103
+        final delta = Delta()..insert(source)..insert('\n', attribute.toJson());
108
         final result = notusMarkdown.encode(delta);
104
         final result = notusMarkdown.encode(delta);
109
         expect(result, expected);
105
         expect(result, expected);
110
       }
106
       }
117
 
113
 
118
     test('multiline blocks', () {
114
     test('multiline blocks', () {
119
       runFor(NotusAttribute<String> attribute, String source, String expected) {
115
       runFor(NotusAttribute<String> attribute, String source, String expected) {
120
-        final delta = new Delta()
116
+        final delta = Delta()
121
           ..insert(source)
117
           ..insert(source)
122
           ..insert('\n', attribute.toJson())
118
           ..insert('\n', attribute.toJson())
123
           ..insert(source)
119
           ..insert(source)

+ 16
- 19
packages/notus/test/document/block_test.dart View File

5
 import 'package:test/test.dart';
5
 import 'package:test/test.dart';
6
 import 'package:quill_delta/quill_delta.dart';
6
 import 'package:quill_delta/quill_delta.dart';
7
 
7
 
8
-final ulAttrs = new NotusStyle().merge(NotusAttribute.ul);
9
-final olAttrs = new NotusStyle().merge(NotusAttribute.ol);
10
-final h1Attrs = new NotusStyle().merge(NotusAttribute.h1);
8
+final ulAttrs = NotusStyle().merge(NotusAttribute.ul);
9
+final olAttrs = NotusStyle().merge(NotusAttribute.ol);
10
+final h1Attrs = NotusStyle().merge(NotusAttribute.h1);
11
 
11
 
12
 void main() {
12
 void main() {
13
   group('$BlockNode', () {
13
   group('$BlockNode', () {
14
     ContainerNode root;
14
     ContainerNode root;
15
     setUp(() {
15
     setUp(() {
16
-      root = new RootNode();
16
+      root = RootNode();
17
     });
17
     });
18
 
18
 
19
     test('empty', () {
19
     test('empty', () {
20
-      BlockNode node = new BlockNode();
20
+      BlockNode node = BlockNode();
21
       expect(node, isEmpty);
21
       expect(node, isEmpty);
22
       expect(node.length, 0);
22
       expect(node.length, 0);
23
-      expect(node.style, new NotusStyle());
23
+      expect(node.style, NotusStyle());
24
     });
24
     });
25
 
25
 
26
     test('toString', () {
26
     test('toString', () {
27
-      LineNode line = new LineNode();
28
-      line.add(new TextNode('London "Grammar"'));
29
-      BlockNode block = new BlockNode();
27
+      LineNode line = LineNode();
28
+      line.add(TextNode('London "Grammar"'));
29
+      BlockNode block = BlockNode();
30
       block.applyAttribute(NotusAttribute.ul);
30
       block.applyAttribute(NotusAttribute.ul);
31
       block.add(line);
31
       block.add(line);
32
       final expected = '§ {ul}\n  └ ¶ ⟨London "Grammar"⟩ ⏎';
32
       final expected = '§ {ul}\n  └ ¶ ⟨London "Grammar"⟩ ⏎';
54
 
54
 
55
       expect(root.childCount, 1);
55
       expect(root.childCount, 1);
56
       BlockNode block = root.first;
56
       BlockNode block = root.first;
57
-      expect(block.style.get(NotusAttribute.block),
58
-          NotusAttribute.ul);
57
+      expect(block.style.get(NotusAttribute.block), NotusAttribute.ul);
59
       expect(block.childCount, 1);
58
       expect(block.childCount, 1);
60
       expect(block.first, const TypeMatcher<LineNode>());
59
       expect(block.first, const TypeMatcher<LineNode>());
61
 
60
 
62
       LineNode line = block.first;
61
       LineNode line = block.first;
63
-      Delta delta = new Delta()
62
+      Delta delta = Delta()
64
         ..insert('Hello world')
63
         ..insert('Hello world')
65
         ..insert('\n', ulAttrs.toJson());
64
         ..insert('\n', ulAttrs.toJson());
66
       expect(line.toDelta(), delta);
65
       expect(line.toDelta(), delta);
72
 
71
 
73
       expect(root.childCount, 2);
72
       expect(root.childCount, 2);
74
       BlockNode block = root.last;
73
       BlockNode block = root.last;
75
-      expect(block.style.get(NotusAttribute.block),
76
-          NotusAttribute.ul);
74
+      expect(block.style.get(NotusAttribute.block), NotusAttribute.ul);
77
       expect(block.childCount, 1);
75
       expect(block.childCount, 1);
78
       expect(block.first, const TypeMatcher<LineNode>());
76
       expect(block.first, const TypeMatcher<LineNode>());
79
     });
77
     });
85
 
83
 
86
       expect(root.childCount, 1);
84
       expect(root.childCount, 1);
87
       BlockNode block = root.first;
85
       BlockNode block = root.first;
88
-      expect(block.style.get(NotusAttribute.block),
89
-          NotusAttribute.ul);
86
+      expect(block.style.get(NotusAttribute.block), NotusAttribute.ul);
90
       expect(block.childCount, 2);
87
       expect(block.childCount, 2);
91
       expect(block.first, const TypeMatcher<LineNode>());
88
       expect(block.first, const TypeMatcher<LineNode>());
92
       expect(block.last, const TypeMatcher<LineNode>());
89
       expect(block.last, const TypeMatcher<LineNode>());
102
       expect(root.childCount, 2);
99
       expect(root.childCount, 2);
103
       root.retain(28, 1, olAttrs);
100
       root.retain(28, 1, olAttrs);
104
       expect(root.childCount, 3);
101
       expect(root.childCount, 3);
105
-      final expected = new Delta()
102
+      final expected = Delta()
106
         ..insert('London Grammar Songs')
103
         ..insert('London Grammar Songs')
107
         ..insert('\n', NotusAttribute.h1.toJson())
104
         ..insert('\n', NotusAttribute.h1.toJson())
108
         ..insert('Hey now')
105
         ..insert('Hey now')
124
       expect(root.childCount, 2);
121
       expect(root.childCount, 2);
125
       root.retain(47, 1, olAttrs);
122
       root.retain(47, 1, olAttrs);
126
       expect(root.childCount, 3);
123
       expect(root.childCount, 3);
127
-      final expected = new Delta()
124
+      final expected = Delta()
128
         ..insert('London Grammar Songs')
125
         ..insert('London Grammar Songs')
129
         ..insert('\n', NotusAttribute.h1.toJson())
126
         ..insert('\n', NotusAttribute.h1.toJson())
130
         ..insert('Hey now')
127
         ..insert('Hey now')
146
       expect(root.childCount, 2);
143
       expect(root.childCount, 2);
147
       root.retain(35, 1, olAttrs);
144
       root.retain(35, 1, olAttrs);
148
       expect(root.childCount, 4);
145
       expect(root.childCount, 4);
149
-      final expected = new Delta()
146
+      final expected = Delta()
150
         ..insert('London Grammar Songs')
147
         ..insert('London Grammar Songs')
151
         ..insert('\n', NotusAttribute.h1.toJson())
148
         ..insert('\n', NotusAttribute.h1.toJson())
152
         ..insert('Hey now')
149
         ..insert('Hey now')

+ 28
- 32
packages/notus/test/document/line_test.dart View File

5
 import 'package:quill_delta/quill_delta.dart';
5
 import 'package:quill_delta/quill_delta.dart';
6
 import 'package:notus/notus.dart';
6
 import 'package:notus/notus.dart';
7
 
7
 
8
-final boldStyle = new NotusStyle().merge(NotusAttribute.bold);
9
-final h1Style = new NotusStyle().merge(NotusAttribute.h1);
10
-final h2Style = new NotusStyle().merge(NotusAttribute.h2);
11
-final ulStyle = new NotusStyle().merge(NotusAttribute.ul);
12
-final bqStyle = new NotusStyle().merge(NotusAttribute.bq);
8
+final boldStyle = NotusStyle().merge(NotusAttribute.bold);
9
+final h1Style = NotusStyle().merge(NotusAttribute.h1);
10
+final h2Style = NotusStyle().merge(NotusAttribute.h2);
11
+final ulStyle = NotusStyle().merge(NotusAttribute.ul);
12
+final bqStyle = NotusStyle().merge(NotusAttribute.bq);
13
 
13
 
14
 void main() {
14
 void main() {
15
   group('$LineNode', () {
15
   group('$LineNode', () {
16
     ContainerNode root;
16
     ContainerNode root;
17
     setUp(() {
17
     setUp(() {
18
-      root = new RootNode();
18
+      root = RootNode();
19
     });
19
     });
20
 
20
 
21
     test('empty', () {
21
     test('empty', () {
22
-      LineNode node = new LineNode();
22
+      LineNode node = LineNode();
23
       expect(node, isEmpty);
23
       expect(node, isEmpty);
24
       expect(node.length, 1);
24
       expect(node.length, 1);
25
-      expect(node.style, new NotusStyle());
26
-      expect(node.toDelta().toList(), [new Operation.insert('\n')]);
25
+      expect(node.style, NotusStyle());
26
+      expect(node.toDelta().toList(), [Operation.insert('\n')]);
27
     });
27
     });
28
 
28
 
29
     test('hasEmbed', () {
29
     test('hasEmbed', () {
30
-      LineNode node = new LineNode();
30
+      LineNode node = LineNode();
31
       expect(node.hasEmbed, isFalse);
31
       expect(node.hasEmbed, isFalse);
32
-      node.add(new EmbedNode());
32
+      node.add(EmbedNode());
33
       expect(node.hasEmbed, isTrue);
33
       expect(node.hasEmbed, isTrue);
34
     });
34
     });
35
 
35
 
50
     });
50
     });
51
 
51
 
52
     test('toString', () {
52
     test('toString', () {
53
-      LineNode node = new LineNode();
53
+      LineNode node = LineNode();
54
       node.insert(0, 'London "Grammar" - Hey Now', null);
54
       node.insert(0, 'London "Grammar" - Hey Now', null);
55
       node.retain(0, 16, boldStyle);
55
       node.retain(0, 16, boldStyle);
56
       node.applyAttribute(NotusAttribute.h1);
56
       node.applyAttribute(NotusAttribute.h1);
68
     });
68
     });
69
 
69
 
70
     test('insert into empty line', () {
70
     test('insert into empty line', () {
71
-      LineNode node = new LineNode();
71
+      LineNode node = LineNode();
72
       node.insert(0, 'London "Grammar" - Hey Now', null);
72
       node.insert(0, 'London "Grammar" - Hey Now', null);
73
       expect(node, hasLength(27));
73
       expect(node, hasLength(27));
74
-      expect(
75
-          node.toDelta(), new Delta()..insert('London "Grammar" - Hey Now\n'));
74
+      expect(node.toDelta(), Delta()..insert('London "Grammar" - Hey Now\n'));
76
     });
75
     });
77
 
76
 
78
     test('insert into empty line with styles', () {
77
     test('insert into empty line with styles', () {
79
-      LineNode node = new LineNode();
78
+      LineNode node = LineNode();
80
       node.insert(0, 'London "Grammar" - Hey Now', null);
79
       node.insert(0, 'London "Grammar" - Hey Now', null);
81
       node.retain(0, 16, boldStyle);
80
       node.retain(0, 16, boldStyle);
82
       node.applyAttribute(NotusAttribute.h1);
81
       node.applyAttribute(NotusAttribute.h1);
83
       expect(node, hasLength(27));
82
       expect(node, hasLength(27));
84
       expect(node.childCount, 2);
83
       expect(node.childCount, 2);
85
 
84
 
86
-      final delta = new Delta()
85
+      final delta = Delta()
87
         ..insert('London "Grammar"', boldStyle.toJson())
86
         ..insert('London "Grammar"', boldStyle.toJson())
88
         ..insert(' - Hey Now')
87
         ..insert(' - Hey Now')
89
         ..insert('\n', NotusAttribute.h1.toJson());
88
         ..insert('\n', NotusAttribute.h1.toJson());
91
     });
90
     });
92
 
91
 
93
     test('insert into non-empty line', () {
92
     test('insert into non-empty line', () {
94
-      LineNode node = new LineNode();
93
+      LineNode node = LineNode();
95
       node.insert(0, 'Hello world', null);
94
       node.insert(0, 'Hello world', null);
96
       node.insert(11, '!!!', null);
95
       node.insert(11, '!!!', null);
97
       expect(node, hasLength(15));
96
       expect(node, hasLength(15));
98
       expect(node.childCount, 1);
97
       expect(node.childCount, 1);
99
-      expect(node.toDelta(), new Delta()..insert('Hello world!!!\n'));
98
+      expect(node.toDelta(), Delta()..insert('Hello world!!!\n'));
100
     });
99
     });
101
 
100
 
102
     test('insert text with line-break at the end of line', () {
101
     test('insert text with line-break at the end of line', () {
106
 
105
 
107
       LineNode line = root.first;
106
       LineNode line = root.first;
108
       expect(line, hasLength(15));
107
       expect(line, hasLength(15));
109
-      expect(line.toDelta(), new Delta()..insert('Hello world!!!\n'));
108
+      expect(line.toDelta(), Delta()..insert('Hello world!!!\n'));
110
 
109
 
111
       LineNode line2 = root.last;
110
       LineNode line2 = root.last;
112
       expect(line2, hasLength(1));
111
       expect(line2, hasLength(1));
113
-      expect(line2.toDelta(), new Delta()..insert('\n'));
112
+      expect(line2.toDelta(), Delta()..insert('\n'));
114
     });
113
     });
115
 
114
 
116
     test('insert into second text segment', () {
115
     test('insert into second text segment', () {
120
 
119
 
121
       LineNode line = root.first;
120
       LineNode line = root.first;
122
       expect(line, hasLength(15));
121
       expect(line, hasLength(15));
123
-      Delta delta = new Delta()
122
+      Delta delta = Delta()
124
         ..insert('Hello ')
123
         ..insert('Hello ')
125
         ..insert('world', boldStyle.toJson())
124
         ..insert('world', boldStyle.toJson())
126
         ..insert('!!!\n');
125
         ..insert('!!!\n');
134
       LineNode line = root.first;
133
       LineNode line = root.first;
135
       expect(line, hasLength(12));
134
       expect(line, hasLength(12));
136
 
135
 
137
-      Delta delta = new Delta()
136
+      Delta delta = Delta()
138
         ..insert('Hello world')
137
         ..insert('Hello world')
139
         ..insert('\n', NotusAttribute.h1.toJson());
138
         ..insert('\n', NotusAttribute.h1.toJson());
140
       expect(line.toDelta(), delta);
139
       expect(line.toDelta(), delta);
155
     });
154
     });
156
 
155
 
157
     test('format root line to unset block style', () {
156
     test('format root line to unset block style', () {
158
-      final unsetBlock = new NotusStyle().put(NotusAttribute.block.unset);
157
+      final unsetBlock = NotusStyle().put(NotusAttribute.block.unset);
159
       root.insert(0, 'Hello world', null);
158
       root.insert(0, 'Hello world', null);
160
       root.retain(11, 1, unsetBlock);
159
       root.retain(11, 1, unsetBlock);
161
       expect(root.childCount, 1);
160
       expect(root.childCount, 1);
188
       LineNode line = root.first;
187
       LineNode line = root.first;
189
       expect(line, hasLength(8));
188
       expect(line, hasLength(8));
190
       expect(line.childCount, 1);
189
       expect(line.childCount, 1);
191
-      Delta lineDelta = new Delta()..insert('Hellord\n');
190
+      Delta lineDelta = Delta()..insert('Hellord\n');
192
       expect(line.toDelta(), lineDelta);
191
       expect(line.toDelta(), lineDelta);
193
     });
192
     });
194
 
193
 
199
       expect(root.childCount, 1);
198
       expect(root.childCount, 1);
200
       LineNode line = root.first;
199
       LineNode line = root.first;
201
       expect(line, hasLength(18));
200
       expect(line, hasLength(18));
202
-      Delta lineDelta = new Delta()
201
+      Delta lineDelta = Delta()
203
         ..insert('Hello ')
202
         ..insert('Hello ')
204
         ..insert('worl', boldStyle.toJson())
203
         ..insert('worl', boldStyle.toJson())
205
         ..insert(' cd ef!\n');
204
         ..insert(' cd ef!\n');
213
       expect(root.childCount, 1);
212
       expect(root.childCount, 1);
214
       LineNode line = root.first;
213
       LineNode line = root.first;
215
       expect(line.childCount, 1);
214
       expect(line.childCount, 1);
216
-      final delta = new Delta()
217
-        ..insert('delnes')
218
-        ..insert('\n', h2Style.toJson());
215
+      final delta = Delta()..insert('delnes')..insert('\n', h2Style.toJson());
219
       expect(line.toDelta(), delta);
216
       expect(line.toDelta(), delta);
220
     });
217
     });
221
 
218
 
252
       root.delete(37, 1);
249
       root.delete(37, 1);
253
       expect(root.childCount, 3);
250
       expect(root.childCount, 3);
254
       LineNode line = root.children.elementAt(1);
251
       LineNode line = root.children.elementAt(1);
255
-      expect(
256
-          line.toDelta(), new Delta()..insert('This is my first multilin\n'));
252
+      expect(line.toDelta(), Delta()..insert('This is my first multilin\n'));
257
     });
253
     });
258
 
254
 
259
     test('collectStyle', () {
255
     test('collectStyle', () {
270
 
266
 
271
     test('collectStyle with embed nodes', () {
267
     test('collectStyle with embed nodes', () {
272
       root.insert(0, 'Hello world\n\nMore text.\n', null);
268
       root.insert(0, 'Hello world\n\nMore text.\n', null);
273
-      NotusStyle style = new NotusStyle();
269
+      NotusStyle style = NotusStyle();
274
       style = style.put(NotusAttribute.embed.horizontalRule);
270
       style = style.put(NotusAttribute.embed.horizontalRule);
275
       root.insert(12, EmbedNode.kPlainTextPlaceholder, style);
271
       root.insert(12, EmbedNode.kPlainTextPlaceholder, style);
276
 
272
 

+ 3
- 3
packages/notus/test/document/node_test.dart View File

8
   group('$Node', () {
8
   group('$Node', () {
9
     RootNode root;
9
     RootNode root;
10
     setUp(() {
10
     setUp(() {
11
-      root = new RootNode();
11
+      root = RootNode();
12
     });
12
     });
13
 
13
 
14
     test('mounted', () {
14
     test('mounted', () {
15
-      LineNode line = new LineNode();
16
-      TextNode text = new TextNode();
15
+      LineNode line = LineNode();
16
+      TextNode text = TextNode();
17
       expect(text.mounted, isFalse);
17
       expect(text.mounted, isFalse);
18
       line.add(text);
18
       line.add(text);
19
       expect(text.mounted, isTrue);
19
       expect(text.mounted, isTrue);

+ 11
- 12
packages/notus/test/document/text_test.dart View File

5
 import 'package:quill_delta/quill_delta.dart';
5
 import 'package:quill_delta/quill_delta.dart';
6
 import 'package:notus/notus.dart';
6
 import 'package:notus/notus.dart';
7
 
7
 
8
-final boldStyle = new NotusStyle().merge(NotusAttribute.bold);
9
-final boldUnsetStyle = new NotusStyle().put(NotusAttribute.bold.unset);
10
-final italicStyle = new NotusStyle().merge(NotusAttribute.italic);
8
+final boldStyle = NotusStyle().merge(NotusAttribute.bold);
9
+final boldUnsetStyle = NotusStyle().put(NotusAttribute.bold.unset);
10
+final italicStyle = NotusStyle().merge(NotusAttribute.italic);
11
 
11
 
12
 void main() {
12
 void main() {
13
   group('$TextNode', () {
13
   group('$TextNode', () {
15
     TextNode node;
15
     TextNode node;
16
 
16
 
17
     setUp(() {
17
     setUp(() {
18
-      line = new LineNode();
19
-      node = new TextNode('London "Grammar"');
18
+      line = LineNode();
19
+      node = TextNode('London "Grammar"');
20
       line.add(node);
20
       line.add(node);
21
     });
21
     });
22
 
22
 
23
     test('new empty text', () {
23
     test('new empty text', () {
24
-      final node = new TextNode();
24
+      final node = TextNode();
25
       expect(node.value, isEmpty);
25
       expect(node.value, isEmpty);
26
       expect(node.length, 0);
26
       expect(node.length, 0);
27
-      expect(node.style, new NotusStyle());
27
+      expect(node.style, NotusStyle());
28
       expect(node.toDelta(), isEmpty);
28
       expect(node.toDelta(), isEmpty);
29
     });
29
     });
30
 
30
 
37
     test('new text with contents', () {
37
     test('new text with contents', () {
38
       expect(node.value, isNotEmpty);
38
       expect(node.value, isNotEmpty);
39
       expect(node.length, 16);
39
       expect(node.length, 16);
40
-      expect(
41
-          node.toDelta().toList(), [new Operation.insert('London "Grammar"')]);
40
+      expect(node.toDelta().toList(), [Operation.insert('London "Grammar"')]);
42
     });
41
     });
43
 
42
 
44
     test('insert at the end', () {
43
     test('insert at the end', () {
99
       final b = boldStyle.toJson();
98
       final b = boldStyle.toJson();
100
       expect(
99
       expect(
101
         line.children.elementAt(0).toDelta(),
100
         line.children.elementAt(0).toDelta(),
102
-        new Delta()..insert('Lon', b),
101
+        Delta()..insert('Lon', b),
103
       );
102
       );
104
       expect(
103
       expect(
105
         line.children.elementAt(1).toDelta(),
104
         line.children.elementAt(1).toDelta(),
106
-        new Delta()..insert('don'),
105
+        Delta()..insert('don'),
107
       );
106
       );
108
       expect(
107
       expect(
109
         line.children.elementAt(2).toDelta(),
108
         line.children.elementAt(2).toDelta(),
110
-        new Delta()..insert('don', b),
109
+        Delta()..insert('don', b),
111
       );
110
       );
112
     });
111
     });
113
   });
112
   });

+ 19
- 19
packages/notus/test/document_test.dart View File

9
 import 'matchers.dart';
9
 import 'matchers.dart';
10
 
10
 
11
 NotusDocument dartconfDoc() {
11
 NotusDocument dartconfDoc() {
12
-  Delta delta = new Delta()..insert('DartConf\nLos Angeles\n');
13
-  return new NotusDocument.fromDelta(delta);
12
+  Delta delta = Delta()..insert('DartConf\nLos Angeles\n');
13
+  return NotusDocument.fromDelta(delta);
14
 }
14
 }
15
 
15
 
16
 NotusDocument dartconfEmbedDoc() {
16
 NotusDocument dartconfEmbedDoc() {
17
   final hr = NotusAttribute.embed.horizontalRule.toJson();
17
   final hr = NotusAttribute.embed.horizontalRule.toJson();
18
-  Delta delta = new Delta()
18
+  Delta delta = Delta()
19
     ..insert('DartConf\n')
19
     ..insert('DartConf\n')
20
     ..insert(kZeroWidthSpace, hr)
20
     ..insert(kZeroWidthSpace, hr)
21
     ..insert('\n')
21
     ..insert('\n')
22
     ..insert('Los Angeles\n');
22
     ..insert('Los Angeles\n');
23
-  return new NotusDocument.fromDelta(delta);
23
+  return NotusDocument.fromDelta(delta);
24
 }
24
 }
25
 
25
 
26
 final ul = NotusAttribute.ul.toJson();
26
 final ul = NotusAttribute.ul.toJson();
29
 void main() {
29
 void main() {
30
   group('$NotusDocument', () {
30
   group('$NotusDocument', () {
31
     test('validates for doc delta', () {
31
     test('validates for doc delta', () {
32
-      var badDelta = new Delta()
32
+      var badDelta = Delta()
33
         ..insert('Text')
33
         ..insert('Text')
34
         ..retain(5)
34
         ..retain(5)
35
         ..insert('\n');
35
         ..insert('\n');
36
       expect(() {
36
       expect(() {
37
-        new NotusDocument.fromDelta(badDelta);
37
+        NotusDocument.fromDelta(badDelta);
38
       }, throwsArgumentError);
38
       }, throwsArgumentError);
39
     });
39
     });
40
 
40
 
41
     test('empty document contains single empty line', () {
41
     test('empty document contains single empty line', () {
42
-      NotusDocument doc = new NotusDocument();
42
+      NotusDocument doc = NotusDocument();
43
       expect(doc.toPlainText(), '\n');
43
       expect(doc.toPlainText(), '\n');
44
     });
44
     });
45
 
45
 
67
     });
67
     });
68
 
68
 
69
     test('document delta must end with line-break character', () {
69
     test('document delta must end with line-break character', () {
70
-      Delta delta = new Delta()..insert('DartConf\nLos Angeles');
70
+      Delta delta = Delta()..insert('DartConf\nLos Angeles');
71
       expect(() {
71
       expect(() {
72
-        new NotusDocument.fromDelta(delta);
72
+        NotusDocument.fromDelta(delta);
73
       }, throwsA(const TypeMatcher<AssertionError>()));
73
       }, throwsA(const TypeMatcher<AssertionError>()));
74
     });
74
     });
75
 
75
 
105
     test('format returns actual change delta', () {
105
     test('format returns actual change delta', () {
106
       NotusDocument doc = dartconfDoc();
106
       NotusDocument doc = dartconfDoc();
107
       final change = doc.format(0, 15, NotusAttribute.ul);
107
       final change = doc.format(0, 15, NotusAttribute.ul);
108
-      final expectedChange = new Delta()
108
+      final expectedChange = Delta()
109
         ..retain(8)
109
         ..retain(8)
110
         ..retain(1, ul)
110
         ..retain(1, ul)
111
         ..retain(11)
111
         ..retain(11)
116
     test('format updates document delta', () {
116
     test('format updates document delta', () {
117
       NotusDocument doc = dartconfDoc();
117
       NotusDocument doc = dartconfDoc();
118
       doc.format(0, 15, NotusAttribute.ul);
118
       doc.format(0, 15, NotusAttribute.ul);
119
-      final expectedDoc = new Delta()
119
+      final expectedDoc = Delta()
120
         ..insert('DartConf')
120
         ..insert('DartConf')
121
         ..insert('\n', ul)
121
         ..insert('\n', ul)
122
         ..insert('Los Angeles')
122
         ..insert('Los Angeles')
127
     test('format allows zero-length updates', () {
127
     test('format allows zero-length updates', () {
128
       NotusDocument doc = dartconfDoc();
128
       NotusDocument doc = dartconfDoc();
129
       doc.format(0, 0, NotusAttribute.ul);
129
       doc.format(0, 0, NotusAttribute.ul);
130
-      final expectedDoc = new Delta()
130
+      final expectedDoc = Delta()
131
         ..insert('DartConf')
131
         ..insert('DartConf')
132
         ..insert('\n', ul)
132
         ..insert('\n', ul)
133
         ..insert('Los Angeles')
133
         ..insert('Los Angeles')
147
       NotusDocument doc = dartconfDoc();
147
       NotusDocument doc = dartconfDoc();
148
       doc.format(0, 15, NotusAttribute.ul);
148
       doc.format(0, 15, NotusAttribute.ul);
149
       final change = doc.insert(8, '\n');
149
       final change = doc.insert(8, '\n');
150
-      final expectedChange = new Delta()
150
+      final expectedChange = Delta()
151
         ..retain(8)
151
         ..retain(8)
152
         ..insert('\n', ul);
152
         ..insert('\n', ul);
153
       expect(change, expectedChange);
153
       expect(change, expectedChange);
157
       NotusDocument doc = dartconfDoc();
157
       NotusDocument doc = dartconfDoc();
158
       doc.format(0, 15, NotusAttribute.ul);
158
       doc.format(0, 15, NotusAttribute.ul);
159
       doc.insert(8, '\n');
159
       doc.insert(8, '\n');
160
-      final expectedDoc = new Delta()
160
+      final expectedDoc = Delta()
161
         ..insert('DartConf')
161
         ..insert('DartConf')
162
         ..insert('\n\n', ul)
162
         ..insert('\n\n', ul)
163
         ..insert('Los Angeles')
163
         ..insert('Los Angeles')
182
     test('compose throws assert error if change is empty', () {
182
     test('compose throws assert error if change is empty', () {
183
       NotusDocument doc = dartconfDoc();
183
       NotusDocument doc = dartconfDoc();
184
       expect(() {
184
       expect(() {
185
-        doc.compose(new Delta()..retain(1), ChangeSource.local);
185
+        doc.compose(Delta()..retain(1), ChangeSource.local);
186
       }, throwsA(const TypeMatcher<AssertionError>()));
186
       }, throwsA(const TypeMatcher<AssertionError>()));
187
     });
187
     });
188
 
188
 
219
       doc.close();
219
       doc.close();
220
       expect(doc.isClosed, isTrue);
220
       expect(doc.isClosed, isTrue);
221
       expect(() {
221
       expect(() {
222
-        doc.compose(new Delta()..insert('a'), ChangeSource.local);
222
+        doc.compose(Delta()..insert('a'), ChangeSource.local);
223
       }, throwsAssertionError);
223
       }, throwsAssertionError);
224
       expect(() {
224
       expect(() {
225
         doc.insert(0, 'a');
225
         doc.insert(0, 'a');
247
       LineNode line = doc.root.children.elementAt(1);
247
       LineNode line = doc.root.children.elementAt(1);
248
       EmbedNode embed = line.first;
248
       EmbedNode embed = line.first;
249
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
249
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
250
-      final style = new NotusStyle().merge(NotusAttribute.embed.horizontalRule);
250
+      final style = NotusStyle().merge(NotusAttribute.embed.horizontalRule);
251
       expect(embed.style, style);
251
       expect(embed.style, style);
252
     });
252
     });
253
 
253
 
260
       LineNode line = doc.root.children.elementAt(1);
260
       LineNode line = doc.root.children.elementAt(1);
261
       EmbedNode embed = line.first;
261
       EmbedNode embed = line.first;
262
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
262
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
263
-      final style = new NotusStyle().merge(NotusAttribute.embed.horizontalRule);
263
+      final style = NotusStyle().merge(NotusAttribute.embed.horizontalRule);
264
       expect(embed.style, style);
264
       expect(embed.style, style);
265
     });
265
     });
266
 
266
 
276
       LineNode line = doc.root.children.elementAt(1);
276
       LineNode line = doc.root.children.elementAt(1);
277
       EmbedNode embed = line.first;
277
       EmbedNode embed = line.first;
278
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
278
       expect(embed.toPlainText(), EmbedNode.kPlainTextPlaceholder);
279
-      final style = new NotusStyle().merge(NotusAttribute.embed.horizontalRule);
279
+      final style = NotusStyle().merge(NotusAttribute.embed.horizontalRule);
280
       expect(embed.style, style);
280
       expect(embed.style, style);
281
     });
281
     });
282
 
282
 

+ 18
- 18
packages/notus/test/heuristics/delete_rules_test.dart View File

10
 
10
 
11
 void main() {
11
 void main() {
12
   group('$PreserveLineStyleOnMergeRule', () {
12
   group('$PreserveLineStyleOnMergeRule', () {
13
-    final rule = new PreserveLineStyleOnMergeRule();
13
+    final rule = PreserveLineStyleOnMergeRule();
14
     test('preserves block style', () {
14
     test('preserves block style', () {
15
       final ul = NotusAttribute.ul.toJson();
15
       final ul = NotusAttribute.ul.toJson();
16
-      final doc = new Delta()
16
+      final doc = Delta()
17
         ..insert('Title\nOne')
17
         ..insert('Title\nOne')
18
         ..insert('\n', ul)
18
         ..insert('\n', ul)
19
         ..insert('Two\n');
19
         ..insert('Two\n');
20
       final actual = rule.apply(doc, 9, 1);
20
       final actual = rule.apply(doc, 9, 1);
21
-      final expected = new Delta()
21
+      final expected = Delta()
22
         ..retain(9)
22
         ..retain(9)
23
         ..delete(1)
23
         ..delete(1)
24
         ..retain(3)
24
         ..retain(3)
28
 
28
 
29
     test('resets block style', () {
29
     test('resets block style', () {
30
       final unsetUl = NotusAttribute.block.unset.toJson();
30
       final unsetUl = NotusAttribute.block.unset.toJson();
31
-      final doc = new Delta()
31
+      final doc = Delta()
32
         ..insert('Title\nOne')
32
         ..insert('Title\nOne')
33
         ..insert('\n', NotusAttribute.ul.toJson())
33
         ..insert('\n', NotusAttribute.ul.toJson())
34
         ..insert('Two\n');
34
         ..insert('Two\n');
35
       final actual = rule.apply(doc, 5, 1);
35
       final actual = rule.apply(doc, 5, 1);
36
-      final expected = new Delta()
36
+      final expected = Delta()
37
         ..retain(5)
37
         ..retain(5)
38
         ..delete(1)
38
         ..delete(1)
39
         ..retain(3)
39
         ..retain(3)
43
   });
43
   });
44
 
44
 
45
   group('$CatchAllDeleteRule', () {
45
   group('$CatchAllDeleteRule', () {
46
-    final rule = new CatchAllDeleteRule();
46
+    final rule = CatchAllDeleteRule();
47
 
47
 
48
     test('applies change as-is', () {
48
     test('applies change as-is', () {
49
-      final doc = new Delta()..insert('Document\n');
49
+      final doc = Delta()..insert('Document\n');
50
       final actual = rule.apply(doc, 3, 5);
50
       final actual = rule.apply(doc, 3, 5);
51
-      final expected = new Delta()
51
+      final expected = Delta()
52
         ..retain(3)
52
         ..retain(3)
53
         ..delete(5);
53
         ..delete(5);
54
       expect(actual, expected);
54
       expect(actual, expected);
56
   });
56
   });
57
 
57
 
58
   group('$EnsureEmbedLineRule', () {
58
   group('$EnsureEmbedLineRule', () {
59
-    final rule = new EnsureEmbedLineRule();
59
+    final rule = EnsureEmbedLineRule();
60
 
60
 
61
     test('ensures line-break before embed', () {
61
     test('ensures line-break before embed', () {
62
       final hr = NotusAttribute.embed.horizontalRule;
62
       final hr = NotusAttribute.embed.horizontalRule;
63
-      final doc = new Delta()
63
+      final doc = Delta()
64
         ..insert('Document\n')
64
         ..insert('Document\n')
65
         ..insert(kZeroWidthSpace, hr.toJson())
65
         ..insert(kZeroWidthSpace, hr.toJson())
66
         ..insert('\n');
66
         ..insert('\n');
67
       final actual = rule.apply(doc, 8, 1);
67
       final actual = rule.apply(doc, 8, 1);
68
-      final expected = new Delta()..retain(8);
68
+      final expected = Delta()..retain(8);
69
       expect(actual, expected);
69
       expect(actual, expected);
70
     });
70
     });
71
 
71
 
72
     test('ensures line-break after embed', () {
72
     test('ensures line-break after embed', () {
73
       final hr = NotusAttribute.embed.horizontalRule;
73
       final hr = NotusAttribute.embed.horizontalRule;
74
-      final doc = new Delta()
74
+      final doc = Delta()
75
         ..insert('Document\n')
75
         ..insert('Document\n')
76
         ..insert(kZeroWidthSpace, hr.toJson())
76
         ..insert(kZeroWidthSpace, hr.toJson())
77
         ..insert('\n');
77
         ..insert('\n');
78
       final actual = rule.apply(doc, 10, 1);
78
       final actual = rule.apply(doc, 10, 1);
79
-      final expected = new Delta()..retain(11);
79
+      final expected = Delta()..retain(11);
80
       expect(actual, expected);
80
       expect(actual, expected);
81
     });
81
     });
82
 
82
 
83
     test('still deletes everything between embeds', () {
83
     test('still deletes everything between embeds', () {
84
       final hr = NotusAttribute.embed.horizontalRule;
84
       final hr = NotusAttribute.embed.horizontalRule;
85
-      final doc = new Delta()
85
+      final doc = Delta()
86
         ..insert('Document\n')
86
         ..insert('Document\n')
87
         ..insert(kZeroWidthSpace, hr.toJson())
87
         ..insert(kZeroWidthSpace, hr.toJson())
88
         ..insert('\nSome text\n')
88
         ..insert('\nSome text\n')
89
         ..insert(kZeroWidthSpace, hr.toJson())
89
         ..insert(kZeroWidthSpace, hr.toJson())
90
         ..insert('\n');
90
         ..insert('\n');
91
       final actual = rule.apply(doc, 10, 11);
91
       final actual = rule.apply(doc, 10, 11);
92
-      final expected = new Delta()
92
+      final expected = Delta()
93
         ..retain(11)
93
         ..retain(11)
94
         ..delete(9);
94
         ..delete(9);
95
       expect(actual, expected);
95
       expect(actual, expected);
97
 
97
 
98
     test('allows deleting empty line after embed', () {
98
     test('allows deleting empty line after embed', () {
99
       final hr = NotusAttribute.embed.horizontalRule;
99
       final hr = NotusAttribute.embed.horizontalRule;
100
-      final doc = new Delta()
100
+      final doc = Delta()
101
         ..insert('Document\n')
101
         ..insert('Document\n')
102
         ..insert(kZeroWidthSpace, hr.toJson())
102
         ..insert(kZeroWidthSpace, hr.toJson())
103
         ..insert('\n')
103
         ..insert('\n')
105
         ..insert('Text')
105
         ..insert('Text')
106
         ..insert('\n');
106
         ..insert('\n');
107
       final actual = rule.apply(doc, 10, 1);
107
       final actual = rule.apply(doc, 10, 1);
108
-      final expected = new Delta()
108
+      final expected = Delta()
109
         ..retain(11)
109
         ..retain(11)
110
         ..delete(1);
110
         ..delete(1);
111
       expect(actual, expected);
111
       expect(actual, expected);
113
 
113
 
114
     test('allows deleting empty line(s) before embed', () {
114
     test('allows deleting empty line(s) before embed', () {
115
       final hr = NotusAttribute.embed.horizontalRule;
115
       final hr = NotusAttribute.embed.horizontalRule;
116
-      final doc = new Delta()
116
+      final doc = Delta()
117
         ..insert('Document\n')
117
         ..insert('Document\n')
118
         ..insert('\n')
118
         ..insert('\n')
119
         ..insert('\n')
119
         ..insert('\n')

+ 13
- 13
packages/notus/test/heuristics/format_rules_test.dart View File

10
 
10
 
11
 void main() {
11
 void main() {
12
   group('$ResolveLineFormatRule', () {
12
   group('$ResolveLineFormatRule', () {
13
-    final rule = new ResolveLineFormatRule();
13
+    final rule = ResolveLineFormatRule();
14
 
14
 
15
     test('apply', () {
15
     test('apply', () {
16
-      final doc = new Delta()..insert('Correct\nLine\nStyle\nRule\n');
16
+      final doc = Delta()..insert('Correct\nLine\nStyle\nRule\n');
17
 
17
 
18
       final actual = rule.apply(doc, 0, 20, NotusAttribute.ul);
18
       final actual = rule.apply(doc, 0, 20, NotusAttribute.ul);
19
       expect(actual, isNotNull);
19
       expect(actual, isNotNull);
20
       final ul = NotusAttribute.ul.toJson();
20
       final ul = NotusAttribute.ul.toJson();
21
-      final expected = new Delta()
21
+      final expected = Delta()
22
         ..retain(7)
22
         ..retain(7)
23
         ..retain(1, ul)
23
         ..retain(1, ul)
24
         ..retain(4)
24
         ..retain(4)
31
     });
31
     });
32
 
32
 
33
     test('apply with zero length (collapsed selection)', () {
33
     test('apply with zero length (collapsed selection)', () {
34
-      final doc = new Delta()..insert('Correct\nLine\nStyle\nRule\n');
34
+      final doc = Delta()..insert('Correct\nLine\nStyle\nRule\n');
35
       final actual = rule.apply(doc, 0, 0, NotusAttribute.ul);
35
       final actual = rule.apply(doc, 0, 0, NotusAttribute.ul);
36
       expect(actual, isNotNull);
36
       expect(actual, isNotNull);
37
       final ul = NotusAttribute.ul.toJson();
37
       final ul = NotusAttribute.ul.toJson();
38
-      final expected = new Delta()..retain(7)..retain(1, ul);
38
+      final expected = Delta()..retain(7)..retain(1, ul);
39
       expect(actual, expected);
39
       expect(actual, expected);
40
     });
40
     });
41
 
41
 
42
     test('apply with zero length in the middle of a line', () {
42
     test('apply with zero length in the middle of a line', () {
43
       final ul = NotusAttribute.ul.toJson();
43
       final ul = NotusAttribute.ul.toJson();
44
-      final doc = new Delta()
44
+      final doc = Delta()
45
         ..insert('Title\nOne')
45
         ..insert('Title\nOne')
46
         ..insert('\n', ul)
46
         ..insert('\n', ul)
47
         ..insert('Two')
47
         ..insert('Two')
48
         ..insert('\n', ul)
48
         ..insert('\n', ul)
49
         ..insert('Three!\n');
49
         ..insert('Three!\n');
50
       final actual = rule.apply(doc, 7, 0, NotusAttribute.ul);
50
       final actual = rule.apply(doc, 7, 0, NotusAttribute.ul);
51
-      final expected = new Delta()..retain(9)..retain(1, ul);
51
+      final expected = Delta()..retain(9)..retain(1, ul);
52
       expect(actual, expected);
52
       expect(actual, expected);
53
     });
53
     });
54
   });
54
   });
55
 
55
 
56
   group('$ResolveInlineFormatRule', () {
56
   group('$ResolveInlineFormatRule', () {
57
-    final rule = new ResolveInlineFormatRule();
57
+    final rule = ResolveInlineFormatRule();
58
 
58
 
59
     test('apply', () {
59
     test('apply', () {
60
-      final doc = new Delta()..insert('Correct\nLine\nStyle\nRule\n');
60
+      final doc = Delta()..insert('Correct\nLine\nStyle\nRule\n');
61
 
61
 
62
       final actual = rule.apply(doc, 0, 20, NotusAttribute.bold);
62
       final actual = rule.apply(doc, 0, 20, NotusAttribute.bold);
63
       expect(actual, isNotNull);
63
       expect(actual, isNotNull);
64
       final b = NotusAttribute.bold.toJson();
64
       final b = NotusAttribute.bold.toJson();
65
-      final expected = new Delta()
65
+      final expected = Delta()
66
         ..retain(7, b)
66
         ..retain(7, b)
67
         ..retain(1)
67
         ..retain(1)
68
         ..retain(4, b)
68
         ..retain(4, b)
75
   });
75
   });
76
 
76
 
77
   group('$FormatLinkAtCaretPositionRule', () {
77
   group('$FormatLinkAtCaretPositionRule', () {
78
-    final rule = new FormatLinkAtCaretPositionRule();
78
+    final rule = FormatLinkAtCaretPositionRule();
79
 
79
 
80
     test('apply', () {
80
     test('apply', () {
81
       final link =
81
       final link =
82
           NotusAttribute.link.fromString('https://github.com/memspace/bold');
82
           NotusAttribute.link.fromString('https://github.com/memspace/bold');
83
       final newLink =
83
       final newLink =
84
           NotusAttribute.link.fromString('https://github.com/memspace/zefyr');
84
           NotusAttribute.link.fromString('https://github.com/memspace/zefyr');
85
-      final doc = new Delta()
85
+      final doc = Delta()
86
         ..insert('Visit our ')
86
         ..insert('Visit our ')
87
         ..insert('website', link.toJson())
87
         ..insert('website', link.toJson())
88
         ..insert(' for more details.\n');
88
         ..insert(' for more details.\n');
89
 
89
 
90
       final actual = rule.apply(doc, 13, 0, newLink);
90
       final actual = rule.apply(doc, 13, 0, newLink);
91
       expect(actual, isNotNull);
91
       expect(actual, isNotNull);
92
-      final expected = new Delta()..retain(10)..retain(7, newLink.toJson());
92
+      final expected = Delta()..retain(10)..retain(7, newLink.toJson());
93
       expect(actual, expected);
93
       expect(actual, expected);
94
     });
94
     });
95
   });
95
   });

+ 38
- 39
packages/notus/test/heuristics/insert_rules_test.dart View File

10
 
10
 
11
 void main() {
11
 void main() {
12
   group('$CatchAllInsertRule', () {
12
   group('$CatchAllInsertRule', () {
13
-    final rule = new CatchAllInsertRule();
13
+    final rule = CatchAllInsertRule();
14
 
14
 
15
     test('applies change as-is', () {
15
     test('applies change as-is', () {
16
-      final doc = new Delta()..insert('Document\n');
16
+      final doc = Delta()..insert('Document\n');
17
       final actual = rule.apply(doc, 8, '!');
17
       final actual = rule.apply(doc, 8, '!');
18
-      final expected = new Delta()
18
+      final expected = Delta()
19
         ..retain(8)
19
         ..retain(8)
20
         ..insert('!');
20
         ..insert('!');
21
       expect(actual, expected);
21
       expect(actual, expected);
23
   });
23
   });
24
 
24
 
25
   group('$PreserveLineStyleOnSplitRule', () {
25
   group('$PreserveLineStyleOnSplitRule', () {
26
-    final rule = new PreserveLineStyleOnSplitRule();
26
+    final rule = PreserveLineStyleOnSplitRule();
27
 
27
 
28
     test('skips at the beginning of a document', () {
28
     test('skips at the beginning of a document', () {
29
-      final doc = new Delta()..insert('One\n');
29
+      final doc = Delta()..insert('One\n');
30
       final actual = rule.apply(doc, 0, '\n');
30
       final actual = rule.apply(doc, 0, '\n');
31
       expect(actual, isNull);
31
       expect(actual, isNull);
32
     });
32
     });
33
 
33
 
34
     test('applies in a block', () {
34
     test('applies in a block', () {
35
-      final doc = new Delta()
35
+      final doc = Delta()
36
         ..insert('One and two')
36
         ..insert('One and two')
37
         ..insert('\n', ul)
37
         ..insert('\n', ul)
38
         ..insert('Three')
38
         ..insert('Three')
39
         ..insert('\n', ul);
39
         ..insert('\n', ul);
40
       final actual = rule.apply(doc, 8, '\n');
40
       final actual = rule.apply(doc, 8, '\n');
41
-      final expected = new Delta()
41
+      final expected = Delta()
42
         ..retain(8)
42
         ..retain(8)
43
         ..insert('\n', ul);
43
         ..insert('\n', ul);
44
       expect(actual, isNotNull);
44
       expect(actual, isNotNull);
50
     final rule = const ResetLineFormatOnNewLineRule();
50
     final rule = const ResetLineFormatOnNewLineRule();
51
 
51
 
52
     test('applies when line-break is inserted at the end of line', () {
52
     test('applies when line-break is inserted at the end of line', () {
53
-      final doc = new Delta()
53
+      final doc = Delta()
54
         ..insert('Hello world')
54
         ..insert('Hello world')
55
         ..insert('\n', NotusAttribute.h1.toJson());
55
         ..insert('\n', NotusAttribute.h1.toJson());
56
       final actual = rule.apply(doc, 11, '\n');
56
       final actual = rule.apply(doc, 11, '\n');
57
       expect(actual, isNotNull);
57
       expect(actual, isNotNull);
58
-      final expected = new Delta()
58
+      final expected = Delta()
59
         ..retain(11)
59
         ..retain(11)
60
         ..insert('\n', NotusAttribute.h1.toJson())
60
         ..insert('\n', NotusAttribute.h1.toJson())
61
         ..retain(1, NotusAttribute.heading.unset.toJson());
61
         ..retain(1, NotusAttribute.heading.unset.toJson());
63
     });
63
     });
64
 
64
 
65
     test('applies without style reset if not needed', () {
65
     test('applies without style reset if not needed', () {
66
-      final doc = new Delta()..insert('Hello world\n');
66
+      final doc = Delta()..insert('Hello world\n');
67
       final actual = rule.apply(doc, 11, '\n');
67
       final actual = rule.apply(doc, 11, '\n');
68
       expect(actual, isNotNull);
68
       expect(actual, isNotNull);
69
-      final expected = new Delta()
69
+      final expected = Delta()
70
         ..retain(11)
70
         ..retain(11)
71
         ..insert('\n');
71
         ..insert('\n');
72
       expect(actual, expected);
72
       expect(actual, expected);
73
     });
73
     });
74
 
74
 
75
     test('applies at the beginning of a document', () {
75
     test('applies at the beginning of a document', () {
76
-      final doc = new Delta()..insert('\n', NotusAttribute.h1.toJson());
76
+      final doc = Delta()..insert('\n', NotusAttribute.h1.toJson());
77
       final actual = rule.apply(doc, 0, '\n');
77
       final actual = rule.apply(doc, 0, '\n');
78
       expect(actual, isNotNull);
78
       expect(actual, isNotNull);
79
-      final expected = new Delta()
79
+      final expected = Delta()
80
         ..insert('\n', NotusAttribute.h1.toJson())
80
         ..insert('\n', NotusAttribute.h1.toJson())
81
         ..retain(1, NotusAttribute.heading.unset.toJson());
81
         ..retain(1, NotusAttribute.heading.unset.toJson());
82
       expect(actual, expected);
82
       expect(actual, expected);
85
     test('applies and keeps block style', () {
85
     test('applies and keeps block style', () {
86
       final style = NotusAttribute.ul.toJson();
86
       final style = NotusAttribute.ul.toJson();
87
       style.addAll(NotusAttribute.h1.toJson());
87
       style.addAll(NotusAttribute.h1.toJson());
88
-      final doc = new Delta()..insert('Hello world')..insert('\n', style);
88
+      final doc = Delta()..insert('Hello world')..insert('\n', style);
89
       final actual = rule.apply(doc, 11, '\n');
89
       final actual = rule.apply(doc, 11, '\n');
90
       expect(actual, isNotNull);
90
       expect(actual, isNotNull);
91
-      final expected = new Delta()
91
+      final expected = Delta()
92
         ..retain(11)
92
         ..retain(11)
93
         ..insert('\n', style)
93
         ..insert('\n', style)
94
         ..retain(1, NotusAttribute.heading.unset.toJson());
94
         ..retain(1, NotusAttribute.heading.unset.toJson());
96
     });
96
     });
97
 
97
 
98
     test('applies to a line in the middle of a document', () {
98
     test('applies to a line in the middle of a document', () {
99
-      final doc = new Delta()
99
+      final doc = Delta()
100
         ..insert('Hello \nworld!\nMore lines here.')
100
         ..insert('Hello \nworld!\nMore lines here.')
101
         ..insert('\n', NotusAttribute.h2.toJson());
101
         ..insert('\n', NotusAttribute.h2.toJson());
102
       final actual = rule.apply(doc, 30, '\n');
102
       final actual = rule.apply(doc, 30, '\n');
103
       expect(actual, isNotNull);
103
       expect(actual, isNotNull);
104
-      final expected = new Delta()
104
+      final expected = Delta()
105
         ..retain(30)
105
         ..retain(30)
106
         ..insert('\n', NotusAttribute.h2.toJson())
106
         ..insert('\n', NotusAttribute.h2.toJson())
107
         ..retain(1, NotusAttribute.heading.unset.toJson());
107
         ..retain(1, NotusAttribute.heading.unset.toJson());
110
   });
110
   });
111
 
111
 
112
   group('$AutoExitBlockRule', () {
112
   group('$AutoExitBlockRule', () {
113
-    final rule = new AutoExitBlockRule();
113
+    final rule = AutoExitBlockRule();
114
 
114
 
115
     test('applies when line-break is inserted on empty line in a block', () {
115
     test('applies when line-break is inserted on empty line in a block', () {
116
       final ul = NotusAttribute.ul.toJson();
116
       final ul = NotusAttribute.ul.toJson();
117
-      final doc = new Delta()
117
+      final doc = Delta()
118
         ..insert('Item 1')
118
         ..insert('Item 1')
119
         ..insert('\n', ul)
119
         ..insert('\n', ul)
120
         ..insert('Item 2')
120
         ..insert('Item 2')
121
         ..insert('\n\n', ul);
121
         ..insert('\n\n', ul);
122
       final actual = rule.apply(doc, 14, '\n');
122
       final actual = rule.apply(doc, 14, '\n');
123
       expect(actual, isNotNull);
123
       expect(actual, isNotNull);
124
-      final expected = new Delta()
124
+      final expected = Delta()
125
         ..retain(14)
125
         ..retain(14)
126
         ..retain(1, NotusAttribute.block.unset.toJson());
126
         ..retain(1, NotusAttribute.block.unset.toJson());
127
       expect(actual, expected);
127
       expect(actual, expected);
129
 
129
 
130
     test('applies only on empty line', () {
130
     test('applies only on empty line', () {
131
       final ul = NotusAttribute.ul.toJson();
131
       final ul = NotusAttribute.ul.toJson();
132
-      final doc = new Delta()..insert('Item 1')..insert('\n', ul);
132
+      final doc = Delta()..insert('Item 1')..insert('\n', ul);
133
       final actual = rule.apply(doc, 6, '\n');
133
       final actual = rule.apply(doc, 6, '\n');
134
       expect(actual, isNull);
134
       expect(actual, isNull);
135
     });
135
     });
136
 
136
 
137
     test('applies at the beginning of a document', () {
137
     test('applies at the beginning of a document', () {
138
       final ul = NotusAttribute.ul.toJson();
138
       final ul = NotusAttribute.ul.toJson();
139
-      final doc = new Delta()..insert('\n', ul);
139
+      final doc = Delta()..insert('\n', ul);
140
       final actual = rule.apply(doc, 0, '\n');
140
       final actual = rule.apply(doc, 0, '\n');
141
       expect(actual, isNotNull);
141
       expect(actual, isNotNull);
142
-      final expected = new Delta()
143
-        ..retain(1, NotusAttribute.block.unset.toJson());
142
+      final expected = Delta()..retain(1, NotusAttribute.block.unset.toJson());
144
       expect(actual, expected);
143
       expect(actual, expected);
145
     });
144
     });
146
 
145
 
147
     test('ignores non-empty line at the beginning of a document', () {
146
     test('ignores non-empty line at the beginning of a document', () {
148
       final ul = NotusAttribute.ul.toJson();
147
       final ul = NotusAttribute.ul.toJson();
149
-      final doc = new Delta()..insert('Text\n', ul);
148
+      final doc = Delta()..insert('Text\n', ul);
150
       final actual = rule.apply(doc, 0, '\n');
149
       final actual = rule.apply(doc, 0, '\n');
151
       expect(actual, isNull);
150
       expect(actual, isNull);
152
     });
151
     });
153
   });
152
   });
154
 
153
 
155
   group('$PreserveInlineStylesRule', () {
154
   group('$PreserveInlineStylesRule', () {
156
-    final rule = new PreserveInlineStylesRule();
155
+    final rule = PreserveInlineStylesRule();
157
     test('apply', () {
156
     test('apply', () {
158
-      final doc = new Delta()
157
+      final doc = Delta()
159
         ..insert('Doc with ')
158
         ..insert('Doc with ')
160
         ..insert('bold', bold)
159
         ..insert('bold', bold)
161
         ..insert(' text');
160
         ..insert(' text');
162
       final actual = rule.apply(doc, 13, 'er');
161
       final actual = rule.apply(doc, 13, 'er');
163
-      final expected = new Delta()
162
+      final expected = Delta()
164
         ..retain(13)
163
         ..retain(13)
165
         ..insert('er', bold);
164
         ..insert('er', bold);
166
       expect(expected, actual);
165
       expect(expected, actual);
167
     });
166
     });
168
 
167
 
169
     test('apply at the beginning of a document', () {
168
     test('apply at the beginning of a document', () {
170
-      final doc = new Delta()..insert('Doc with ');
169
+      final doc = Delta()..insert('Doc with ');
171
       final actual = rule.apply(doc, 0, 'A ');
170
       final actual = rule.apply(doc, 0, 'A ');
172
       expect(actual, isNull);
171
       expect(actual, isNull);
173
     });
172
     });
174
   });
173
   });
175
 
174
 
176
   group('$AutoFormatLinksRule', () {
175
   group('$AutoFormatLinksRule', () {
177
-    final rule = new AutoFormatLinksRule();
176
+    final rule = AutoFormatLinksRule();
178
     final link = NotusAttribute.link.fromString('https://example.com').toJson();
177
     final link = NotusAttribute.link.fromString('https://example.com').toJson();
179
 
178
 
180
     test('apply simple', () {
179
     test('apply simple', () {
181
-      final doc = new Delta()..insert('Doc with link https://example.com');
180
+      final doc = Delta()..insert('Doc with link https://example.com');
182
       final actual = rule.apply(doc, 33, ' ');
181
       final actual = rule.apply(doc, 33, ' ');
183
-      final expected = new Delta()
182
+      final expected = Delta()
184
         ..retain(14)
183
         ..retain(14)
185
         ..retain(19, link)
184
         ..retain(19, link)
186
         ..insert(' ');
185
         ..insert(' ');
188
     });
187
     });
189
 
188
 
190
     test('applies only to insert of single space', () {
189
     test('applies only to insert of single space', () {
191
-      final doc = new Delta()..insert('Doc with link https://example.com');
190
+      final doc = Delta()..insert('Doc with link https://example.com');
192
       final actual = rule.apply(doc, 33, '/');
191
       final actual = rule.apply(doc, 33, '/');
193
       expect(actual, isNull);
192
       expect(actual, isNull);
194
     });
193
     });
195
 
194
 
196
     test('applies for links at the beginning of line', () {
195
     test('applies for links at the beginning of line', () {
197
-      final doc = new Delta()..insert('Doc with link\nhttps://example.com');
196
+      final doc = Delta()..insert('Doc with link\nhttps://example.com');
198
       final actual = rule.apply(doc, 33, ' ');
197
       final actual = rule.apply(doc, 33, ' ');
199
-      final expected = new Delta()
198
+      final expected = Delta()
200
         ..retain(14)
199
         ..retain(14)
201
         ..retain(19, link)
200
         ..retain(19, link)
202
         ..insert(' ');
201
         ..insert(' ');
204
     });
203
     });
205
 
204
 
206
     test('ignores if already formatted as link', () {
205
     test('ignores if already formatted as link', () {
207
-      final doc = new Delta()
206
+      final doc = Delta()
208
         ..insert('Doc with link\n')
207
         ..insert('Doc with link\n')
209
         ..insert('https://example.com', link);
208
         ..insert('https://example.com', link);
210
       final actual = rule.apply(doc, 33, ' ');
209
       final actual = rule.apply(doc, 33, ' ');
213
   });
212
   });
214
 
213
 
215
   group('$PreserveBlockStyleOnPasteRule', () {
214
   group('$PreserveBlockStyleOnPasteRule', () {
216
-    final rule = new PreserveBlockStyleOnPasteRule();
215
+    final rule = PreserveBlockStyleOnPasteRule();
217
 
216
 
218
     test('applies in a block', () {
217
     test('applies in a block', () {
219
-      final doc = new Delta()
218
+      final doc = Delta()
220
         ..insert('One and two')
219
         ..insert('One and two')
221
         ..insert('\n', ul)
220
         ..insert('\n', ul)
222
         ..insert('Three')
221
         ..insert('Three')
223
         ..insert('\n', ul);
222
         ..insert('\n', ul);
224
       final actual = rule.apply(doc, 8, 'also \n');
223
       final actual = rule.apply(doc, 8, 'also \n');
225
-      final expected = new Delta()
224
+      final expected = Delta()
226
         ..retain(8)
225
         ..retain(8)
227
         ..insert('also ')
226
         ..insert('also ')
228
         ..insert('\n', ul);
227
         ..insert('\n', ul);

+ 3
- 3
packages/notus/test/heuristics_test.dart View File

7
 import 'package:test/test.dart';
7
 import 'package:test/test.dart';
8
 
8
 
9
 NotusDocument dartconfDoc() {
9
 NotusDocument dartconfDoc() {
10
-  Delta delta = new Delta()..insert('DartConf\nLos Angeles\n');
11
-  return new NotusDocument.fromDelta(delta);
10
+  Delta delta = Delta()..insert('DartConf\nLos Angeles\n');
11
+  return NotusDocument.fromDelta(delta);
12
 }
12
 }
13
 
13
 
14
 final ul = NotusAttribute.ul.toJson();
14
 final ul = NotusAttribute.ul.toJson();
18
   group('$NotusHeuristics', () {
18
   group('$NotusHeuristics', () {
19
     test('ensures heuristics are applied', () {
19
     test('ensures heuristics are applied', () {
20
       final doc = dartconfDoc();
20
       final doc = dartconfDoc();
21
-      final heuristics = new NotusHeuristics(
21
+      final heuristics = NotusHeuristics(
22
         formatRules: [],
22
         formatRules: [],
23
         insertRules: [],
23
         insertRules: [],
24
         deleteRules: [],
24
         deleteRules: [],

+ 3
- 4
packages/notus/test/matchers.dart View File

4
 
4
 
5
 import 'package:test/test.dart';
5
 import 'package:test/test.dart';
6
 
6
 
7
-const isAssertionError = const TypeMatcher<AssertionError>();
7
+const isAssertionError = TypeMatcher<AssertionError>();
8
 
8
 
9
-const Matcher throwsAssertionError =
10
-    // ignore: deprecated_member_use
11
-    const Throws(isAssertionError);
9
+// ignore: deprecated_member_use
10
+const Matcher throwsAssertionError = Throws(isAssertionError);