Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: tests/language_strong/async_star_test.dart

Issue 2765693002: Update all tests (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library async_start_test; 5 library async_start_test;
6 6
7 import "package:unittest/unittest.dart"; 7 import "package:unittest/unittest.dart";
8 import "dart:async"; 8 import "dart:async";
9 9
10 main() { 10 main() {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 }); 141 });
142 142
143 test("labeled", () { 143 test("labeled", () {
144 f() async* { 144 f() async* {
145 label1: yield 0; 145 label1: yield 0;
146 } 146 }
147 return expectList(f(), [0]); 147 return expectList(f(), [0]);
148 }); 148 });
149 149
150 // VM issue 2238 150 // VM issue 2238
151 test("labeled 2", () { /// 01: ok 151 test("labeled 2", () { //# 01: ok
152 f() async* { /// 01: continued 152 f() async* { //# 01: continued
153 label1: label2: yield 0; /// 01: continued 153 label1: label2: yield 0; //# 01: continued
154 } /// 01: continued 154 } //# 01: continued
155 return expectList(f(), [0]); /// 01: continued 155 return expectList(f(), [0]); //# 01: continued
156 }); /// 01: continued 156 }); //# 01: continued
157 157
158 test("for-loop", () { 158 test("for-loop", () {
159 f() async* { 159 f() async* {
160 for (int i = 0; i < 3; i++) yield i; 160 for (int i = 0; i < 3; i++) yield i;
161 } 161 }
162 return expectList(f(), [0, 1, 2]); 162 return expectList(f(), [0, 1, 2]);
163 }); 163 });
164 164
165 test("for-in-loop", () { 165 test("for-in-loop", () {
166 f() async* { 166 f() async* {
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 done.complete(); 703 done.complete();
704 } 704 }
705 }, onDone: () { 705 }, onDone: () {
706 fail("Unexpected done!"); 706 fail("Unexpected done!");
707 }); 707 });
708 return done.future.whenComplete(() { 708 return done.future.whenComplete(() {
709 expect(list.length == 18 || list.length == 19, isTrue); 709 expect(list.length == 18 || list.length == 19, isTrue);
710 }); 710 });
711 }); 711 });
712 712
713 test("canceling while paused at yield", () { /// 02: ok 713 test("canceling while paused at yield", () { //# 02: ok
714 var list = []; /// 02: contin ued 714 var list = []; //# 02: contin ued
715 var sync = new Sync(); /// 02: contin ued 715 var sync = new Sync(); //# 02: contin ued
716 f() async* { /// 02: contin ued 716 f() async* { //# 02: contin ued
717 list.add("*1"); /// 02: contin ued 717 list.add("*1"); //# 02: contin ued
718 yield 1; /// 02: contin ued 718 yield 1; //# 02: contin ued
719 await sync.wait(); /// 02: contin ued 719 await sync.wait(); //# 02: contin ued
720 sync.release(); /// 02: contin ued 720 sync.release(); //# 02: contin ued
721 list.add("*2"); /// 02: contin ued 721 list.add("*2"); //# 02: contin ued
722 yield 2; /// 02: contin ued 722 yield 2; //# 02: contin ued
723 list.add("*3"); /// 02: contin ued 723 list.add("*3"); //# 02: contin ued
724 }; /// 02: contin ued 724 }; //# 02: contin ued
725 var stream = f(); /// 02: contin ued 725 var stream = f(); //# 02: contin ued
726 // TODO(jmesserly): added workaround for: 726 // TODO(jmesserly): added workaround for:
727 // https://github.com/dart-lang/dev_compiler/issues/269 727 // https://github.com/dart-lang/dev_compiler/issues/269
728 var sub = stream.listen((x) => list.add(x)); /// 02: continued 728 var sub = stream.listen((x) => list.add(x)); //# 02: continued
729 return sync.wait().whenComplete(() { /// 02: contin ued 729 return sync.wait().whenComplete(() { //# 02: contin ued
730 expect(list, equals(["*1", 1])); /// 02: contin ued 730 expect(list, equals(["*1", 1])); //# 02: contin ued
731 sub.pause(); /// 02: contin ued 731 sub.pause(); //# 02: contin ued
732 return sync.wait(); /// 02: contin ued 732 return sync.wait(); //# 02: contin ued
733 }).whenComplete(() { /// 02: contin ued 733 }).whenComplete(() { //# 02: contin ued
734 expect(list, equals(["*1", 1, "*2"])); /// 02: contin ued 734 expect(list, equals(["*1", 1, "*2"])); //# 02: contin ued
735 sub.cancel(); /// 02: contin ued 735 sub.cancel(); //# 02: contin ued
736 return new Future.delayed(MS * 200, () { /// 02: contin ued 736 return new Future.delayed(MS * 200, () { //# 02: contin ued
737 // Should not have yielded 2 or added *3 while paused. /// 02: contin ued 737 // Should not have yielded 2 or added *3 while paused. //# 02: contin ued
738 expect(list, equals(["*1", 1, "*2"])); /// 02: contin ued 738 expect(list, equals(["*1", 1, "*2"])); //# 02: contin ued
739 }); /// 02: contin ued 739 }); //# 02: contin ued
740 }); /// 02: contin ued 740 }); //# 02: contin ued
741 }); /// 02: contin ued 741 }); //# 02: contin ued
742 }); 742 });
743 743
744 group("await for", () { 744 group("await for", () {
745 mkStream(int n) async* { 745 mkStream(int n) async* {
746 for (int i = 0; i < n; i++) yield i; 746 for (int i = 0; i < n; i++) yield i;
747 } 747 }
748 748
749 test("simple stream", () { 749 test("simple stream", () {
750 f(s) async { 750 f(s) async {
751 var r = 0; 751 var r = 0;
752 await for(var v in s) r += v; 752 await for(var v in s) r += v;
753 return r; 753 return r;
754 } 754 }
755 return f(mkStream(5)).then((v) { 755 return f(mkStream(5)).then((v) {
756 expect(v, equals(10)); 756 expect(v, equals(10));
757 }); 757 });
758 }); 758 });
759 759
760 test("simple stream, await", () { 760 test("simple stream, await", () {
761 f(s) async { 761 f(s) async {
762 var r = 0; 762 var r = 0;
763 await for(var v in s) r += await new Future.microtask(() => v); 763 await for(var v in s) r += await new Future.microtask(() => v);
764 return r; 764 return r;
765 } 765 }
766 return f(mkStream(5)).then((v) { 766 return f(mkStream(5)).then((v) {
767 expect(v, equals(10)); 767 expect(v, equals(10));
768 }); 768 });
769 }); 769 });
770 770
771 test("simple stream - take", () { /// 03: ok 771 test("simple stream - take", () { //# 03: ok
772 f(s) async { /// 03: continued 772 f(s) async { //# 03: continued
773 var r = 0; /// 03: continued 773 var r = 0; //# 03: continued
774 await for(var v in s.take(5)) r += v; /// 03: continued 774 await for(var v in s.take(5)) r += v; //# 03: continued
775 return r; /// 03: continued 775 return r; //# 03: continued
776 } /// 03: continued 776 } //# 03: continued
777 return f(mkStream(10)).then((v) { /// 03: continued 777 return f(mkStream(10)).then((v) { //# 03: continued
778 expect(v, equals(10)); /// 03: continued 778 expect(v, equals(10)); //# 03: continued
779 }); /// 03: continued 779 }); //# 03: continued
780 }); /// 03: continued 780 }); //# 03: continued
781 781
782 test("simple stream reyield", () { 782 test("simple stream reyield", () {
783 f(s) async* { 783 f(s) async* {
784 var r = 0; 784 var r = 0;
785 await for(var v in s) yield r += v; 785 await for(var v in s) yield r += v;
786 } 786 }
787 return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]); 787 return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]);
788 }); 788 });
789 789
790 test("simple stream, await, reyield", () { 790 test("simple stream, await, reyield", () {
791 f(s) async* { 791 f(s) async* {
792 var r = 0; 792 var r = 0;
793 await for(var v in s) yield r += await new Future.microtask(() => v); 793 await for(var v in s) yield r += await new Future.microtask(() => v);
794 } 794 }
795 return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]); 795 return expectList(f(mkStream(5)), [0, 1, 3, 6, 10]);
796 }); 796 });
797 797
798 test("simple stream - take, reyield", () { /// 04: ok 798 test("simple stream - take, reyield", () { //# 04: ok
799 f(s) async* { /// 04: continued 799 f(s) async* { //# 04: continued
800 var r = 0; /// 04: continued 800 var r = 0; //# 04: continued
801 await for(var v in s.take(5)) yield r += v; /// 04: continued 801 await for(var v in s.take(5)) yield r += v; //# 04: continued
802 } /// 04: continued 802 } //# 04: continued
803 return expectList(f(mkStream(10)), [0, 1, 3, 6, 10]); /// 04: continued 803 return expectList(f(mkStream(10)), [0, 1, 3, 6, 10]); //# 04: continued
804 }); /// 04: continued 804 }); //# 04: continued
805 805
806 test("nested", () { 806 test("nested", () {
807 f() async { 807 f() async {
808 var r = 0; 808 var r = 0;
809 await for (var i in mkStream(5)) { 809 await for (var i in mkStream(5)) {
810 await for (var j in mkStream(3)) { 810 await for (var j in mkStream(3)) {
811 r += i * j; 811 r += i * j;
812 } 812 }
813 } 813 }
814 return r; 814 return r;
(...skipping 27 matching lines...) Expand all
842 r += await new Future.microtask(() => ai * j); 842 r += await new Future.microtask(() => ai * j);
843 } 843 }
844 } 844 }
845 return r; 845 return r;
846 } 846 }
847 return f().then((v) { 847 return f().then((v) {
848 expect(v, equals((1 + 2 + 3 + 4) * (1 + 2))); 848 expect(v, equals((1 + 2 + 3 + 4) * (1 + 2)));
849 }); 849 });
850 }); 850 });
851 851
852 test("await pauses loop", () { /// 05: ok 852 test("await pauses loop", () { //# 05: ok
853 var sc; /// 05: con tinued 853 var sc; //# 05: con tinued
854 var i = 0; /// 05: con tinued 854 var i = 0; //# 05: con tinued
855 void send() { /// 05: con tinued 855 void send() { //# 05: con tinued
856 if (i == 5) { /// 05: con tinued 856 if (i == 5) { //# 05: con tinued
857 sc.close(); /// 05: con tinued 857 sc.close(); //# 05: con tinued
858 } else { /// 05: con tinued 858 } else { //# 05: con tinued
859 sc.add(i++); /// 05: con tinued 859 sc.add(i++); //# 05: con tinued
860 } /// 05: con tinued 860 } //# 05: con tinued
861 } /// 05: con tinued 861 } //# 05: con tinued
862 sc = new StreamController(onListen: send, onResume: send); /// 05: con tinued 862 sc = new StreamController(onListen: send, onResume: send); //# 05: con tinued
863 f(s) async { /// 05: con tinued 863 f(s) async { //# 05: con tinued
864 var r = 0; /// 05: con tinued 864 var r = 0; //# 05: con tinued
865 await for (var i in s) { /// 05: con tinued 865 await for (var i in s) { //# 05: con tinued
866 r += await new Future.delayed(MS * 10, () => i); /// 05: con tinued 866 r += await new Future.delayed(MS * 10, () => i); //# 05: con tinued
867 } /// 05: con tinued 867 } //# 05: con tinued
868 return r; /// 05: con tinued 868 return r; //# 05: con tinued
869 } /// 05: con tinued 869 } //# 05: con tinued
870 return f(sc.stream).then((v) { /// 05: con tinued 870 return f(sc.stream).then((v) { //# 05: con tinued
871 expect(v, equals(10)); /// 05: con tinued 871 expect(v, equals(10)); //# 05: con tinued
872 }); /// 05: con tinued 872 }); //# 05: con tinued
873 }); /// 05: con tinued 873 }); //# 05: con tinued
874 }); 874 });
875 } 875 }
876 876
877 // Obscuring identity function. 877 // Obscuring identity function.
878 id(x) { 878 id(x) {
879 try { 879 try {
880 if (x != null) throw x; 880 if (x != null) throw x;
881 } catch (e) { 881 } catch (e) {
882 return e; 882 return e;
883 } 883 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 921 }
922 922
923 // Release whoever is currently waiting. 923 // Release whoever is currently waiting.
924 void release([v]) { 924 void release([v]) {
925 if (_completer != null) { 925 if (_completer != null) {
926 _completer.complete(v); 926 _completer.complete(v);
927 _completer = null; 927 _completer = null;
928 } 928 }
929 } 929 }
930 } 930 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698