Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
|
Brian Wilkerson
2016/01/10 16:45:26
2016
Paul Berry
2016/01/10 22:15:17
Done.
| |
| 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 import 'package:analyzer/src/summary/format.dart'; | |
| 6 import 'package:analyzer/src/summary/prelink.dart'; | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 | |
| 9 import '../../reflective_tests.dart'; | |
| 10 | |
| 11 main() { | |
| 12 groupSep = ' | '; | |
| 13 runReflectiveTests(NameFilterTest); | |
| 14 } | |
| 15 | |
| 16 class MockUnlinkedCombinator implements UnlinkedCombinator { | |
| 17 @override | |
| 18 final List<String> hides; | |
| 19 | |
| 20 @override | |
| 21 final List<String> shows; | |
| 22 | |
| 23 MockUnlinkedCombinator( | |
| 24 {this.hides: const <String>[], this.shows: const <String>[]}); | |
| 25 | |
| 26 @override | |
| 27 Map<String, Object> toMap() { | |
| 28 fail('toMap() called unexpectedly'); | |
| 29 return null; | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 @reflectiveTest | |
| 34 class NameFilterTest { | |
| 35 test_forCombinator_hide() { | |
| 36 NameFilter filter = new NameFilter.forCombinator( | |
| 37 new MockUnlinkedCombinator(hides: ['foo', 'bar'])); | |
| 38 expect(filter.accepts('foo'), isFalse); | |
| 39 expect(filter.accepts('bar'), isFalse); | |
| 40 expect(filter.accepts('baz'), isTrue); | |
| 41 expect(filter.shownNames, isNull); | |
| 42 expect(filter.hiddenNames, isNotNull); | |
| 43 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 44 } | |
| 45 | |
| 46 test_forCombinator_show() { | |
| 47 NameFilter filter = new NameFilter.forCombinator( | |
| 48 new MockUnlinkedCombinator(shows: ['foo', 'bar'])); | |
| 49 expect(filter.accepts('foo'), isTrue); | |
| 50 expect(filter.accepts('bar'), isTrue); | |
| 51 expect(filter.accepts('baz'), isFalse); | |
| 52 expect(filter.hiddenNames, isNull); | |
| 53 expect(filter.shownNames, isNotNull); | |
| 54 expect(filter.shownNames, ['foo', 'bar'].toSet()); | |
| 55 } | |
| 56 | |
| 57 test_forCombinators() { | |
| 58 NameFilter filter = new NameFilter.forCombinators([ | |
| 59 new MockUnlinkedCombinator(hides: ['foo']), | |
| 60 new MockUnlinkedCombinator(hides: ['bar']) | |
| 61 ]); | |
| 62 expect(filter.accepts('foo'), isFalse); | |
| 63 expect(filter.accepts('bar'), isFalse); | |
| 64 expect(filter.accepts('baz'), isTrue); | |
| 65 expect(filter.shownNames, isNull); | |
| 66 expect(filter.hiddenNames, isNotNull); | |
| 67 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 68 } | |
| 69 | |
| 70 test_identity() { | |
| 71 expect(NameFilter.identity.accepts('foo'), isTrue); | |
| 72 expect(NameFilter.identity.hiddenNames, isNotNull); | |
| 73 expect(NameFilter.identity.hiddenNames, isEmpty); | |
| 74 expect(NameFilter.identity.shownNames, isNull); | |
| 75 } | |
| 76 | |
| 77 test_merge_hides_hides() { | |
| 78 NameFilter filter = | |
| 79 new NameFilter.forCombinator(new MockUnlinkedCombinator(hides: ['foo'])) | |
| 80 .merge(new NameFilter.forCombinator( | |
| 81 new MockUnlinkedCombinator(hides: ['bar']))); | |
| 82 expect(filter.accepts('foo'), isFalse); | |
| 83 expect(filter.accepts('bar'), isFalse); | |
| 84 expect(filter.accepts('baz'), isTrue); | |
| 85 expect(filter.shownNames, isNull); | |
| 86 expect(filter.hiddenNames, isNotNull); | |
| 87 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 88 } | |
| 89 | |
| 90 test_merge_hides_identity() { | |
| 91 NameFilter filter = new NameFilter.forCombinator( | |
| 92 new MockUnlinkedCombinator(hides: ['foo', 'bar'])) | |
| 93 .merge(NameFilter.identity); | |
| 94 expect(filter.accepts('foo'), isFalse); | |
| 95 expect(filter.accepts('bar'), isFalse); | |
| 96 expect(filter.accepts('baz'), isTrue); | |
| 97 expect(filter.shownNames, isNull); | |
| 98 expect(filter.hiddenNames, isNotNull); | |
| 99 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 100 } | |
| 101 | |
| 102 test_merge_hides_shows() { | |
| 103 NameFilter filter = new NameFilter.forCombinator( | |
| 104 new MockUnlinkedCombinator(hides: ['bar', 'baz'])).merge( | |
| 105 new NameFilter.forCombinator( | |
| 106 new MockUnlinkedCombinator(shows: ['foo', 'bar']))); | |
| 107 expect(filter.accepts('foo'), isTrue); | |
| 108 expect(filter.accepts('bar'), isFalse); | |
| 109 expect(filter.accepts('baz'), isFalse); | |
| 110 expect(filter.hiddenNames, isNull); | |
| 111 expect(filter.shownNames, isNotNull); | |
| 112 expect(filter.shownNames, ['foo'].toSet()); | |
| 113 } | |
| 114 | |
| 115 test_merge_identity_hides() { | |
| 116 NameFilter filter = NameFilter.identity.merge(new NameFilter.forCombinator( | |
| 117 new MockUnlinkedCombinator(hides: ['foo', 'bar']))); | |
| 118 expect(filter.accepts('foo'), isFalse); | |
| 119 expect(filter.accepts('bar'), isFalse); | |
| 120 expect(filter.accepts('baz'), isTrue); | |
| 121 expect(filter.shownNames, isNull); | |
| 122 expect(filter.hiddenNames, isNotNull); | |
| 123 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 124 } | |
| 125 | |
| 126 test_merge_identity_identity() { | |
| 127 NameFilter filter = NameFilter.identity.merge(NameFilter.identity); | |
| 128 expect(filter.accepts('foo'), isTrue); | |
| 129 expect(filter.hiddenNames, isNotNull); | |
| 130 expect(filter.hiddenNames, isEmpty); | |
| 131 expect(filter.shownNames, isNull); | |
| 132 } | |
| 133 | |
| 134 test_merge_identity_shows() { | |
| 135 NameFilter filter = NameFilter.identity.merge(new NameFilter.forCombinator( | |
| 136 new MockUnlinkedCombinator(shows: ['foo', 'bar']))); | |
| 137 expect(filter.accepts('foo'), isTrue); | |
| 138 expect(filter.accepts('bar'), isTrue); | |
| 139 expect(filter.accepts('baz'), isFalse); | |
| 140 expect(filter.hiddenNames, isNull); | |
| 141 expect(filter.shownNames, isNotNull); | |
| 142 expect(filter.shownNames, ['foo', 'bar'].toSet()); | |
| 143 } | |
| 144 | |
| 145 test_merge_shows_hides() { | |
| 146 NameFilter filter = new NameFilter.forCombinator( | |
| 147 new MockUnlinkedCombinator(shows: ['foo', 'bar'])).merge( | |
| 148 new NameFilter.forCombinator( | |
| 149 new MockUnlinkedCombinator(hides: ['bar', 'baz']))); | |
| 150 expect(filter.accepts('foo'), isTrue); | |
| 151 expect(filter.accepts('bar'), isFalse); | |
| 152 expect(filter.accepts('baz'), isFalse); | |
| 153 expect(filter.hiddenNames, isNull); | |
| 154 expect(filter.shownNames, isNotNull); | |
| 155 expect(filter.shownNames, ['foo'].toSet()); | |
| 156 } | |
| 157 | |
| 158 test_merge_shows_identity() { | |
| 159 NameFilter filter = new NameFilter.forCombinator( | |
| 160 new MockUnlinkedCombinator(shows: ['foo', 'bar'])) | |
| 161 .merge(NameFilter.identity); | |
| 162 expect(filter.accepts('foo'), isTrue); | |
| 163 expect(filter.accepts('bar'), isTrue); | |
| 164 expect(filter.accepts('baz'), isFalse); | |
| 165 expect(filter.hiddenNames, isNull); | |
| 166 expect(filter.shownNames, isNotNull); | |
| 167 expect(filter.shownNames, ['foo', 'bar'].toSet()); | |
| 168 } | |
| 169 | |
| 170 test_merge_shows_shows() { | |
| 171 NameFilter filter = new NameFilter.forCombinator( | |
| 172 new MockUnlinkedCombinator(shows: ['foo', 'bar'])).merge( | |
| 173 new NameFilter.forCombinator( | |
| 174 new MockUnlinkedCombinator(shows: ['bar', 'baz']))); | |
| 175 expect(filter.accepts('foo'), isFalse); | |
| 176 expect(filter.accepts('bar'), isTrue); | |
| 177 expect(filter.accepts('baz'), isFalse); | |
| 178 expect(filter.hiddenNames, isNull); | |
| 179 expect(filter.shownNames, isNotNull); | |
| 180 expect(filter.shownNames, ['bar'].toSet()); | |
| 181 } | |
| 182 | |
| 183 test_merge_shows_shows_emptyResult() { | |
| 184 NameFilter filter = | |
| 185 new NameFilter.forCombinator(new MockUnlinkedCombinator(shows: ['foo'])) | |
| 186 .merge(new NameFilter.forCombinator( | |
| 187 new MockUnlinkedCombinator(shows: ['bar']))); | |
| 188 expect(filter.accepts('foo'), isFalse); | |
| 189 expect(filter.accepts('bar'), isFalse); | |
| 190 expect(filter.accepts('baz'), isFalse); | |
| 191 expect(filter.hiddenNames, isNull); | |
| 192 expect(filter.shownNames, isNotNull); | |
| 193 expect(filter.shownNames, isEmpty); | |
| 194 } | |
| 195 } | |
| OLD | NEW |