1
- // @dart=2.9
1
+ // Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
2
4
3
5
import 'package:dartdoc/src/mustachio/parser.dart' ;
4
6
import 'package:test/test.dart' ;
@@ -354,11 +356,11 @@ void main() {
354
356
expect (ast, hasLength (2 ));
355
357
_expectText (ast[0 ], equals ('Text ' ));
356
358
var section = ast[1 ] as Section ;
357
- _expectSection (section, equals (['key' ]));
359
+ _expectSection (section, equals (['key' ]), spanStart : 5 , spanEnd : 49 );
358
360
expect (section.children, hasLength (3 ));
359
361
_expectText (section.children[0 ], equals (' AA ' ));
360
362
var innerSection = section.children[1 ] as Section ;
361
- _expectSection (innerSection, equals (['key' ]));
363
+ _expectSection (innerSection, equals (['key' ]), spanStart : 17 , spanEnd : 37 );
362
364
expect (innerSection.children, hasLength (1 ));
363
365
_expectText (innerSection.children[0 ], equals (' BB ' ));
364
366
});
@@ -407,7 +409,7 @@ void main() {
407
409
}
408
410
409
411
void _expectText (MustachioNode node, Object matcher,
410
- {int spanStart, int spanEnd}) {
412
+ {int ? spanStart, int ? spanEnd}) {
411
413
expect (node, isA <Text >().having ((e) => e.content, 'content' , matcher));
412
414
if (spanStart != null ) {
413
415
expect (
@@ -421,82 +423,94 @@ void _expectText(MustachioNode node, Object matcher,
421
423
}
422
424
}
423
425
424
- void _expectVariable (MustachioNode node, Object matcher,
425
- {bool escape = true ,
426
- int spanStart,
427
- int spanEnd,
428
- int keySpanStart,
429
- int keySpanEnd}) {
426
+ void _expectVariable (
427
+ MustachioNode node,
428
+ Object matcher, {
429
+ bool escape = true ,
430
+ required int spanStart,
431
+ required int spanEnd,
432
+ int ? keySpanStart,
433
+ int ? keySpanEnd,
434
+ }) {
430
435
expect (
431
436
node,
432
437
isA <Variable >()
433
438
.having ((e) => e.key, 'key' , matcher)
434
439
.having ((e) => e.escape, 'escape' , escape));
435
- if (spanStart != null ) {
436
- var actualSpanStart = (node as Variable ).span.start.offset;
437
- _expectSpanOffset ( 'Variable' , ' start' , actualSpanStart, spanStart) ;
438
- }
439
- if (spanEnd != null ) {
440
- var actualSpanEnd = ( node as Variable ) .span.end.offset;
441
- _expectSpanOffset ('Variable' , 'end' , actualSpanEnd, spanEnd);
442
- }
440
+ node as Variable ;
441
+
442
+ var actualSpanStart = node.span. start.offset ;
443
+ _expectSpanOffset ( 'Variable' , 'start' , actualSpanStart, spanStart);
444
+
445
+ var actualSpanEnd = node.span.end.offset;
446
+ _expectSpanOffset ('Variable' , 'end' , actualSpanEnd, spanEnd);
447
+
443
448
if (keySpanStart != null ) {
444
- var actualKeySpanStart = ( node as Variable ) .keySpan.start.offset;
449
+ var actualKeySpanStart = node.keySpan.start.offset;
445
450
_expectSpanOffset (
446
451
'Variable key' , 'start' , actualKeySpanStart, keySpanStart);
447
452
}
448
453
if (keySpanEnd != null ) {
449
- var actualKeySpanEnd = ( node as Variable ) .keySpan.end.offset;
454
+ var actualKeySpanEnd = node.keySpan.end.offset;
450
455
_expectSpanOffset ('Variable key' , 'end' , actualKeySpanEnd, keySpanEnd);
451
456
}
452
457
}
453
458
454
- void _expectSection (MustachioNode node, Object matcher,
455
- {bool invert = false ,
456
- int spanStart,
457
- int spanEnd,
458
- int keySpanStart,
459
- int keySpanEnd}) {
459
+ void _expectSection (
460
+ MustachioNode node,
461
+ Object matcher, {
462
+ bool invert = false ,
463
+ required int spanStart,
464
+ required int spanEnd,
465
+ int ? keySpanStart,
466
+ int ? keySpanEnd,
467
+ }) {
460
468
expect (
461
469
node,
462
470
isA <Section >()
463
471
.having ((e) => e.key, 'key' , matcher)
464
472
.having ((e) => e.invert, 'invert' , invert));
465
- if (spanStart != null ) {
466
- var actualSpanStart = (node as Section ).span.start.offset;
467
- _expectSpanOffset ( 'Section' , ' start' , actualSpanStart, spanStart) ;
468
- }
469
- if (spanEnd != null ) {
470
- var actualSpanEnd = ( node as Section ) .span.end.offset;
471
- _expectSpanOffset ('Section' , 'end' , actualSpanEnd, spanEnd);
472
- }
473
+ node as Section ;
474
+
475
+ var actualSpanStart = node.span. start.offset ;
476
+ _expectSpanOffset ( 'Section' , 'start' , actualSpanStart, spanStart);
477
+
478
+ var actualSpanEnd = node.span.end.offset;
479
+ _expectSpanOffset ('Section' , 'end' , actualSpanEnd, spanEnd);
480
+
473
481
if (keySpanStart != null ) {
474
- var actualKeySpanStart = ( node as Section ) .keySpan.start.offset;
482
+ var actualKeySpanStart = node.keySpan.start.offset;
475
483
_expectSpanOffset ('Section key' , 'start' , actualKeySpanStart, keySpanStart);
476
484
}
477
485
if (keySpanEnd != null ) {
478
- var actualKeySpanEnd = ( node as Section ) .keySpan.end.offset;
486
+ var actualKeySpanEnd = node.keySpan.end.offset;
479
487
_expectSpanOffset ('Section key' , 'end' , actualKeySpanEnd, keySpanEnd);
480
488
}
481
489
}
482
490
483
- void _expectPartial (MustachioNode node, Object matcher,
484
- {int spanStart, int spanEnd, int keySpanStart, int keySpanEnd}) {
491
+ void _expectPartial (
492
+ MustachioNode node,
493
+ Object matcher, {
494
+ required int spanStart,
495
+ required int spanEnd,
496
+ int ? keySpanStart,
497
+ int ? keySpanEnd,
498
+ }) {
485
499
expect (node, isA <Partial >().having ((e) => e.key, 'key' , matcher));
486
- if (spanStart != null ) {
487
- var actualSpanStart = (node as Partial ).span.start.offset;
488
- _expectSpanOffset ( 'Partial' , ' start' , actualSpanStart, spanStart) ;
489
- }
490
- if (spanEnd != null ) {
491
- var actualSpanEnd = ( node as Partial ) .span.end.offset;
492
- _expectSpanOffset ('Partial' , 'end' , actualSpanEnd, spanEnd);
493
- }
500
+ node as Partial ;
501
+
502
+ var actualSpanStart = node.span. start.offset ;
503
+ _expectSpanOffset ( 'Partial' , 'start' , actualSpanStart, spanStart);
504
+
505
+ var actualSpanEnd = node.span.end.offset;
506
+ _expectSpanOffset ('Partial' , 'end' , actualSpanEnd, spanEnd);
507
+
494
508
if (keySpanStart != null ) {
495
- var actualKeySpanStart = ( node as Partial ) .keySpan.start.offset;
509
+ var actualKeySpanStart = node.keySpan.start.offset;
496
510
_expectSpanOffset ('Partial key' , 'start' , actualKeySpanStart, keySpanStart);
497
511
}
498
512
if (keySpanEnd != null ) {
499
- var actualKeySpanEnd = ( node as Partial ) .keySpan.end.offset;
513
+ var actualKeySpanEnd = node.keySpan.end.offset;
500
514
_expectSpanOffset ('Partial key' , 'end' , actualKeySpanEnd, keySpanEnd);
501
515
}
502
516
}
0 commit comments