Skip to content

Commit

Permalink
Add string comparison tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Sep 25, 2023
1 parent e873010 commit e644306
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sugar/lib/src/core/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ extension Strings on String {
/// 'A' < 'Apple'; // true
/// 'Apple' < 'A'; // false
///
/// 'a' < 'A'; // true
/// 'A' < 'a'; // false
/// 'A' < 'a'; // true
/// 'a' < 'A'; // false
/// ```
bool operator < (String other) => compareTo(other) < 0;

Expand All @@ -442,8 +442,8 @@ extension Strings on String {
/// 'A' <= 'Apple'; // true
/// 'Apple' <= 'A'; // false
///
/// 'a' <= 'A'; // true
/// 'A' <= 'a'; // false
/// 'A' <= 'a'; // true
/// 'a' <= 'A'; // false
/// ```
bool operator <= (String other) => compareTo(other) <= 0;

Expand All @@ -461,8 +461,8 @@ extension Strings on String {
/// 'Apple' > 'A'; // true
/// 'A' > 'Apple'; // false
///
/// 'A' > 'a'; // true
/// 'a' > 'A'; // false
/// 'a' > 'A'; // true
/// 'A' > 'a'; // false
/// ```
bool operator > (String other) => compareTo(other) > 0;

Expand All @@ -480,8 +480,8 @@ extension Strings on String {
/// 'Apple' >= 'A'; // true
/// 'A' >= 'Apple'; // false
///
/// 'A' >= 'a'; // true
/// 'a' >= 'A'; // false
/// 'a' >= 'A'; // true
/// 'A' >= 'a'; // false
/// ```
bool operator >= (String other) => compareTo(other) >= 0;

Expand Down
64 changes: 64 additions & 0 deletions sugar/test/src/core/strings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,68 @@ void main() {
test('suffix', () => expect('ABC '.isNotBlank, true));
});

group('<', () {
test('A < B', () => expect('A' < 'B', true));

test('B < A', () => expect('B' < 'A', false));

test('A < A', () => expect('A' < 'A', false));

test('A < Apple', () => expect('A' < 'Apple', true));

test('Apple < A', () => expect('Apple' < 'A', false));

test('a < A', () => expect('a' < 'A', false));

test('A < a', () => expect('A' < 'a', true));
});

group('<=', () {
test('A <= B', () => expect('A' <= 'B', true));

test('B <= A', () => expect('B' <= 'A', false));

test('A <= A', () => expect('A' <= 'A', true));

test('A <= Apple', () => expect('A' <= 'Apple', true));

test('Apple <= A', () => expect('Apple' <= 'A', false));

test('a <= A', () => expect('a' <= 'A', false));

test('A <= a', () => expect('A' <= 'a', true));
});

group('>', () {
test('A > B', () => expect('A' > 'B', false));

test('B > A', () => expect('B' > 'A', true));

test('A > A', () => expect('A' > 'A', false));

test('A > Apple', () => expect('A' > 'Apple', false));

test('Apple > A', () => expect('Apple' > 'A', true));

test('a > A', () => expect('a' > 'A', true));

test('A > a', () => expect('A' > 'a', false));
});

group('>=', () {
test('A >= B', () => expect('A' >= 'B', false));

test('B >= A', () => expect('B' >= 'A', true));

test('A >= A', () => expect('A' >= 'A', true));

test('A >= Apple', () => expect('A' >= 'Apple', false));

test('Apple >= A', () => expect('Apple' >= 'A', true));

test('a >= A', () => expect('a' >= 'A', true));

test('A >= a', () => expect('A' >= 'a', false));
});

}

0 comments on commit e644306

Please sign in to comment.