Skip to content

Commit

Permalink
fix(package_info_plus): adds value equality for PackageInfo (#1328)
Browse files Browse the repository at this point in the history
Co-authored-by: Damian Bast <me@damianbast.com>
  • Loading branch information
dkbast and dkbast committed Nov 9, 2022
1 parent 0530d5e commit d572feb
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Expand Up @@ -89,4 +89,32 @@ class PackageInfo {
installerStore: installerStore,
);
}

/// Overwrite equals for value equality
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PackageInfo &&
runtimeType == other.runtimeType &&
appName == other.appName &&
packageName == other.packageName &&
version == other.version &&
buildNumber == other.buildNumber &&
buildSignature == other.buildSignature &&
installerStore == other.installerStore;

/// Overwrite hashCode for value equality
@override
int get hashCode =>
appName.hashCode ^
packageName.hashCode ^
version.hashCode ^
buildNumber.hashCode ^
buildSignature.hashCode ^
installerStore.hashCode;

@override
String toString() {
return 'PackageInfo(appName: $appName, buildNumber: $buildNumber, packageName: $packageName, version: $version, buildSignature: $buildSignature, installerStore: $installerStore)';
}
}
Expand Up @@ -68,4 +68,54 @@ void main() {
expect(info.buildSignature, 'deadbeef');
expect(info.installerStore, null);
});

test('equals checks for value equality', () async {
final info1 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
final info2 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
expect(info1, info2);
});

test('hashCode checks for value equality', () async {
final info1 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
final info2 = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
expect(info1.hashCode, info2.hashCode);
});

test('toString returns a string representation', () async {
final info = PackageInfo(
appName: 'package_info_example',
buildNumber: '1',
packageName: 'io.flutter.plugins.packageinfoexample',
version: '1.0',
buildSignature: '',
installerStore: null);
expect(
info.toString(),
'PackageInfo(appName: package_info_example, buildNumber: 1, packageName: io.flutter.plugins.packageinfoexample, version: 1.0, buildSignature: , installerStore: null)',
);
});
}

0 comments on commit d572feb

Please sign in to comment.