test: use isTrue/isFalse matcher
This commit is contained in:
parent
f5b940bc07
commit
79d192a441
21
README.md
21
README.md
|
@ -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.
|
||||||
|
|
||||||
<!-- [](https://pub.dev/packages/linkfy_text) -->
|
]
|
||||||
|
[](https://pub.dev/packages/linkfy_text)
|
||||||
|
|
||||||
## Using
|

|
||||||
|
|
||||||
|
## 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`
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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]);
|
||||||
|
|
Loading…
Reference in New Issue