test: use isTrue/isFalse matcher

This commit is contained in:
iamstanlee 2021-06-04 04:47:34 -07:00
parent f5b940bc07
commit 79d192a441
2 changed files with 19 additions and 12 deletions

View File

@ -1,18 +1,23 @@
# linkfy_text
A lightweight flutter package to linkify texts containing urls, emails and hashtags. A lightweight flutter package to linkify texts containing urls, emails and hashtags.
<!-- [![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/linkfy_text) --> ![issues](https://img.shields.io/github/issues/Iamstanlee/linkfy_text)]
[![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/linkfy_text)
## Using ![final](https://user-images.githubusercontent.com/43510799/104180838-2385fd80-5451-11eb-8506-1640b4ea829f.gif)
## Usage
```dart ```dart
// first import the package // first import the package
import 'package:linkfy_text/linkify_text.dart'; import 'package:linkfy_text/linkify_text.dart';
LinkifyText( LinkifyText(
"This text contains a url: https://flutter.dev", "This text contains a url: https://flutter.dev",
linkStyle: TextStyle(color: Colors.blue, fontSize: 16), linkStyle: TextStyle(color: Colors.blue, fontSize: 16),
onTap: (link) { onTap: (link) {
// onTap is called when a link is pressed /// do stuff with `link`
print("${link.value}");
}, },
); );
``` ```
@ -21,11 +26,13 @@ Be default, The above snippet would linkify all urls in the string, you can choo
```dart ```dart
LinkifyText( LinkifyText(
"This text contains an #hashtag", "This text contains an #hashtag and a url",
linkStyle: TextStyle(color: Colors.blue, fontSize: 16), linkStyle: TextStyle(color: Colors.blue, fontSize: 16),
linkTypes: [LinkType.hashtag] linkTypes: [LinkType.url, LinkType.hashtag]
onTap: (link) { onTap: (link) {
print("${link.value}"); /// do stuff with `link`
}, },
); );
``` ```

View File

@ -42,7 +42,7 @@ void main() {
test("Should match all emails", () { test("Should match all emails", () {
_emails.forEach((e) { _emails.forEach((e) {
bool hasMatch = RegExp(emailRegExp).hasMatch(e); bool hasMatch = RegExp(emailRegExp).hasMatch(e);
expect(hasMatch, true); expect(hasMatch, isTrue);
}); });
}); });
@ -50,25 +50,25 @@ void main() {
List<String> _emails = ["hello@world", "@js.com"]; List<String> _emails = ["hello@world", "@js.com"];
_emails.forEach((e) { _emails.forEach((e) {
bool hasMatch = RegExp(emailRegExp).hasMatch(e); bool hasMatch = RegExp(emailRegExp).hasMatch(e);
expect(hasMatch, false); expect(hasMatch, isFalse);
}); });
}); });
test("Should match all urls", () { test("Should match all urls", () {
_urls.forEach((u) { _urls.forEach((u) {
bool hasMatch = RegExp(urlRegExp).hasMatch(u); bool hasMatch = RegExp(urlRegExp).hasMatch(u);
expect(hasMatch, true); expect(hasMatch, isTrue);
}); });
}); });
test("Should match all hashtags", () { test("Should match all hashtags", () {
_hashtags.forEach((h) { _hashtags.forEach((h) {
bool hasMatch = RegExp(hashtagRegExp).hasMatch(h); bool hasMatch = RegExp(hashtagRegExp).hasMatch(h);
expect(hasMatch, true); expect(hasMatch, isTrue);
}); });
}); });
test("Should construct regex pattern from LinkTypes and match", () { test("Should construct regex pattern from LinkTypes and match length", () {
RegExp _urlRegExp = constructRegExpFromLinkType([LinkType.url]); RegExp _urlRegExp = constructRegExpFromLinkType([LinkType.url]);
RegExp _hashtagRegExp = constructRegExpFromLinkType([LinkType.hashTag]); RegExp _hashtagRegExp = constructRegExpFromLinkType([LinkType.hashTag]);
RegExp _emailRegExp = constructRegExpFromLinkType([LinkType.email]); RegExp _emailRegExp = constructRegExpFromLinkType([LinkType.email]);