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: packages/matcher/test/test_utils.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « packages/matcher/test/string_matchers_test.dart ('k') | packages/observe/.gitignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 library matcher.test_utils;
6
7 import 'dart:collection';
8
9 import 'package:test/test.dart';
10
11 void shouldFail(value, Matcher matcher, expected) {
12 var failed = false;
13 try {
14 expect(value, matcher);
15 } on TestFailure catch (err) {
16 failed = true;
17
18 var _errorString = err.message;
19
20 if (expected is String) {
21 expect(_errorString, equalsIgnoringWhitespace(expected));
22 } else {
23 expect(_errorString.replaceAll('\n', ''), expected);
24 }
25 }
26
27 expect(failed, isTrue, reason: 'Expected to fail.');
28 }
29
30 void shouldPass(value, Matcher matcher) {
31 expect(value, matcher);
32 }
33
34 doesNotThrow() {}
35 doesThrow() {
36 throw 'X';
37 }
38
39 class Widget {
40 int price;
41 }
42
43 class HasPrice extends CustomMatcher {
44 HasPrice(matcher) : super("Widget with a price that is", "price", matcher);
45 featureValueOf(actual) => actual.price;
46 }
47
48 class SimpleIterable extends IterableBase<int> {
49 final int count;
50
51 SimpleIterable(this.count);
52
53 bool contains(int val) => count < val ? false : true;
54
55 bool any(bool f(element)) {
56 for (var i = 0; i <= count; i++) {
57 if (f(i)) return true;
58 }
59 return false;
60 }
61
62 String toString() => "<[$count]>";
63
64 Iterator get iterator {
65 return new _SimpleIterator(count);
66 }
67 }
68
69 class _SimpleIterator implements Iterator<int> {
70 int _count;
71 int _current;
72
73 _SimpleIterator(this._count);
74
75 bool moveNext() {
76 if (_count > 0) {
77 _current = _count;
78 _count--;
79 return true;
80 }
81 _current = null;
82 return false;
83 }
84
85 int get current => _current;
86 }
OLDNEW
« no previous file with comments | « packages/matcher/test/string_matchers_test.dart ('k') | packages/observe/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698