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

Side by Side Diff: tools/testing/dart/utils.dart

Issue 21001003: test.py: First step towards support of caching dart2js compilations across runtimes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 utils; 5 library utils;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:utf' as utf; 9 import 'dart:utf' as utf;
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (_sink != null) { 57 if (_sink != null) {
58 _sink.writeln(msg); 58 _sink.writeln(msg);
59 } else { 59 } else {
60 print(msg); 60 print(msg);
61 } 61 }
62 } 62 }
63 63
64 static String get _datetime => "${new DateTime.now()}"; 64 static String get _datetime => "${new DateTime.now()}";
65 } 65 }
66 66
67
68 /**
69 * [areByteArraysEqual] compares a range of bytes from [buffer1] with a
70 * range of bytes from [buffer2].
71 *
72 * Returns [true] if the [count] bytes in [buffer1] (starting at
73 * [offset1]) match the [count] bytes in [buffer2] (starting at
74 * [offset2]).
75 * Otherwise [false] is returned.
76 */
77 bool areByteArraysEqual(List<int> buffer1, int offset1,
78 List<int> buffer2, int offset2,
79 int count) {
80 if ((offset1 + count) > buffer1.length ||
81 (offset2 + count) > buffer2.length) {
82 return false;
83 }
84
85 for (var i = 0; i < count; i++) {
86 if (buffer1[offset1 + i] != buffer2[offset2 + i]) {
87 return false;
88 }
89 }
90 return true;
91 }
92
93 /**
94 * [findBytes] searches for [pattern] in [data] beginning at [startPos].
95 *
96 * Returns [true] if [pattern] was found in [data].
97 * Otherwise [false] is returned.
98 */
99 int findBytes(List<int> data, List<int> pattern, [int startPos=0]) {
100 // TODO(kustermann): Use one of the fast string-matching algorithms!
101 for (int i=startPos; i < (data.length-pattern.length); i++) {
ricow1 2013/07/30 09:30:11 space around = I would remove parenthesis around d
kustermann 2013/07/31 15:53:54 Done. Kept the parenthesis (it's not that obvious
ricow1 2013/08/01 13:26:21 OH, as discussed offline I though length-pattern w
102 bool found = true;
103 for (int j=0; j<pattern.length; j++) {
ricow1 2013/07/30 09:30:11 space around = and <
kustermann 2013/07/31 15:53:54 Done.
104 if (data[i+j] != pattern[j]) {
105 found = false;
ricow1 2013/07/30 09:30:11 break here?
kustermann 2013/07/31 15:53:54 Done.
106 }
107 }
108 if (found) {
109 return i;
110 }
111 }
112 return -1;
113 }
114
67 List<int> encodeUtf8(String string) { 115 List<int> encodeUtf8(String string) {
68 return utf.encodeUtf8(string); 116 return utf.encodeUtf8(string);
69 } 117 }
70 118
71 // TODO(kustermann,ricow): As soon we have a debug log we should log 119 // TODO(kustermann,ricow): As soon we have a debug log we should log
72 // invalid utf8-encoded input to the log. 120 // invalid utf8-encoded input to the log.
73 // Currently invalid bytes will be replaced by a replacement character. 121 // Currently invalid bytes will be replaced by a replacement character.
74 String decodeUtf8(List<int> bytes) { 122 String decodeUtf8(List<int> bytes) {
75 return utf.decodeUtf8(bytes); 123 return utf.decodeUtf8(bytes);
76 } 124 }
77 125
78 // This function is pretty stupid and only puts quotes around an argument if 126 // This function is pretty stupid and only puts quotes around an argument if
79 // it the argument contains a space. 127 // it the argument contains a space.
80 String escapeCommandLineArgument(String argument) { 128 String escapeCommandLineArgument(String argument) {
81 if (argument.contains(' ')) { 129 if (argument.contains(' ')) {
82 return '"$argument"'; 130 return '"$argument"';
83 } 131 }
84 return argument; 132 return argument;
85 } 133 }
86 134
135 class HashCodeBuilder {
136 int _value = 0;
137
138 void add(Object object) {
139 _value = ((_value * 31) ^ object.hashCode) & 0x3FFFFFFF;
140 }
141
142 int get value => _value;
143 }
144
145 class UniqueObject {
146 static int _nextId = 1;
147 final int _hashCode;
148
149 int get hashCode => _hashCode;
150 operator==(other) => other is UniqueObject && _hashCode == other._hashCode;
151
152 UniqueObject() : _hashCode = ++_nextId;
153 }
OLDNEW
« tools/testing/dart/test_suite.dart ('K') | « tools/testing/dart/test_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698