@@ -44,18 +44,14 @@ class FoldingComputerTest extends AbstractContextTest {
4444 Map <int , FoldingKind > expected, {
4545 Set <FoldingKind >? onlyVerify,
4646 }) {
47- var expectedRegions =
48- expected.entries.map ((entry) {
49- var range = code.ranges[entry.key].sourceRange;
50- return FoldingRegion (entry.value, range.offset, range.length);
51- }).toSet ();
52-
53- var actualRegions =
54- onlyVerify == null
55- ? regions.toSet ()
56- : regions
57- .where ((region) => onlyVerify.contains (region.kind))
58- .toSet ();
47+ var expectedRegions = expected.entries.map ((entry) {
48+ var range = code.ranges[entry.key].sourceRange;
49+ return FoldingRegion (entry.value, range.offset, range.length);
50+ }).toSet ();
51+
52+ var actualRegions = onlyVerify == null
53+ ? regions.toSet ()
54+ : regions.where ((region) => onlyVerify.contains (region.kind)).toSet ();
5955
6056 expect (actualRegions, expectedRegions);
6157 }
@@ -566,6 +562,97 @@ void f/*[0*/() {
566562 /*1]*/];
567563}/*0]*/
568564
565+ // Content after
566+ ''' ;
567+
568+ await _computeRegions (content);
569+ expectRegions ({0 : FoldingKind .FUNCTION_BODY , 1 : FoldingKind .LITERAL });
570+ }
571+
572+ Future <void > test_literal_list_insideNullAwareElement () async {
573+ var content = '''
574+ // Content before
575+
576+ void f/*[0*/() {
577+ final List<List<String>> things = <List<String>>[/*[1*/
578+ ?<String>[/*[2*/
579+ "one",
580+ "two"
581+ /*2]*/];
582+ /*1]*/];
583+ }/*0]*/
584+
585+ // Content after
586+ ''' ;
587+
588+ await _computeRegions (content);
589+ expectRegions ({
590+ 0 : FoldingKind .FUNCTION_BODY ,
591+ 1 : FoldingKind .LITERAL ,
592+ 2 : FoldingKind .LITERAL
593+ });
594+ }
595+
596+ Future <void > test_literal_list_insideNullAwareKey () async {
597+ var content = '''
598+ // Content before
599+
600+ void f/*[0*/() {
601+ final Map<List<String>, bool> things = <List<String>, bool>{/*[1*/
602+ ?<String>[/*[2*/
603+ "one",
604+ "two"
605+ /*2]*/]: true
606+ /*1]*/};
607+ }/*0]*/
608+
609+ // Content after
610+ ''' ;
611+
612+ await _computeRegions (content);
613+ expectRegions ({
614+ 0 : FoldingKind .FUNCTION_BODY ,
615+ 1 : FoldingKind .LITERAL ,
616+ 2 : FoldingKind .LITERAL
617+ });
618+ }
619+
620+ Future <void > test_literal_list_insideNullAwareValue () async {
621+ var content = '''
622+ // Content before
623+
624+ void f/*[0*/() {
625+ final Map<Symbol, List<String>> things = <Symbol, List<String>>{/*[1*/
626+ #key: ?<String>[/*[2*/
627+ "one",
628+ "two"
629+ /*2]*/]
630+ /*1]*/};
631+ }/*0]*/
632+
633+ // Content after
634+ ''' ;
635+
636+ await _computeRegions (content);
637+ expectRegions ({
638+ 0 : FoldingKind .FUNCTION_BODY ,
639+ 1 : FoldingKind .LITERAL ,
640+ 2 : FoldingKind .LITERAL
641+ });
642+ }
643+
644+ Future <void > test_literal_list_withNullAwareElement () async {
645+ var content = '''
646+ // Content before
647+
648+ void f/*[0*/() {
649+ final List<String> things = <String>[/*[1*/
650+ "one",
651+ ?null
652+ "two"
653+ /*1]*/];
654+ }/*0]*/
655+
569656// Content after
570657''' ;
571658
@@ -584,6 +671,92 @@ void f/*[0*/() {
584671 /*1]*/};
585672}/*0]*/
586673
674+ // Content after
675+ ''' ;
676+
677+ await _computeRegions (content);
678+ expectRegions ({0 : FoldingKind .FUNCTION_BODY , 1 : FoldingKind .LITERAL });
679+ }
680+
681+ Future <void > test_literal_map_insideNullAwareKey () async {
682+ var content = '''
683+ // Content before
684+
685+ void f/*[0*/() {
686+ final Map<Map<String, int>, false> things = <Map<String, int>, false>{/*[1*/
687+ ?<String, int>{/*[2*/
688+ "one": 1,
689+ "two": 2
690+ /*2]*/}: true
691+ /*1]*/};
692+ }/*0]*/
693+
694+ // Content after
695+ ''' ;
696+
697+ await _computeRegions (content);
698+ expectRegions ({
699+ 0 : FoldingKind .FUNCTION_BODY ,
700+ 1 : FoldingKind .LITERAL ,
701+ 2 : FoldingKind .LITERAL
702+ });
703+ }
704+
705+ Future <void > test_literal_map_insideNullAwareValue () async {
706+ var content = '''
707+ // Content before
708+
709+ void f/*[0*/() {
710+ final Map<Symbol, Map<String, int>> things = <Symbol, Map<String, int>>{/*[1*/
711+ #key: ?<String, int>{/*[2*/
712+ "one": 1,
713+ "two": 2
714+ /*2]*/}
715+ /*1]*/};
716+ }/*0]*/
717+
718+ // Content after
719+ ''' ;
720+
721+ await _computeRegions (content);
722+ expectRegions ({
723+ 0 : FoldingKind .FUNCTION_BODY ,
724+ 1 : FoldingKind .LITERAL ,
725+ 2 : FoldingKind .LITERAL
726+ });
727+ }
728+
729+ Future <void > test_literal_map_withNullAwareKey () async {
730+ var content = '''
731+ // Content before
732+
733+ void f/*[0*/() {
734+ final Map<String, int> things = <String, int>{/*[1*/
735+ "one": 1,
736+ ?null: 0,
737+ "two": 2
738+ /*1]*/};
739+ }/*0]*/
740+
741+ // Content after
742+ ''' ;
743+
744+ await _computeRegions (content);
745+ expectRegions ({0 : FoldingKind .FUNCTION_BODY , 1 : FoldingKind .LITERAL });
746+ }
747+
748+ Future <void > test_literal_map_withNullAwareValue () async {
749+ var content = '''
750+ // Content before
751+
752+ void f/*[0*/() {
753+ final Map<String, int> things = <String, int>{/*[1*/
754+ "one": 1,
755+ "null": ?null,
756+ "two": 2
757+ /*1]*/};
758+ }/*0]*/
759+
587760// Content after
588761''' ;
589762
@@ -618,6 +791,97 @@ void f/*[0*/() {
618791 });
619792 }
620793
794+ Future <void > test_literal_set_insideNullAwareElement () async {
795+ var content = '''
796+ // Content before
797+
798+ void f/*[0*/() {
799+ final Set<Set<String>> things = <Set<String>>{/*[1*/
800+ ?<String>{/*[2*/
801+ "one",
802+ "two"
803+ /*2]*/}
804+ /*1]*/};
805+ }/*0]*/
806+
807+ // Content after
808+ ''' ;
809+
810+ await _computeRegions (content);
811+ expectRegions ({
812+ 0 : FoldingKind .FUNCTION_BODY ,
813+ 1 : FoldingKind .LITERAL ,
814+ 2 : FoldingKind .LITERAL
815+ });
816+ }
817+
818+ Future <void > test_literal_set_insideNullAwareKey () async {
819+ var content = '''
820+ // Content before
821+
822+ void f/*[0*/() {
823+ final Map<Set<String>, bool> things = <Set<String>, bool>{/*[1*/
824+ ?<String>{/*[2*/
825+ "one",
826+ "two"
827+ /*2]*/}: true
828+ /*1]*/};
829+ }/*0]*/
830+
831+ // Content after
832+ ''' ;
833+
834+ await _computeRegions (content);
835+ expectRegions ({
836+ 0 : FoldingKind .FUNCTION_BODY ,
837+ 1 : FoldingKind .LITERAL ,
838+ 2 : FoldingKind .LITERAL
839+ });
840+ }
841+
842+ Future <void > test_literal_set_insideNullAwareValue () async {
843+ var content = '''
844+ // Content before
845+
846+ void f/*[0*/() {
847+ final Map<Symbol, Set<String>> things = <Symbol, Set<String>>{/*[1*/
848+ #key: ?<String>{/*[2*/
849+ "one",
850+ "two"
851+ /*2]*/}
852+ /*1]*/};
853+ }/*0]*/
854+
855+ // Content after
856+ ''' ;
857+
858+ await _computeRegions (content);
859+ expectRegions ({
860+ 0 : FoldingKind .FUNCTION_BODY ,
861+ 1 : FoldingKind .LITERAL ,
862+ 2 : FoldingKind .LITERAL
863+ });
864+ }
865+
866+ Future <void > test_literal_set_withNullAwareElement () async {
867+ var content = '''
868+ // Content before
869+
870+ void f/*[0*/() {
871+ final Set<String> things = <String>{/*[1*/
872+ "one",
873+ ?null
874+ "two"
875+ /*1]*/};
876+ }/*0]*/
877+
878+ // Content after
879+ ''' ;
880+
881+ await _computeRegions (content);
882+ expectRegions ({0 : FoldingKind .FUNCTION_BODY , 1 : FoldingKind .LITERAL });
883+ }
884+
621885 Future <void > test_mixin () async {
622886 var content = '''
623887// Content before
0 commit comments