-
Notifications
You must be signed in to change notification settings - Fork 2
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 #90 from GIHAA/feat-startsWith
Feat: added starts_with under the string manipulation
- Loading branch information
Showing
3 changed files
with
43 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,17 @@ | ||
///Checks if string starts with the given target string. | ||
/// | ||
/// Arguments | ||
/// | ||
/// - string (String): The string to be checked. | ||
/// - target (String): The target string that is expected to be at the beginning of the given string. | ||
/// - position (int): Optional parameter specifying the starting position in the given string to begin the comparison. Defaults to 0 | ||
/// | ||
/// Returns | ||
/// | ||
/// - (Boolean): Returns true if the string starts with the target string at the specified position; otherwise, returns false | ||
|
||
@Deprecated('The function startsWith() is deprecated. Use the built-in startsWith() method instead.') | ||
bool startsWith(String string, String target, [int position = 0]) { | ||
return string.startsWith(target, position); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/flodash/test/modules/string/starts_with_test.dart
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,24 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:flodash/flodash.dart' as flodash; | ||
|
||
void main() { | ||
test('should return true if the string starts with the target', () { | ||
String string = 'abc'; | ||
String target = 'a'; | ||
bool result = flodash.startsWith(string, target); | ||
expect(result, true); | ||
}); | ||
test('should return false if the string does not start with the target', () { | ||
String string = 'abc'; | ||
String target = 'b'; | ||
bool result = flodash.startsWith(string, target); | ||
expect(result, false); | ||
}); | ||
test('should return true if the string starts with the target at the specified position', () { | ||
String string = 'abc'; | ||
String target = 'b'; | ||
int position = 1; | ||
bool result = flodash.startsWith(string, target, position); | ||
expect(result, true); | ||
}); | ||
} |