Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Matcher generic #3652

Closed
DartBot opened this issue Jun 14, 2012 · 8 comments
Closed

make Matcher generic #3652

DartBot opened this issue Jun 14, 2012 · 8 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@DartBot
Copy link

DartBot commented Jun 14, 2012

This issue was originally filed by @seaneagan


It would be nice if dart:unittest's Matcher was generic:

interface Matcher<T> {
  bool matches(T item);
  //...
}

//...

Matcher<num> closeTo(num value, num delta);
Matcher<Map<K, V>> containsPair<K, V>(K key, V value);
Matcher<Map<Dynamic, V>> containsValue<V>(V value);
Matcher<Map<K, Dynamic>> containsKey<K>(K key);
Matcher<String> startsWith(String str);
Matcher<String> endsWith(String str);
Matcher<String> matches(Pattern pattern);
Matcher<String> equalsIgnoringCase(String str);
Matcher<String> equalsIgnoringWhiteSpace(String str);
Matcher<T> lessThan<T extends Comparable<T>>(Comparable c);
Matcher<T> greaterThan<T extends Comparable<T>>(T c);
Matcher<T> lessThanOrEqualTo<T extends Comparable<T>>(T c);
Matcher<T> greaterThanOrEqualTo<T extends Comparable<T>>(T c);
Matcher<Collection<E>> every(Matcher<E>);
Matcher<Collection<E>> some(Matcher<E>);
Matcher<bool> get isTrue();
Matcher<bool> get isFalse();
Matcher<num> get isPositive();
Matcher<num> get isNegative();
Matcher<num> get isNonPositive();
Matcher<num> get isNonNegative();
Matcher<num> get isZero();
Matcher<num> get isNonZero();
Matcher<Function> get throws();
Matcher<Function> get returnsNormally();
Matcher<Future> get completes();
//etc.

If issue #4 were fixed, then "expect" could change to:

void expect<T>(T item, Matcher<T> matcher);
//...
expect<bool>(b, isTrue);
expect<num>(i, lessThan<num>(6));
expect<String>(s, matches(new Regexp(@­"\d+"));

a better option though might be to change expect to an instance method of Matcher, and rename it to "test":

isTrue.test(b);
isPositive.test(x);
matches(new Regexp(@­"\d+")).test(s);

@DartBot
Copy link
Author

DartBot commented Jun 15, 2012

This comment was originally written by @seaneagan


If going the Matcher#test route, it would be nice to have it be a "final method" as in Java, either in BaseMatcher, or just rename BaseMatcher to Matcher and get rid of the explicit interface.

@anders-sandholm
Copy link
Contributor

Added Area-Test, Triaged labels.

@anders-sandholm
Copy link
Contributor

Removed Area-Test label.
Added Area-UnitTest label.

@gramster
Copy link

In many cases, the type of the argument is tested anyway and the matcher will fail with an appropriate error message if it is the wrong type. This could be done at compile time rather than run time using generics, but it adds developer pain to have to type every call to expect.


Added NotPlanned label.

@DartBot
Copy link
Author

DartBot commented Jun 25, 2012

This comment was originally written by @seaneagan


Presumably if Dart added generic methods (issue #254) the type argument to the method call would be optional just like all other type annotations are. Also, type arguments could likely be inferred in many cases.

Even if generic methods aren't added this would still make it much easier to tell which types each matcher matches against, since you can tell merely by looking at the method signature or field definitition, as opposed to having to read the doc comments.

@kevmoo
Copy link
Member

kevmoo commented Feb 12, 2014

Added Pkg-Unittest label.

@kevmoo
Copy link
Member

kevmoo commented Feb 12, 2014

Removed Area-UnitTest label.
Added Area-Pkg label.

@DartBot DartBot added Type-Defect area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue labels Feb 12, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/test#136.

copybara-service bot pushed a commit that referenced this issue Nov 25, 2022
Bump pub to 6fdcdd4357645817e7d7027ee2157ed68ef69c53

Changes:
```
> git log --format="%C(auto) %h %s" 6ac42d7..6fdcdd4
 https://dart.googlesource.com/pub.git/+/6fdcdd43 Support `--native-assets` in kernel compilation commands (#3667)
 https://dart.googlesource.com/pub.git/+/7202dd5e Fix error message for missing transitive dependency (#3196)
 https://dart.googlesource.com/pub.git/+/ab3304e1 Ignore analysis_options.yaml everywhere (#3666)
 https://dart.googlesource.com/pub.git/+/54e0b1eb Only check for sdk updates during resolveExecutable (#3665)
 https://dart.googlesource.com/pub.git/+/327d9ee8 Fix global activate --git-ref (#3656)
 https://dart.googlesource.com/pub.git/+/1485d60c Add env var flag to
override stdout.hasTerminal for output animations (#3658)
 https://dart.googlesource.com/pub.git/+/13ca9de1 Fix escapeShellArgument (#3663)
 https://dart.googlesource.com/pub.git/+/75c671c7 Allow adding from multiple sources (#3571)
 https://dart.googlesource.com/pub.git/+/1acfd4f7 dart pub get --enforce-lockfile (#3637)
 https://dart.googlesource.com/pub.git/+/9810fc6f Suggest using 2.12 as lower-bound SDK constraint (#3660)
 https://dart.googlesource.com/pub.git/+/f481f27a Add a README.md to the pub cache after command ends (#3650)
 https://dart.googlesource.com/pub.git/+/d54d52d3 Have executableForCommand rerun pub get if sdk changed minor version (#3652)
 https://dart.googlesource.com/pub.git/+/ea986525 Delete move.yml (#3648)

```

Diff: https://dart.googlesource.com/pub.git/+/6ac42d7644dedfcc500147ab47886eecab4b1b38~..6fdcdd4357645817e7d7027ee2157ed68ef69c53/

Bump webdev to 637b406f325669507b5c1048c19a7c0083c1bd6e

Changes:
```
> git log --format="%C(auto) %h %s" 3ec168f..637b406
 https://dart.googlesource.com/webdev.git/+/637b406 Support `--native-assets` in `FrontendServerClient` (#1797)
 https://dart.googlesource.com/webdev.git/+/a19d563 Save debug information in `chrome.storage` after a Dart app loads  (#1791)
 https://dart.googlesource.com/webdev.git/+/9cc10d4 Connect to a `chrome.runtime` port to keep the service worker alive  (#1789)

```
Diff: https://dart.googlesource.com/webdev.git/+/3ec168f6815af9d5f11278111d147bc82c0755c3~..637b406f325669507b5c1048c19a7c0083c1bd6e/


Update CHANGELOG


Bump pub to 6fdcdd4357645817e7d7027ee2157ed68ef69c53

Changes:
```
> git log --format="%C(auto) %h %s" 6ac42d7..6fdcdd4
 https://dart.googlesource.com/pub.git/+/6fdcdd43 Support `--native-assets` in kernel compilation commands (#3667)
 https://dart.googlesource.com/pub.git/+/7202dd5e Fix error message for missing transitive dependency (#3196)
 https://dart.googlesource.com/pub.git/+/ab3304e1 Ignore analysis_options.yaml everywhere (#3666)
 https://dart.googlesource.com/pub.git/+/54e0b1eb Only check for sdk updates during resolveExecutable (#3665)
 https://dart.googlesource.com/pub.git/+/327d9ee8 Fix global activate --git-ref (#3656)
 https://dart.googlesource.com/pub.git/+/1485d60c Add env var flag to override stdout.hasTerminal for output animations (#3658)
 https://dart.googlesource.com/pub.git/+/13ca9de1 Fix escapeShellArgument (#3663)
 https://dart.googlesource.com/pub.git/+/75c671c7 Allow adding from multiple sources (#3571)
 https://dart.googlesource.com/pub.git/+/1acfd4f7 dart pub get --enforce-lockfile (#3637)
 https://dart.googlesource.com/pub.git/+/9810fc6f Suggest using 2.12 as lower-bound SDK constraint (#3660)
 https://dart.googlesource.com/pub.git/+/f481f27a Add a README.md to the pub cache after command ends (#3650)
 https://dart.googlesource.com/pub.git/+/d54d52d3 Have executableForCommand rerun pub get if sdk changed minor version (#3652)
 https://dart.googlesource.com/pub.git/+/ea986525 Delete move.yml (#3648)

```

Diff: https://dart.googlesource.com/pub.git/+/6ac42d7644dedfcc500147ab47886eecab4b1b38~..6fdcdd4357645817e7d7027ee2157ed68ef69c53/
Change-Id: I65b928479b44f08305853078b0f34a6b66602709
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271709
Auto-Submit: Sigurd Meldgaard <sigurdm@google.com>
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Jonas Jensen <jonasfj@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

4 participants