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

Side by Side Diff: lib/src/backend/metadata.dart

Issue 1491383003: Disallow non-hyphenated-identifier tag names. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | lib/src/backend/platform_selector/scanner.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) 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 test.backend.metadata; 5 library test.backend.metadata;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:collection/collection.dart'; 9 import 'package:collection/collection.dart';
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 /// [testOn] defaults to [PlatformSelector.all]. 111 /// [testOn] defaults to [PlatformSelector.all].
112 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false, 112 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false,
113 this.verboseTrace: false, this.skipReason, 113 this.verboseTrace: false, this.skipReason,
114 Map<PlatformSelector, Metadata> onPlatform, Iterable<String> tags}) 114 Map<PlatformSelector, Metadata> onPlatform, Iterable<String> tags})
115 : testOn = testOn == null ? PlatformSelector.all : testOn, 115 : testOn = testOn == null ? PlatformSelector.all : testOn,
116 timeout = timeout == null ? const Timeout.factor(1) : timeout, 116 timeout = timeout == null ? const Timeout.factor(1) : timeout,
117 skip = skip, 117 skip = skip,
118 onPlatform = onPlatform == null 118 onPlatform = onPlatform == null
119 ? const {} 119 ? const {}
120 : new UnmodifiableMapView(onPlatform), 120 : new UnmodifiableMapView(onPlatform),
121 tags = tags == null ? new Set() : new UnmodifiableSetView(tags.toSet()); 121 tags = tags == null
122 ? new Set()
123 : new UnmodifiableSetView(tags.toSet()) {
124 _validateTags();
125 }
122 126
123 /// Creates a new Metadata, but with fields parsed from caller-friendly values 127 /// Creates a new Metadata, but with fields parsed from caller-friendly values
124 /// where applicable. 128 /// where applicable.
125 /// 129 ///
126 /// Throws a [FormatException] if any field is invalid. 130 /// Throws a [FormatException] if any field is invalid.
127 Metadata.parse({String testOn, Timeout timeout, skip, 131 Metadata.parse({String testOn, Timeout timeout, skip,
128 this.verboseTrace: false, Map<String, dynamic> onPlatform, 132 this.verboseTrace: false, Map<String, dynamic> onPlatform,
129 tags}) 133 tags})
130 : testOn = testOn == null 134 : testOn = testOn == null
131 ? PlatformSelector.all 135 ? PlatformSelector.all
132 : new PlatformSelector.parse(testOn), 136 : new PlatformSelector.parse(testOn),
133 timeout = timeout == null ? const Timeout.factor(1) : timeout, 137 timeout = timeout == null ? const Timeout.factor(1) : timeout,
134 skip = skip != null && skip != false, 138 skip = skip != null && skip != false,
135 skipReason = skip is String ? skip : null, 139 skipReason = skip is String ? skip : null,
136 onPlatform = _parseOnPlatform(onPlatform), 140 onPlatform = _parseOnPlatform(onPlatform),
137 tags = _parseTags(tags) { 141 tags = _parseTags(tags) {
138 if (skip != null && skip is! String && skip is! bool) { 142 if (skip != null && skip is! String && skip is! bool) {
139 throw new ArgumentError( 143 throw new ArgumentError(
140 '"skip" must be a String or a bool, was "$skip".'); 144 '"skip" must be a String or a bool, was "$skip".');
141 } 145 }
146
147 _validateTags();
142 } 148 }
143 149
144 /// Deserializes the result of [Metadata.serialize] into a new [Metadata]. 150 /// Deserializes the result of [Metadata.serialize] into a new [Metadata].
145 Metadata.deserialize(serialized) 151 Metadata.deserialize(serialized)
146 : testOn = serialized['testOn'] == null 152 : testOn = serialized['testOn'] == null
147 ? PlatformSelector.all 153 ? PlatformSelector.all
148 : new PlatformSelector.parse(serialized['testOn']), 154 : new PlatformSelector.parse(serialized['testOn']),
149 timeout = _deserializeTimeout(serialized['timeout']), 155 timeout = _deserializeTimeout(serialized['timeout']),
150 skip = serialized['skip'], 156 skip = serialized['skip'],
151 skipReason = serialized['skipReason'], 157 skipReason = serialized['skipReason'],
152 verboseTrace = serialized['verboseTrace'], 158 verboseTrace = serialized['verboseTrace'],
153 tags = new Set.from(serialized['tags']), 159 tags = new Set.from(serialized['tags']),
154 onPlatform = new Map.fromIterable(serialized['onPlatform'], 160 onPlatform = new Map.fromIterable(serialized['onPlatform'],
155 key: (pair) => new PlatformSelector.parse(pair.first), 161 key: (pair) => new PlatformSelector.parse(pair.first),
156 value: (pair) => new Metadata.deserialize(pair.last)); 162 value: (pair) => new Metadata.deserialize(pair.last));
157 163
158 /// Deserializes timeout from the format returned by [_serializeTimeout]. 164 /// Deserializes timeout from the format returned by [_serializeTimeout].
159 static _deserializeTimeout(serialized) { 165 static _deserializeTimeout(serialized) {
160 if (serialized == 'none') return Timeout.none; 166 if (serialized == 'none') return Timeout.none;
161 var scaleFactor = serialized['scaleFactor']; 167 var scaleFactor = serialized['scaleFactor'];
162 if (scaleFactor != null) return new Timeout.factor(scaleFactor); 168 if (scaleFactor != null) return new Timeout.factor(scaleFactor);
163 return new Timeout( 169 return new Timeout(
164 new Duration(microseconds: serialized['duration'])); 170 new Duration(microseconds: serialized['duration']));
165 } 171 }
166 172
173 /// Throws an [ArgumentError] if any tags in [tags] aren't hyphenated
174 /// identifiers.
175 void _validateTags() {
176 var invalidTags = tags
177 .where((tag) => !tag.contains(anchoredHyphenatedIdentifier))
178 .map((tag) => '"$tag"')
179 .toList();
180
181 if (invalidTags.isEmpty) return;
182
183 throw new ArgumentError(
184 "Invalid ${pluralize('tag', invalidTags.length)} "
185 "${toSentence(invalidTags)}. Tags must be (optionally hyphenated) "
186 "Dart identifiers.");
187 }
188
167 /// Return a new [Metadata] that merges [this] with [other]. 189 /// Return a new [Metadata] that merges [this] with [other].
168 /// 190 ///
169 /// If the two [Metadata]s have conflicting properties, [other] wins. 191 /// If the two [Metadata]s have conflicting properties, [other] wins.
170 Metadata merge(Metadata other) => 192 Metadata merge(Metadata other) =>
171 new Metadata( 193 new Metadata(
172 testOn: testOn.intersect(other.testOn), 194 testOn: testOn.intersect(other.testOn),
173 timeout: timeout.merge(other.timeout), 195 timeout: timeout.merge(other.timeout),
174 skip: skip || other.skip, 196 skip: skip || other.skip,
175 verboseTrace: verboseTrace || other.verboseTrace, 197 verboseTrace: verboseTrace || other.verboseTrace,
176 skipReason: other.skipReason == null ? skipReason : other.skipReason, 198 skipReason: other.skipReason == null ? skipReason : other.skipReason,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 _serializeTimeout(Timeout timeout) { 251 _serializeTimeout(Timeout timeout) {
230 if (timeout == Timeout.none) return 'none'; 252 if (timeout == Timeout.none) return 'none';
231 return { 253 return {
232 'duration': timeout.duration == null 254 'duration': timeout.duration == null
233 ? null 255 ? null
234 : timeout.duration.inMicroseconds, 256 : timeout.duration.inMicroseconds,
235 'scaleFactor': timeout.scaleFactor 257 'scaleFactor': timeout.scaleFactor
236 }; 258 };
237 } 259 }
238 } 260 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/backend/platform_selector/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698