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

Side by Side Diff: test/matchers_minified_test.dart

Issue 840133003: matcher: fixed status file, formatting, tweaks to readme (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: nits Created 5 years, 11 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 | « test/iterable_matchers_test.dart ('k') | test/matchers_unminified_test.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) 2012, the Dart project authors. Please see the AUTHORS file 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 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 // This file is for matcher tests that rely on the names of various Dart types. 5 // This file is for matcher tests that rely on the names of various Dart types.
6 // These tests normally fail when run in minified dart2js, since the names will 6 // These tests normally fail when run in minified dart2js, since the names will
7 // be mangled. This version of the file is modified to expect minified names. 7 // be mangled. This version of the file is modified to expect minified names.
8 8
9 library matcher.minified_test; 9 library matcher.minified_test;
10 10
11 import 'package:matcher/matcher.dart'; 11 import 'package:matcher/matcher.dart';
12 import 'package:unittest/unittest.dart' show test, group; 12 import 'package:unittest/unittest.dart' show test, group;
13 13
14 import 'test_common.dart'; 14 import 'test_common.dart';
15 import 'test_utils.dart'; 15 import 'test_utils.dart';
16 16
17 // A regexp fragment matching a minified name. 17 // A regexp fragment matching a minified name.
18 const _MINIFIED_NAME = r"[A-Za-z0-9]{1,3}"; 18 const _MINIFIED_NAME = r"[A-Za-z0-9]{1,3}";
19 19
20 void main() { 20 void main() {
21 initUtils(); 21 initUtils();
22 22
23 group('Core matchers', () { 23 group('Core matchers', () {
24 test('throwsFormatException', () { 24 test('throwsFormatException', () {
25 shouldPass(() { throw new FormatException(''); }, 25 shouldPass(() {
26 throwsFormatException); 26 throw new FormatException('');
27 shouldFail(() { throw new Exception(); }, 27 }, throwsFormatException);
28 throwsFormatException, 28 shouldFail(() {
29 matches( 29 throw new Exception();
30 r"Expected: throws FormatException +" 30 }, throwsFormatException, matches(r"Expected: throws FormatException +"
31 r"Actual: <Closure(: \(\) => dynamic)?> +" 31 r"Actual: <Closure(: \(\) => dynamic)?> +"
32 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 32 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
33 }); 33 });
34 34
35 test('throwsArgumentError', () { 35 test('throwsArgumentError', () {
36 shouldPass(() { throw new ArgumentError(''); }, 36 shouldPass(() {
37 throwsArgumentError); 37 throw new ArgumentError('');
38 shouldFail(() { throw new Exception(); }, 38 }, throwsArgumentError);
39 throwsArgumentError, 39 shouldFail(() {
40 matches( 40 throw new Exception();
41 r"Expected: throws ArgumentError +" 41 }, throwsArgumentError, matches(r"Expected: throws ArgumentError +"
42 r"Actual: <Closure(: \(\) => dynamic)?> +" 42 r"Actual: <Closure(: \(\) => dynamic)?> +"
43 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 43 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
44 }); 44 });
45 45
46 test('throwsRangeError', () { 46 test('throwsRangeError', () {
47 shouldPass(() { throw new RangeError(0); }, 47 shouldPass(() {
48 throwsRangeError); 48 throw new RangeError(0);
49 shouldFail(() { throw new Exception(); }, 49 }, throwsRangeError);
50 throwsRangeError, 50 shouldFail(() {
51 matches( 51 throw new Exception();
52 r"Expected: throws RangeError +" 52 }, throwsRangeError, matches(r"Expected: throws RangeError +"
53 r"Actual: <Closure(: \(\) => dynamic)?> +" 53 r"Actual: <Closure(: \(\) => dynamic)?> +"
54 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 54 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
55 }); 55 });
56 56
57 test('throwsNoSuchMethodError', () { 57 test('throwsNoSuchMethodError', () {
58 shouldPass(() { 58 shouldPass(() {
59 throw new NoSuchMethodError(null, const Symbol(''), null, null); 59 throw new NoSuchMethodError(null, const Symbol(''), null, null);
60 }, throwsNoSuchMethodError); 60 }, throwsNoSuchMethodError);
61 shouldFail(() { throw new Exception(); }, 61 shouldFail(() {
62 throwsNoSuchMethodError, 62 throw new Exception();
63 matches( 63 }, throwsNoSuchMethodError, matches(
64 r"Expected: throws NoSuchMethodError +" 64 r"Expected: throws NoSuchMethodError +"
65 r"Actual: <Closure(: \(\) => dynamic)?> +" 65 r"Actual: <Closure(: \(\) => dynamic)?> +"
66 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 66 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
67 }); 67 });
68 68
69 test('throwsUnimplementedError', () { 69 test('throwsUnimplementedError', () {
70 shouldPass(() { throw new UnimplementedError(''); }, 70 shouldPass(() {
71 throwsUnimplementedError); 71 throw new UnimplementedError('');
72 shouldFail(() { throw new Exception(); }, 72 }, throwsUnimplementedError);
73 throwsUnimplementedError, 73 shouldFail(() {
74 matches( 74 throw new Exception();
75 r"Expected: throws UnimplementedError +" 75 }, throwsUnimplementedError, matches(
76 r"Expected: throws UnimplementedError +"
76 r"Actual: <Closure(: \(\) => dynamic)?> +" 77 r"Actual: <Closure(: \(\) => dynamic)?> +"
77 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 78 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
78 }); 79 });
79 80
80 test('throwsUnsupportedError', () { 81 test('throwsUnsupportedError', () {
81 shouldPass(() { throw new UnsupportedError(''); }, 82 shouldPass(() {
82 throwsUnsupportedError); 83 throw new UnsupportedError('');
83 shouldFail(() { throw new Exception(); }, 84 }, throwsUnsupportedError);
84 throwsUnsupportedError, 85 shouldFail(() {
85 matches( 86 throw new Exception();
86 r"Expected: throws UnsupportedError +" 87 }, throwsUnsupportedError, matches(r"Expected: throws UnsupportedError +"
87 r"Actual: <Closure(: \(\) => dynamic)?> +" 88 r"Actual: <Closure(: \(\) => dynamic)?> +"
88 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 89 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
89 }); 90 });
90 91
91 test('throwsStateError', () { 92 test('throwsStateError', () {
92 shouldPass(() { throw new StateError(''); }, 93 shouldPass(() {
93 throwsStateError); 94 throw new StateError('');
94 shouldFail(() { throw new Exception(); }, 95 }, throwsStateError);
95 throwsStateError, 96 shouldFail(() {
96 matches( 97 throw new Exception();
97 r"Expected: throws StateError +" 98 }, throwsStateError, matches(r"Expected: throws StateError +"
98 r"Actual: <Closure(: \(\) => dynamic)?> +" 99 r"Actual: <Closure(: \(\) => dynamic)?> +"
99 r"Which: threw " + _MINIFIED_NAME + r":<Exception>")); 100 r"Which: threw " + _MINIFIED_NAME + r":<Exception>"));
100 }); 101 });
101 }); 102 });
102 103
103 group('Iterable Matchers', () { 104 group('Iterable Matchers', () {
104 test('isEmpty', () { 105 test('isEmpty', () {
105 var d = new SimpleIterable(0); 106 var d = new SimpleIterable(0);
106 var e = new SimpleIterable(1); 107 var e = new SimpleIterable(1);
107 shouldPass(d, isEmpty); 108 shouldPass(d, isEmpty);
108 shouldFail(e, isEmpty, 109 shouldFail(e, isEmpty,
109 matches(r"Expected: empty +Actual: " + _MINIFIED_NAME + r":\[1\]")); 110 matches(r"Expected: empty +Actual: " + _MINIFIED_NAME + r":\[1\]"));
110 }); 111 });
111 112
112 test('isNotEmpty', () { 113 test('isNotEmpty', () {
113 var d = new SimpleIterable(0); 114 var d = new SimpleIterable(0);
114 var e = new SimpleIterable(1); 115 var e = new SimpleIterable(1);
115 shouldPass(e, isNotEmpty); 116 shouldPass(e, isNotEmpty);
116 shouldFail(d, isNotEmpty, 117 shouldFail(d, isNotEmpty, matches(
117 matches(r"Expected: non-empty +Actual: " + _MINIFIED_NAME + r":\[\]")) ; 118 r"Expected: non-empty +Actual: " + _MINIFIED_NAME + r":\[\]"));
118 }); 119 });
119 120
120 test('contains', () { 121 test('contains', () {
121 var d = new SimpleIterable(3); 122 var d = new SimpleIterable(3);
122 shouldPass(d, contains(2)); 123 shouldPass(d, contains(2));
123 shouldFail(d, contains(5), 124 shouldFail(d, contains(5), matches(r"Expected: contains <5> +"
124 matches( 125 r"Actual: " + _MINIFIED_NAME + r":\[3, 2, 1\]"));
125 r"Expected: contains <5> +"
126 r"Actual: " + _MINIFIED_NAME + r":\[3, 2, 1\]"));
127 }); 126 });
128 }); 127 });
129 128
130 group('Feature Matchers', () { 129 group('Feature Matchers', () {
131 test("Feature Matcher", () { 130 test("Feature Matcher", () {
132 var w = new Widget(); 131 var w = new Widget();
133 w.price = 10; 132 w.price = 10;
134 shouldPass(w, new HasPrice(10)); 133 shouldPass(w, new HasPrice(10));
135 shouldPass(w, new HasPrice(greaterThan(0))); 134 shouldPass(w, new HasPrice(greaterThan(0)));
136 shouldFail(w, new HasPrice(greaterThan(10)), 135 shouldFail(w, new HasPrice(greaterThan(10)), matches(
137 matches( 136 r"Expected: Widget with a price that is a value greater than "
138 r"Expected: Widget with a price that is a value greater than " 137 r"<10> +"
139 r"<10> +"
140 r"Actual: <Instance of '" + _MINIFIED_NAME + r"'> +" 138 r"Actual: <Instance of '" + _MINIFIED_NAME + r"'> +"
141 r"Which: has price with value <10> which is not " 139 r"Which: has price with value <10> which is not "
142 r"a value greater than <10>")); 140 r"a value greater than <10>"));
143 }); 141 });
144 }); 142 });
145 } 143 }
OLDNEW
« no previous file with comments | « test/iterable_matchers_test.dart ('k') | test/matchers_unminified_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698