Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Aug 19, 2022
2 parents 08fdb64 + c5f1bbe commit 529ae0b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 41 deletions.
44 changes: 4 additions & 40 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,9 @@ on:
pull_request:

jobs:
semantic-pull-request:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: dart-lang/setup-dart@v1

- name: Install Dependencies
run: dart pub get

- name: Format
run: dart format .

- name: Analyze
run: dart analyze .

- name: Run Tests
run: |
pub global activate test_coverage
export PATH=$PATH:$HOME/.pub-cache/bin
test_coverage
- name: Check Code Coverage
uses: VeryGoodOpenSource/very_good_coverage@v1.1.1

uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
pana:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: subosito/flutter-action@v1.5.3

- name: Install Dependencies
run: |
flutter packages get
flutter pub global activate pana
- name: Verify Pub Score
run: |
PANA=$(pana . --no-warning); PANA_SCORE=$(echo $PANA | sed -n "s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p")
echo "score: $PANA_SCORE"
IFS='/'; read -a SCORE_ARR <<< "$PANA_SCORE"; SCORE=SCORE_ARR[0]; TOTAL=SCORE_ARR[1]
if (( $SCORE < $TOTAL )); then echo "minimum score not met!"; exit 1; fi
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.4

- fix: use `SplayTreeSet` to resolve inconsistent `hashCode` for properties of type `Set` ([#142](https://github.com/felangel/equatable/issues/142))

# 2.0.3

- fix: revert `EquatableMixin` == to use `Object` ([#122](https://github.com/felangel/equatable/issues/122))
Expand Down
3 changes: 3 additions & 0 deletions lib/src/equatable_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ int _combine(int hash, dynamic object) {
});
return hash;
}
if (object is Set) {
object = object.sorted(((dynamic a, dynamic b) => a.hashCode - b.hashCode));
}
if (object is Iterable) {
for (final value in object) {
hash = hash ^ _combine(hash, value);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: equatable
description: A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.
version: 2.0.3
version: 2.0.4
repository: https://github.com/felangel/equatable
issue_tracker: https://github.com/felangel/equatable/issues
homepage: https://github.com/felangel/equatable
Expand Down
22 changes: 22 additions & 0 deletions test/equatable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,17 @@ void main() {
expect(instanceA.hashCode == instanceB.hashCode, true);
});

test('should return when Set values are same but in different order', () {
final instanceA = SimpleEquatable<Set<String>>(
Set.from(<String>['A', 'B']),
);
final instanceB = SimpleEquatable<Set<String>>(
Set.from(<String>['B', 'A']),
);
expect(instanceA == instanceB, true);
expect(instanceA.hashCode == instanceB.hashCode, true);
});

test('should return when values are different', () {
final instanceA = SimpleEquatable<Set<String>>(
Set.from(<String>['A', 'B']),
Expand All @@ -989,6 +1000,17 @@ void main() {
expect(instanceA != instanceB, true);
expect(instanceA.hashCode != instanceB.hashCode, true);
});

test('should support non-comparable types', () {
final instanceA = SimpleEquatable<Set<Object>>(
Set.from(<Object>[Object()]),
);
final instanceB = SimpleEquatable<Set<Object>>(
Set.from(<Object>[Object()]),
);
expect(instanceA == instanceB, false);
expect(instanceA.hashCode == instanceB.hashCode, false);
});
});
});

Expand Down

0 comments on commit 529ae0b

Please sign in to comment.