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.
24
35import 'package:dartdoc/src/mustachio/parser.dart' ;
46import 'package:test/test.dart' ;
@@ -354,11 +356,11 @@ void main() {
354356 expect (ast, hasLength (2 ));
355357 _expectText (ast[0 ], equals ('Text ' ));
356358 var section = ast[1 ] as Section ;
357- _expectSection (section, equals (['key' ]));
359+ _expectSection (section, equals (['key' ]), spanStart : 5 , spanEnd : 49 );
358360 expect (section.children, hasLength (3 ));
359361 _expectText (section.children[0 ], equals (' AA ' ));
360362 var innerSection = section.children[1 ] as Section ;
361- _expectSection (innerSection, equals (['key' ]));
363+ _expectSection (innerSection, equals (['key' ]), spanStart : 17 , spanEnd : 37 );
362364 expect (innerSection.children, hasLength (1 ));
363365 _expectText (innerSection.children[0 ], equals (' BB ' ));
364366 });
@@ -407,7 +409,7 @@ void main() {
407409}
408410
409411void _expectText (MustachioNode node, Object matcher,
410- {int spanStart, int spanEnd}) {
412+ {int ? spanStart, int ? spanEnd}) {
411413 expect (node, isA <Text >().having ((e) => e.content, 'content' , matcher));
412414 if (spanStart != null ) {
413415 expect (
@@ -421,82 +423,94 @@ void _expectText(MustachioNode node, Object matcher,
421423 }
422424}
423425
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+ }) {
430435 expect (
431436 node,
432437 isA <Variable >()
433438 .having ((e) => e.key, 'key' , matcher)
434439 .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+
443448 if (keySpanStart != null ) {
444- var actualKeySpanStart = ( node as Variable ) .keySpan.start.offset;
449+ var actualKeySpanStart = node.keySpan.start.offset;
445450 _expectSpanOffset (
446451 'Variable key' , 'start' , actualKeySpanStart, keySpanStart);
447452 }
448453 if (keySpanEnd != null ) {
449- var actualKeySpanEnd = ( node as Variable ) .keySpan.end.offset;
454+ var actualKeySpanEnd = node.keySpan.end.offset;
450455 _expectSpanOffset ('Variable key' , 'end' , actualKeySpanEnd, keySpanEnd);
451456 }
452457}
453458
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+ }) {
460468 expect (
461469 node,
462470 isA <Section >()
463471 .having ((e) => e.key, 'key' , matcher)
464472 .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+
473481 if (keySpanStart != null ) {
474- var actualKeySpanStart = ( node as Section ) .keySpan.start.offset;
482+ var actualKeySpanStart = node.keySpan.start.offset;
475483 _expectSpanOffset ('Section key' , 'start' , actualKeySpanStart, keySpanStart);
476484 }
477485 if (keySpanEnd != null ) {
478- var actualKeySpanEnd = ( node as Section ) .keySpan.end.offset;
486+ var actualKeySpanEnd = node.keySpan.end.offset;
479487 _expectSpanOffset ('Section key' , 'end' , actualKeySpanEnd, keySpanEnd);
480488 }
481489}
482490
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+ }) {
485499 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+
494508 if (keySpanStart != null ) {
495- var actualKeySpanStart = ( node as Partial ) .keySpan.start.offset;
509+ var actualKeySpanStart = node.keySpan.start.offset;
496510 _expectSpanOffset ('Partial key' , 'start' , actualKeySpanStart, keySpanStart);
497511 }
498512 if (keySpanEnd != null ) {
499- var actualKeySpanEnd = ( node as Partial ) .keySpan.end.offset;
513+ var actualKeySpanEnd = node.keySpan.end.offset;
500514 _expectSpanOffset ('Partial key' , 'end' , actualKeySpanEnd, keySpanEnd);
501515 }
502516}
0 commit comments