-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from Floating-Dartists/fix/#64_double-slashes-…
…in-url fix + tests
- Loading branch information
Showing
3 changed files
with
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extension StringExtensions on String { | ||
/// If the string is not already prefixed with a slash, prefix it with one. | ||
String prefixWithSlash() { | ||
if (startsWith('/')) return this; | ||
return '/$this'; | ||
} | ||
} |
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,18 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:matomo_tracker/utils/extensions.dart'; | ||
|
||
void main() { | ||
group('StringExtensions', () { | ||
group('prefixWithSlash', () { | ||
test('should return the same string', () { | ||
const String testString = '/test'; | ||
expect(testString.prefixWithSlash(), testString); | ||
}); | ||
|
||
test('should return the string with a slash prefix', () { | ||
const String testString = 'test'; | ||
expect(testString.prefixWithSlash(), '/$testString'); | ||
}); | ||
}); | ||
}); | ||
} |