Skip to content

Commit

Permalink
Add map of A1 to A1 extension to support moves literals
Browse files Browse the repository at this point in the history
  • Loading branch information
sjhorn committed Apr 2, 2024
1 parent a3e2c05 commit 40ca5d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.4

- Added support for A1 mapping as an extension on Map<String,String> to Map<A1,A1> to assist with A1 moves

## 1.0.3

- Added support for A1 as an extension on Set to simplify creating an a1 set from String
Expand Down
14 changes: 14 additions & 0 deletions lib/src/a1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ extension StringListA1Extension on List<String> {
Iterable<A1> get a1 => map((e) => e.a1);
}

/// This extension allows a [Set] of [String]s to be converted to
/// a [Set] of [A1]
extension StringSetA1Extension on Set<String> {
/// Return a [Set<A1>] from the current [Set<String>] or throw
/// a [FormatException] see [A1.parse].
Expand All @@ -257,3 +259,15 @@ extension StringSetA1Extension on Set<String> {
/// ```
Set<A1> get a1 => map((e) => e.a1).toSet();
}

/// This extension allows a [Map<String,String>] to be converted to
/// a [Map<A1,A1> to assist with cell movement tracking
extension MapA1Extension on Map<String, String> {
/// Return a [Map<A1,A1>] from the current [Map<String,String>] or throw
/// a [FormatException] see [A1.parse].
/// Example:
/// ```dart
/// Map<A1,A1> moves = {'a1':'b2','c3':'c4'}.a1; // Map<A1,A1>[A1:B2,C3:C4]
/// ```
Map<A1, A1> get a1 => map((key, value) => MapEntry(key.a1, value.a1));
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: a1
version: 1.0.3
version: 1.0.4

homepage: https://pub.dev/packages/a1
repository: https://github.com/sjhorn/a1
Expand Down
5 changes: 5 additions & 0 deletions test/a1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ void main() {
final a1Set = {'a1', 'B2', 'c3'}.a1;
expect(a1Set, containsAll({'a1'.a1, 'B2'.a1, 'c3'.a1}));
});
test('Map of String:String strings to Map of A1:A1s', () {
final moves = {'a1': 'd1', 'B2': 'c3'}.a1;
expect(moves, containsPair('A1'.a1, 'D1'.a1));
expect(moves, containsPair('B2'.a1, 'C3'.a1));
});
test('isLetter', () {
expect('A'.codeUnits.first.isA1Letter, isTrue);
expect('@'.codeUnits.first.isA1Letter, isFalse);
Expand Down

0 comments on commit 40ca5d8

Please sign in to comment.