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

Side by Side Diff: dart/tests/try/web/program_result.dart

Issue 799403005: Avoid repeating common parts of ProgramResults. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
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 library trydart.test.program_result; 5 library trydart.test.program_result;
6 6
7 import '../poi/source_update.dart';
8
7 class ProgramResult { 9 class ProgramResult {
8 final String code; 10 final String code;
9 11
10 final List<String> messages; 12 final List<String> messages;
11 13
12 final bool compileUpdatesShouldThrow; 14 final bool compileUpdatesShouldThrow;
13 15
14 const ProgramResult( 16 const ProgramResult(
15 this.code, this.messages, {this.compileUpdatesShouldThrow: false}); 17 this.code, this.messages, {this.compileUpdatesShouldThrow: false});
16 18
17 List<String> messagesWith(String extra) { 19 List<String> messagesWith(String extra) {
18 return new List<String>.from(messages)..add(extra); 20 return new List<String>.from(messages)..add(extra);
19 } 21 }
22
23 static List<ProgramResult> decode(List encodedResults) {
24 if (encodedResults.length != 2) {
25 throw new ArgumentError(
26 "Unexpected encoding of program results: $encodedResults");
27 }
28 if (encodedResults[0].length == 1) {
29 throw new ArgumentError("Trivial diff, no reason to use decode.");
30 }
31 List<String> sources = expandUpdates(encodedResults[0]);
32 List<ProgramExpectation> expectations = encodedResults[1];
33 if (sources.length != expectations.length) {
34 throw new ArgumentError(
35 "Length mismatch: ${sources.length} != ${expectations.length}");
36 }
37 List<ProgramResult> result = new List<ProgramResult>(sources.length);
38 for (int i = 0; i < sources.length; i++) {
39 result[i] = expectations[i].toResult(sources[i]);
40 }
41 return result;
42 }
20 } 43 }
44
45 class ProgramExpectation {
46 final List<String> messages;
47
48 final bool compileUpdatesShouldThrow;
49
50 const ProgramExpectation(
51 this.messages, {this.compileUpdatesShouldThrow: false});
52
53 ProgramResult toResult(String code) {
54 return new ProgramResult(
55 code, messages, compileUpdatesShouldThrow: compileUpdatesShouldThrow);
56 }
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698