torture.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /// File-level doc for torture (glued to import? no — imports precede nothing).
  2. import 'dart:async';
  3. import 'package:torture/other.dart' as other show OtherClass;
  4. export 'src/reexported.dart' hide Hidden;
  5. part 'torture_part.dart';
  6. /// Doc line one.
  7. /// Doc line two.
  8. void topLevel(int count, String label) {
  9. helper(count);
  10. }
  11. /** Block dartdoc kept. */
  12. int blockDoc() => 1;
  13. // Plain comment doc.
  14. String plainDoc() => 'x';
  15. /// Broken by annotation.
  16. @deprecated
  17. void annotated() {}
  18. @Deprecated('with args')
  19. @pragma('vm:entry-point')
  20. void doubleAnno() {}
  21. const SHARED_MAX = 10;
  22. final DERIVED_VAL = SHARED_MAX + 1;
  23. const lowercase_const = 1;
  24. final typedTop = compute();
  25. var topVar = 5;
  26. int topTyped = 6;
  27. final multiA = 1, multiB = 2;
  28. int get topGetter => 7;
  29. set topSetter(int v) {}
  30. Future<String> asyncFn() async => 'a';
  31. Stream<int> genStar() async* {
  32. yield 1;
  33. }
  34. Iterable<int> syncStar() sync* {
  35. yield 2;
  36. }
  37. num numback(num n) => n;
  38. dynamic dyn(dynamic d) => d;
  39. Object obj(Object o) => o;
  40. List<WidgetT> listRet(Map<String, WidgetT> m) => [];
  41. WidgetT? nullableRet() => null;
  42. other.OtherClass prefixedRet() => other.OtherClass();
  43. T generic<T>(T v) => v;
  44. external void externalFn();
  45. void params({int? named, required WidgetT child, String note = 'x'}) {}
  46. void optionals([int pos = 0, WidgetT? w]) {}
  47. void fnTyped(void cb(int x), int Function(String) modern) {}
  48. void bodyShapes(List<int> xs, Object o) {
  49. var local = 1;
  50. int typed = 2;
  51. final con = 3;
  52. int uninit;
  53. uninit = 4;
  54. local = uninit;
  55. helper(local);
  56. obj.method(local);
  57. this_like.deep.call3(local);
  58. ConfigT.load();
  59. ConfigT.setting;
  60. w?.render();
  61. y2..add(1)..add(2);
  62. final w1 = WidgetT(1);
  63. final w2 = new WidgetT(2);
  64. pad(const EdgeInsetsT.all(8.0));
  65. FactoryT.create().run();
  66. lower().chain();
  67. WidgetT.named(3).chainTail();
  68. xs.map((e) => e * 2).toList();
  69. xs.forEach((e) => use(e));
  70. final lam = (int a) {
  71. helper(a);
  72. };
  73. lam(5);
  74. void localFn(int n) {
  75. inner(n);
  76. }
  77. localFn(6);
  78. if (o is WidgetT) {
  79. use(o);
  80. }
  81. final cast = o as WidgetT;
  82. final tl = <WidgetT>[];
  83. throw StateError('bad');
  84. }
  85. void interpolation(int count) {
  86. log('count $count and ${SHARED_MAX} via ${refresh()}');
  87. }
  88. void refTaker() {
  89. register(topLevel);
  90. obj.cb = topLevel;
  91. final table = [topLevel, blockDoc];
  92. final m = {'k': topLevel, 'x': undefinedName};
  93. reg2(cb: topLevel);
  94. forward(topLevel: topLevel);
  95. final alias = topLevel;
  96. }
  97. /// Class doc.
  98. @immutable
  99. class WidgetT extends BaseT with MixA, MixB implements DrawT {
  100. static const int K_MAX = 9;
  101. static final sharedInst = WidgetT(0);
  102. static var mutableStatic = 1;
  103. final int size;
  104. final untyped = 5;
  105. int counter = 0;
  106. late String title;
  107. WidgetT(this.size);
  108. WidgetT.named(this.size) {
  109. init();
  110. }
  111. WidgetT.bodilessNamed() : size = seed();
  112. factory WidgetT.create() => WidgetT(1);
  113. const factory WidgetT.redir() = WidgetT2;
  114. @override
  115. void render(CanvasT c) {
  116. c.draw();
  117. }
  118. static WidgetT make() => WidgetT(3);
  119. int get area => size * size;
  120. set area(int v) {
  121. counter = v;
  122. }
  123. bool get privado => _check();
  124. bool _check() => true;
  125. Future<void> load() async {
  126. await fetch();
  127. }
  128. WidgetT operator +(WidgetT o) => WidgetT(size + o.size);
  129. void useLocalNew() {
  130. final h = new HolderT(2);
  131. use(h);
  132. }
  133. void readsConst() {
  134. use(K_MAX);
  135. }
  136. }
  137. class WidgetT2 extends WidgetT {
  138. WidgetT2() : super(0);
  139. void _privateMethod() {}
  140. }
  141. class BaseT {}
  142. class DrawT {}
  143. class OnlyMix with MixA {}
  144. abstract class AbstractT {
  145. void mustImpl(WidgetT w);
  146. int get abstractGetter;
  147. }
  148. sealed class ShapeT {}
  149. class CircleT extends ShapeT {}
  150. mixin MixA on BaseT {
  151. void mixMethod() {
  152. helper(1);
  153. }
  154. }
  155. mixin MixB implements DrawT {
  156. int get mixGetter => 2;
  157. }
  158. extension WidgetTExt on WidgetT {
  159. void extMethod() {
  160. render(CanvasT());
  161. }
  162. int get extGetter => 4;
  163. }
  164. extension on String {
  165. void anonExt() {}
  166. }
  167. enum ColorT { red, green, blue }
  168. /// Enum doc.
  169. enum StatusT with MixB implements DrawT {
  170. ok(200),
  171. err(500);
  172. final int code;
  173. const StatusT(this.code);
  174. bool get good => code < 400;
  175. static StatusT parse(int c) => ok;
  176. }
  177. typedef IntFn = int Function(int);
  178. typedef void LegacyCb(int x);
  179. typedef MapAlias = Map<String, WidgetT>;
  180. extension type MetersT(double value) {
  181. double get km => value / 1000;
  182. }
  183. void patternUser(Object o) {
  184. final v = ColorT.red;
  185. switch (o) {
  186. case ColorT.blue:
  187. use(v);
  188. default:
  189. break;
  190. }
  191. final (a, b) = (1, 2);
  192. use(a);
  193. }
  194. // π unicode: “smart quotes” précède — column check ☕
  195. void afterUnicode(String seance) {
  196. emit('café ☕ done');
  197. }