Skip to content
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
28 changes: 22 additions & 6 deletions lib/src/resizable_size.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ final class ResizableSizePixels extends ResizableSize {

@override
operator ==(Object other) =>
other is ResizableSizePixels && other.pixels == pixels;
other is ResizableSizePixels &&
other.pixels == pixels &&
other.min == min &&
other.max == max;

@override
int get hashCode => pixels.hashCode;
int get hashCode => Object.hash(pixels, min, max);
}

final class ResizableSizeRatio extends ResizableSize {
Expand All @@ -95,10 +98,13 @@ final class ResizableSizeRatio extends ResizableSize {

@override
operator ==(Object other) =>
other is ResizableSizeRatio && other.ratio == ratio;
other is ResizableSizeRatio &&
other.ratio == ratio &&
other.min == min &&
other.max == max;

@override
int get hashCode => ratio.hashCode;
int get hashCode => Object.hash(ratio, min, max);
}

final class ResizableSizeExpand extends ResizableSize {
Expand All @@ -113,15 +119,25 @@ final class ResizableSizeExpand extends ResizableSize {

@override
operator ==(Object other) =>
other is ResizableSizeExpand && other.flex == flex;
other is ResizableSizeExpand &&
other.flex == flex &&
other.min == min &&
other.max == max;

@override
int get hashCode => flex.hashCode;
int get hashCode => Object.hash(flex, min, max);
}

final class ResizableSizeShrink extends ResizableSize {
const ResizableSizeShrink._({super.min, super.max}) : super._();

@override
String toString() => 'ResizableSizeShrink()';

@override
operator ==(Object other) =>
other is ResizableSizeShrink && other.min == min && other.max == max;

@override
int get hashCode => Object.hash(min, max);
}
10 changes: 8 additions & 2 deletions test/resizable_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,10 @@ void main() {

expect(controller.isHidden(1), isTrue);
expect(controller.hiddenIndices, equals({1}));
expect(controller.sizes[1], equals(const ResizableSize.pixels(0)));
expect(
controller.sizes[1],
equals(const ResizableSize.pixels(0, min: 0, max: 0)),
);
expect(controller.needsLayout, isTrue);
});

Expand Down Expand Up @@ -558,7 +561,10 @@ void main() {
]);

// hidden index still zero-sized
expect(controller.sizes[1], equals(const ResizableSize.pixels(0)));
expect(
controller.sizes[1],
equals(const ResizableSize.pixels(0, min: 0, max: 0)),
);
expect(controller.isHidden(1), isTrue);

controller.show(1);
Expand Down
143 changes: 143 additions & 0 deletions test/resizable_size_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,149 @@ void main() {
isFalse,
);
});

group('pixels', () {
test('returns false when min differs', () {
expect(
const ResizableSize.pixels(1, min: 10) ==
const ResizableSize.pixels(1, min: 20),
isFalse,
);
});

test('returns false when max differs', () {
expect(
const ResizableSize.pixels(1, max: 100) ==
const ResizableSize.pixels(1, max: 200),
isFalse,
);
});

test('returns true when pixels, min, and max all match', () {
expect(
const ResizableSize.pixels(1, min: 10, max: 100) ==
const ResizableSize.pixels(1, min: 10, max: 100),
isTrue,
);
});

test('hashCode differs when min/max differ', () {
expect(
const ResizableSize.pixels(1, min: 10).hashCode ==
const ResizableSize.pixels(1, min: 20).hashCode,
isFalse,
);
});
});

group('ratio', () {
test('returns false when min differs', () {
expect(
const ResizableSize.ratio(0.5, min: 10) ==
const ResizableSize.ratio(0.5, min: 20),
isFalse,
);
});

test('returns false when max differs', () {
expect(
const ResizableSize.ratio(0.5, max: 100) ==
const ResizableSize.ratio(0.5, max: 200),
isFalse,
);
});

test('returns true when ratio, min, and max all match', () {
expect(
const ResizableSize.ratio(0.5, min: 10, max: 100) ==
const ResizableSize.ratio(0.5, min: 10, max: 100),
isTrue,
);
});

test('hashCode differs when min/max differ', () {
expect(
const ResizableSize.ratio(0.5, min: 10).hashCode ==
const ResizableSize.ratio(0.5, min: 20).hashCode,
isFalse,
);
});
});

group('expand', () {
test('returns false when min differs', () {
expect(
const ResizableSize.expand(min: 10) ==
const ResizableSize.expand(min: 20),
isFalse,
);
});

test('returns false when max differs', () {
expect(
const ResizableSize.expand(max: 100) ==
const ResizableSize.expand(max: 200),
isFalse,
);
});

test('returns true when flex, min, and max all match', () {
expect(
const ResizableSize.expand(flex: 2, min: 10, max: 100) ==
const ResizableSize.expand(flex: 2, min: 10, max: 100),
isTrue,
);
});

test('hashCode differs when min/max differ', () {
expect(
const ResizableSize.expand(min: 10).hashCode ==
const ResizableSize.expand(min: 20).hashCode,
isFalse,
);
});
});

group('shrink', () {
test('returns true for two default shrink instances', () {
expect(
const ResizableSize.shrink() == const ResizableSize.shrink(),
isTrue,
);
});

test('returns false when min differs', () {
expect(
const ResizableSize.shrink(min: 10) ==
const ResizableSize.shrink(min: 20),
isFalse,
);
});

test('returns false when max differs', () {
expect(
const ResizableSize.shrink(max: 100) ==
const ResizableSize.shrink(max: 200),
isFalse,
);
});

test('returns true when min and max match', () {
expect(
const ResizableSize.shrink(min: 10, max: 100) ==
const ResizableSize.shrink(min: 10, max: 100),
isTrue,
);
});

test('hashCode matches for equal instances', () {
expect(
const ResizableSize.shrink(min: 10, max: 100).hashCode ==
const ResizableSize.shrink(min: 10, max: 100).hashCode,
isTrue,
);
});
});
});
});
});
Expand Down
Loading