-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…age-sorting #72: Updated the default sorting
- Loading branch information
Showing
6 changed files
with
293 additions
and
3 deletions.
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,13 @@ | ||
extension ListExtension<T> on List<T> { | ||
List<T> moveToFirstIndex(T item) { | ||
for (var i = 0; i < length; ++i) { | ||
if (this[i] == item) { | ||
final temp = this[0]; | ||
this[0] = this[i]; | ||
this[i] = temp; | ||
break; | ||
} | ||
} | ||
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
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,30 @@ | ||
import 'package:locale_gen/src/extensions/list_extensions.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('List Extensions', () { | ||
test('Test if move to first index is correct when not yet firsst', () { | ||
final list = ['Test', 'blabla', 'what']; | ||
final newList = list.moveToFirstIndex('what'); | ||
expect(newList[0], 'what'); | ||
expect(newList[1], 'Test'); | ||
expect(newList[2], 'blabla'); | ||
}); | ||
test('Test if move to first index is correct when already first', () { | ||
final list = ['Test', 'blabla', 'what']; | ||
final newList = list.moveToFirstIndex('Test'); | ||
expect(newList[0], 'Test'); | ||
expect(newList[1], 'blabla'); | ||
expect(newList[2], 'what'); | ||
}); | ||
test( | ||
'Test const list to move to first index is correct when already first f', | ||
() { | ||
const list = ['Test', 'blabla', 'what']; | ||
final newList = list.moveToFirstIndex('Test'); | ||
expect(newList[0], 'Test'); | ||
expect(newList[1], 'blabla'); | ||
expect(newList[2], 'what'); | ||
}); | ||
}); | ||
} |
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