Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
978aa42
commit 38a525b
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// Wraps [uri] with an escape sequence so it's recognized as a hyperlink. | ||
/// An optional message can be used in place of the [uri]. | ||
/// If no [message] is provided, the text content will be the full [uri]. | ||
/// | ||
/// ```dart | ||
/// final plainLink = link(uri: Uri.parse('https://dart.dev')); | ||
/// print(plainLink); // Equivalent to `[https://dart.dev](https://dart.dev)` in markdown | ||
/// | ||
/// final richLink = link(uri: Uri.parse('https://dart.dev'), message: 'The Dart Website'); | ||
/// print(richLink); // Equivalent to `[The Dart Website](https://dart.dev)` in markdown | ||
/// ``` | ||
String link({required Uri uri, String? message}) { | ||
const leading = '\x1B]8;;'; | ||
const trailing = '\x1B\\'; | ||
|
||
return '$leading$uri$trailing${message ?? uri}$leading$trailing'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:mason_logger/mason_logger.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('link', () { | ||
final uri = Uri.parse('https://github.com/felangel/mason/issues/'); | ||
const lead = '\x1B]8;;'; | ||
const trail = '\x1B\\'; | ||
|
||
test( | ||
'builds output with correct encodings: ' r'\x1B]8;;' ' and ' r'\x1B\\', | ||
() { | ||
const message = 'message'; | ||
final output = link(message: message, uri: uri); | ||
final matcher = stringContainsInOrder( | ||
[lead, '$uri', trail, message, lead, trail], | ||
); | ||
|
||
expect(output, matcher); | ||
}, | ||
); | ||
|
||
test('builds String with Uri when message is null: ', () { | ||
final output = link(uri: uri); | ||
final matcher = stringContainsInOrder( | ||
[lead, '$uri', trail, '$uri', lead, trail], | ||
); | ||
|
||
expect(output, matcher); | ||
}); | ||
}); | ||
} |