| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, 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 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_accepts_accessors_hide() { | |
| 36 NameFilter filter = new NameFilter.forCombinator( | |
| 37 new MockUnlinkedCombinator(hides: ['bar'])); | |
| 38 expect(filter.accepts('foo'), isTrue); | |
| 39 expect(filter.accepts('foo='), isTrue); | |
| 40 expect(filter.accepts('bar'), isFalse); | |
| 41 expect(filter.accepts('bar='), isFalse); | |
| 42 } | |
| 43 | |
| 44 test_accepts_accessors_show() { | |
| 45 NameFilter filter = new NameFilter.forCombinator( | |
| 46 new MockUnlinkedCombinator(shows: ['foo'])); | |
| 47 expect(filter.accepts('foo'), isTrue); | |
| 48 expect(filter.accepts('foo='), isTrue); | |
| 49 expect(filter.accepts('bar'), isFalse); | |
| 50 expect(filter.accepts('bar='), isFalse); | |
| 51 } | |
| 52 | |
| 53 test_forCombinator_hide() { | |
| 54 NameFilter filter = new NameFilter.forCombinator( | |
| 55 new MockUnlinkedCombinator(hides: ['foo', 'bar'])); | |
| 56 expect(filter.accepts('foo'), isFalse); | |
| 57 expect(filter.accepts('bar'), isFalse); | |
| 58 expect(filter.accepts('baz'), isTrue); | |
| 59 expect(filter.shownNames, isNull); | |
| 60 expect(filter.hiddenNames, isNotNull); | |
| 61 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 62 } | |
| 63 | |
| 64 test_forCombinator_show() { | |
| 65 NameFilter filter = new NameFilter.forCombinator( | |
| 66 new MockUnlinkedCombinator(shows: ['foo', 'bar'])); | |
| 67 expect(filter.accepts('foo'), isTrue); | |
| 68 expect(filter.accepts('bar'), isTrue); | |
| 69 expect(filter.accepts('baz'), isFalse); | |
| 70 expect(filter.hiddenNames, isNull); | |
| 71 expect(filter.shownNames, isNotNull); | |
| 72 expect(filter.shownNames, ['foo', 'bar'].toSet()); | |
| 73 } | |
| 74 | |
| 75 test_forCombinators() { | |
| 76 NameFilter filter = new NameFilter.forCombinators([ | |
| 77 new MockUnlinkedCombinator(hides: ['foo']), | |
| 78 new MockUnlinkedCombinator(hides: ['bar']) | |
| 79 ]); | |
| 80 expect(filter.accepts('foo'), isFalse); | |
| 81 expect(filter.accepts('bar'), isFalse); | |
| 82 expect(filter.accepts('baz'), isTrue); | |
| 83 expect(filter.shownNames, isNull); | |
| 84 expect(filter.hiddenNames, isNotNull); | |
| 85 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 86 } | |
| 87 | |
| 88 test_identity() { | |
| 89 expect(NameFilter.identity.accepts('foo'), isTrue); | |
| 90 expect(NameFilter.identity.hiddenNames, isNotNull); | |
| 91 expect(NameFilter.identity.hiddenNames, isEmpty); | |
| 92 expect(NameFilter.identity.shownNames, isNull); | |
| 93 } | |
| 94 | |
| 95 test_merge_hides_hides() { | |
| 96 NameFilter filter = | |
| 97 new NameFilter.forCombinator(new MockUnlinkedCombinator(hides: ['foo'])) | |
| 98 .merge(new NameFilter.forCombinator( | |
| 99 new MockUnlinkedCombinator(hides: ['bar']))); | |
| 100 expect(filter.accepts('foo'), isFalse); | |
| 101 expect(filter.accepts('bar'), isFalse); | |
| 102 expect(filter.accepts('baz'), isTrue); | |
| 103 expect(filter.shownNames, isNull); | |
| 104 expect(filter.hiddenNames, isNotNull); | |
| 105 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 106 } | |
| 107 | |
| 108 test_merge_hides_identity() { | |
| 109 NameFilter filter = new NameFilter.forCombinator( | |
| 110 new MockUnlinkedCombinator(hides: ['foo', 'bar'])) | |
| 111 .merge(NameFilter.identity); | |
| 112 expect(filter.accepts('foo'), isFalse); | |
| 113 expect(filter.accepts('bar'), isFalse); | |
| 114 expect(filter.accepts('baz'), isTrue); | |
| 115 expect(filter.shownNames, isNull); | |
| 116 expect(filter.hiddenNames, isNotNull); | |
| 117 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 118 } | |
| 119 | |
| 120 test_merge_hides_shows() { | |
| 121 NameFilter filter = new NameFilter.forCombinator( | |
| 122 new MockUnlinkedCombinator(hides: ['bar', 'baz'])).merge( | |
| 123 new NameFilter.forCombinator( | |
| 124 new MockUnlinkedCombinator(shows: ['foo', 'bar']))); | |
| 125 expect(filter.accepts('foo'), isTrue); | |
| 126 expect(filter.accepts('bar'), isFalse); | |
| 127 expect(filter.accepts('baz'), isFalse); | |
| 128 expect(filter.hiddenNames, isNull); | |
| 129 expect(filter.shownNames, isNotNull); | |
| 130 expect(filter.shownNames, ['foo'].toSet()); | |
| 131 } | |
| 132 | |
| 133 test_merge_identity_hides() { | |
| 134 NameFilter filter = NameFilter.identity.merge(new NameFilter.forCombinator( | |
| 135 new MockUnlinkedCombinator(hides: ['foo', 'bar']))); | |
| 136 expect(filter.accepts('foo'), isFalse); | |
| 137 expect(filter.accepts('bar'), isFalse); | |
| 138 expect(filter.accepts('baz'), isTrue); | |
| 139 expect(filter.shownNames, isNull); | |
| 140 expect(filter.hiddenNames, isNotNull); | |
| 141 expect(filter.hiddenNames, ['foo', 'bar'].toSet()); | |
| 142 } | |
| 143 | |
| 144 test_merge_identity_identity() { | |
| 145 NameFilter filter = NameFilter.identity.merge(NameFilter.identity); | |
| 146 expect(filter.accepts('foo'), isTrue); | |
| 147 expect(filter.hiddenNames, isNotNull); | |
| 148 expect(filter.hiddenNames, isEmpty); | |
| 149 expect(filter.shownNames, isNull); | |
| 150 } | |
| 151 | |
| 152 test_merge_identity_shows() { | |
| 153 NameFilter filter = NameFilter.identity.merge(new NameFilter.forCombinator( | |
| 154 new MockUnlinkedCombinator(shows: ['foo', 'bar']))); | |
| 155 expect(filter.accepts('foo'), isTrue); | |
| 156 expect(filter.accepts('bar'), isTrue); | |
| 157 expect(filter.accepts('baz'), isFalse); | |
| 158 expect(filter.hiddenNames, isNull); | |
| 159 expect(filter.shownNames, isNotNull); | |
| 160 expect(filter.shownNames, ['foo', 'bar'].toSet()); | |
| 161 } | |
| 162 | |
| 163 test_merge_shows_hides() { | |
| 164 NameFilter filter = new NameFilter.forCombinator( | |
| 165 new MockUnlinkedCombinator(shows: ['foo', 'bar'])).merge( | |
| 166 new NameFilter.forCombinator( | |
| 167 new MockUnlinkedCombinator(hides: ['bar', 'baz']))); | |
| 168 expect(filter.accepts('foo'), isTrue); | |
| 169 expect(filter.accepts('bar'), isFalse); | |
| 170 expect(filter.accepts('baz'), isFalse); | |
| 171 expect(filter.hiddenNames, isNull); | |
| 172 expect(filter.shownNames, isNotNull); | |
| 173 expect(filter.shownNames, ['foo'].toSet()); | |
| 174 } | |
| 175 | |
| 176 test_merge_shows_identity() { | |
| 177 NameFilter filter = new NameFilter.forCombinator( | |
| 178 new MockUnlinkedCombinator(shows: ['foo', 'bar'])) | |
| 179 .merge(NameFilter.identity); | |
| 180 expect(filter.accepts('foo'), isTrue); | |
| 181 expect(filter.accepts('bar'), isTrue); | |
| 182 expect(filter.accepts('baz'), isFalse); | |
| 183 expect(filter.hiddenNames, isNull); | |
| 184 expect(filter.shownNames, isNotNull); | |
| 185 expect(filter.shownNames, ['foo', 'bar'].toSet()); | |
| 186 } | |
| 187 | |
| 188 test_merge_shows_shows() { | |
| 189 NameFilter filter = new NameFilter.forCombinator( | |
| 190 new MockUnlinkedCombinator(shows: ['foo', 'bar'])).merge( | |
| 191 new NameFilter.forCombinator( | |
| 192 new MockUnlinkedCombinator(shows: ['bar', 'baz']))); | |
| 193 expect(filter.accepts('foo'), isFalse); | |
| 194 expect(filter.accepts('bar'), isTrue); | |
| 195 expect(filter.accepts('baz'), isFalse); | |
| 196 expect(filter.hiddenNames, isNull); | |
| 197 expect(filter.shownNames, isNotNull); | |
| 198 expect(filter.shownNames, ['bar'].toSet()); | |
| 199 } | |
| 200 | |
| 201 test_merge_shows_shows_emptyResult() { | |
| 202 NameFilter filter = | |
| 203 new NameFilter.forCombinator(new MockUnlinkedCombinator(shows: ['foo'])) | |
| 204 .merge(new NameFilter.forCombinator( | |
| 205 new MockUnlinkedCombinator(shows: ['bar']))); | |
| 206 expect(filter.accepts('foo'), isFalse); | |
| 207 expect(filter.accepts('bar'), isFalse); | |
| 208 expect(filter.accepts('baz'), isFalse); | |
| 209 expect(filter.hiddenNames, isNull); | |
| 210 expect(filter.shownNames, isNotNull); | |
| 211 expect(filter.shownNames, isEmpty); | |
| 212 } | |
| 213 } | |
| OLD | NEW |