Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(package_info_plus): adds value equality for PackageInfo #1328

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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)';
}
}
Original file line number Diff line number Diff line change
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)',
);
});
}