Add structural equality for dependencies (dart-lang/pubspec_parse#127)
* Add structural equality for dependencies
* Apply suggestions from code review
Co-authored-by: Devon Carew <devoncarew@google.com>
---------
Co-authored-by: Devon Carew <devoncarew@google.com>
diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md
index 87dd5ca..d14b82e 100644
--- a/pkgs/pubspec_parse/CHANGELOG.md
+++ b/pkgs/pubspec_parse/CHANGELOG.md
@@ -1,7 +1,8 @@
-## 1.2.4-wip
+## 1.3.0
- Require Dart 3.0
- Added support for `ignored_advisories` field.
+- Added structural equality for `Dependency` subclasses and `HostedDetails`.
## 1.2.3
diff --git a/pkgs/pubspec_parse/lib/src/dependency.dart b/pkgs/pubspec_parse/lib/src/dependency.dart
index 95bbc8e..acce598 100644
--- a/pkgs/pubspec_parse/lib/src/dependency.dart
+++ b/pkgs/pubspec_parse/lib/src/dependency.dart
@@ -111,6 +111,13 @@
@override
String get _info => sdk;
+
+ @override
+ bool operator ==(Object other) =>
+ other is SdkDependency && other.sdk == sdk && other.version == version;
+
+ @override
+ int get hashCode => Object.hash(sdk, version);
}
@JsonSerializable()
@@ -136,6 +143,16 @@
@override
String get _info => 'url@$url';
+
+ @override
+ bool operator ==(Object other) =>
+ other is GitDependency &&
+ other.url == url &&
+ other.ref == ref &&
+ other.path == path;
+
+ @override
+ int get hashCode => Object.hash(url, ref, path);
}
Uri? parseGitUriOrNull(String? value) =>
@@ -188,6 +205,13 @@
@override
String get _info => 'path@$path';
+
+ @override
+ bool operator ==(Object other) =>
+ other is PathDependency && other.path == path;
+
+ @override
+ int get hashCode => path.hashCode;
}
@JsonSerializable(disallowUnrecognizedKeys: true)
@@ -204,6 +228,15 @@
@override
String get _info => version.toString();
+
+ @override
+ bool operator ==(Object other) =>
+ other is HostedDependency &&
+ other.version == version &&
+ other.hosted == hosted;
+
+ @override
+ int get hashCode => Object.hash(version, hosted);
}
@JsonSerializable(disallowUnrecognizedKeys: true)
@@ -240,6 +273,13 @@
throw ArgumentError.value(data, 'hosted', 'Must be a Map or String.');
}
+
+ @override
+ bool operator ==(Object other) =>
+ other is HostedDetails && other.name == name && other.url == url;
+
+ @override
+ int get hashCode => Object.hash(name, url);
}
VersionConstraint _constraintFromString(String? input) =>
diff --git a/pkgs/pubspec_parse/pubspec.yaml b/pkgs/pubspec_parse/pubspec.yaml
index 4f8eabc..9ca992d 100644
--- a/pkgs/pubspec_parse/pubspec.yaml
+++ b/pkgs/pubspec_parse/pubspec.yaml
@@ -1,5 +1,5 @@
name: pubspec_parse
-version: 1.2.4-wip
+version: 1.3.0
description: >-
Simple package for parsing pubspec.yaml files with a type-safe API and rich
error reporting.