Add type param filter (#596)

Format code
Add match by type tests
pull/598/head
Sashika Nawarathne 5 years ago committed by GitHub
parent 1091fb1f33
commit a0d314bf5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,6 +9,17 @@ bool matchesQuery(String query, String sampleAttributes) {
var queryWords = query.split(' ')..removeWhere((s) => s.isEmpty);
var attributes = sampleAttributes.split(' ')..removeWhere((s) => s.isEmpty);
// Test for type filter
// This will check whether a type parameter is present in the
// search query, and return false if the self type mismatches
// the query type
for (var word in queryWords) {
if ((word.contains('type:') && !attributes.contains(word)) ||
(word.contains('platform:') && !attributes.contains('type:demo'))) {
return false;
}
}
// Test for exact matches
if (attributes.contains(query)) {
return true;

@ -107,7 +107,8 @@ void main() {
'widget:AnimatedBuilder '
'widget:FutureBuilder '
'package:json_serializable '
'package:path';
'package:path '
'type:sample';
// Test if various queries match these attributes
expect(matchesQuery('foo', attributes), false);
@ -124,6 +125,11 @@ void main() {
expect(matchesQuery('kitten tag:cats', attributes), true);
expect(matchesQuery('tag:beginner dogs', attributes), false);
expect(matchesQuery('asdf ', attributes), false);
// Test if queries match by type
expect(matchesQuery('type:sample', attributes), true);
expect(matchesQuery('type:cookbook', attributes), false);
expect(matchesQuery('kittens type:cookbook', attributes), false);
});
});

@ -33,7 +33,10 @@ void deploy() {
@Depends(createThumbnails)
Future buildRelease() async {
var app = PubApp.local('build_runner');
await app.runAsync('build --release --output web:public --delete-conflicting-outputs'.split(' ').toList());
await app.runAsync(
'build --release --output web:public --delete-conflicting-outputs'
.split(' ')
.toList());
}
@DefaultTask('Build the project.')

@ -5,6 +5,5 @@ import 'package:mdc_web/mdc_web.dart';
InputElement searchInput;
void main() {
querySelectorAll('.mdc-card__primary-action')
.forEach((el) => MDCRipple(el));
querySelectorAll('.mdc-card__primary-action').forEach((el) => MDCRipple(el));
}

Loading…
Cancel
Save