-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update languages structure screenshot (#70)
* docs: update structure screenshot * feat: added material supported languages sealed constant * feat: added iso standardized string extension * test: tests for iso standardized string extension
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
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
14 changes: 14 additions & 0 deletions
14
packages/sealed_languages/lib/src/helpers/extensions/iso_standardized_string_extension.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,14 @@ | ||
/// Extension on [String] providing additional functionality | ||
/// for ISO standardized strings. | ||
extension IsoStandardizedStringExtension on String { | ||
/// Checks if the string is a valid ISO code. | ||
/// | ||
/// Returns `true` if the string matches strings that consist of Latin | ||
/// characters (uppercase or lowercase) and have a length of 3 or more | ||
/// characters, indicating that it is a valid ISO code. | ||
/// Returns `false` otherwise. | ||
/// | ||
/// In terms of this package, it means that it is a valid | ||
/// ISO `code` (not `codeOther`). | ||
bool get isIsoCode => RegExp(r"^[a-zA-Z]{3,}$").hasMatch(this); | ||
} |
23 changes: 23 additions & 0 deletions
23
.../sealed_languages/test/src/helpers/extensions/iso_standardized_string_extension_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,23 @@ | ||
import "package:sealed_languages/sealed_languages.dart"; | ||
import "package:test/test.dart"; | ||
|
||
void main() => group("IsoStandardizedStringExtension", () { | ||
group("isIsoCode", () { | ||
test("should return true for valid ISO codes", () { | ||
expect("ENG".isIsoCode, isTrue); | ||
expect("Latn".isIsoCode, isTrue); | ||
expect("abc".isIsoCode, isTrue); | ||
expect("xyz".isIsoCode, isTrue); | ||
expect("AbC".isIsoCode, isTrue); | ||
}); | ||
|
||
test("should return false for invalid ISO codes", () { | ||
expect("A".isIsoCode, isFalse); | ||
expect("AB".isIsoCode, isFalse); | ||
expect("123".isIsoCode, isFalse); | ||
expect("AB3".isIsoCode, isFalse); | ||
expect("abc123".isIsoCode, isFalse); | ||
expect("!@#".isIsoCode, isFalse); | ||
}); | ||
}); | ||
}); |