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: pkg/smoke/lib/src/common.dart

Issue 180273004: Fixes in smoke, which in turn should fix todomvc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « pkg/smoke/lib/smoke.dart ('k') | pkg/smoke/lib/static.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// Some common utilities used by other libraries in this package. 5 /// Some common utilities used by other libraries in this package.
6 library smoke.src.common; 6 library smoke.src.common;
7 7
8 import 'package:smoke/smoke.dart' as smoke show isSubclassOf;
9
8 /// Returns [input] adjusted to be within [min] and [max] length. Truncating it 10 /// Returns [input] adjusted to be within [min] and [max] length. Truncating it
9 /// if it's longer, or padding it with nulls if it's shorter. The returned list 11 /// if it's longer, or padding it with nulls if it's shorter. The returned list
10 /// is a new copy if any modification is needed, otherwise [input] is returned. 12 /// is a new copy if any modification is needed, otherwise [input] is returned.
11 List adjustList(List input, int min, int max) { 13 List adjustList(List input, int min, int max) {
12 if (input.length < min) { 14 if (input.length < min) {
13 return new List(min)..setRange(0, input.length, input); 15 return new List(min)..setRange(0, input.length, input);
14 } 16 }
15 17
16 if (input.length > max) { 18 if (input.length > max) {
17 return new List(max)..setRange(0, max, input); 19 return new List(max)..setRange(0, max, input);
18 } 20 }
19 return input; 21 return input;
20 } 22 }
21 23
22 /// Returns whether [metadata] contains any annotation that is either equal to 24 /// Returns whether [metadata] contains any annotation that is either equal to
23 /// an annotation in [queryAnnotations] or whose type is listed in 25 /// an annotation in [queryAnnotations] or whose type is listed in
24 /// [queryAnnotations]. 26 /// [queryAnnotations].
25 bool matchesAnnotation(Iterable metadata, Iterable queryAnnotations) { 27 bool matchesAnnotation(Iterable metadata, Iterable queryAnnotations) {
26 return metadata.any((m) => queryAnnotations.contains(m) || 28 for (var meta in metadata) {
27 queryAnnotations.contains(m.runtimeType)); 29 for (var queryMeta in queryAnnotations) {
30 if (meta == queryMeta) return true;
31 if (queryMeta is Type &&
32 smoke.isSubclassOf(meta.runtimeType, queryMeta)) return true;
33 }
34 }
35 return false;
28 } 36 }
29 37
30 /// Number of arguments supported by [minArgs] and [maxArgs]. 38 /// Number of arguments supported by [minArgs] and [maxArgs].
31 const SUPPORTED_ARGS = 3; 39 const SUPPORTED_ARGS = 3;
32 40
33 typedef _Func0(); 41 typedef _Func0();
34 typedef _Func1(a); 42 typedef _Func1(a);
35 typedef _Func2(a, b); 43 typedef _Func2(a, b);
36 typedef _Func3(a, b, c); 44 typedef _Func3(a, b, c);
37 45
(...skipping 24 matching lines...) Expand all
62 /// mandatory arguments, this function returns `-1`, but if the funtion takes 70 /// mandatory arguments, this function returns `-1`, but if the funtion takes
63 /// `2` mandatory arguments and 10 optional arguments, this function returns 71 /// `2` mandatory arguments and 10 optional arguments, this function returns
64 /// `3`. 72 /// `3`.
65 int maxArgs(Function f) { 73 int maxArgs(Function f) {
66 if (f is _Func3) return 3; 74 if (f is _Func3) return 3;
67 if (f is _Func2) return 2; 75 if (f is _Func2) return 2;
68 if (f is _Func1) return 1; 76 if (f is _Func1) return 1;
69 if (f is _Func0) return 0; 77 if (f is _Func0) return 0;
70 return -1; 78 return -1;
71 } 79 }
OLDNEW
« no previous file with comments | « pkg/smoke/lib/smoke.dart ('k') | pkg/smoke/lib/static.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698