Color operator== should compare runtimeTypes (flutter/engine#3495)
This commit is contained in:
@@ -170,7 +170,9 @@ class Color {
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
if (other is! Color)
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other.runtimeType != runtimeType)
|
||||
return false;
|
||||
final Color typedOther = other;
|
||||
return value == typedOther.value;
|
||||
|
||||
@@ -6,6 +6,10 @@ import 'dart:ui';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
class NotAColor extends Color {
|
||||
const NotAColor(int value) : super(value);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test("color accessors should work", () {
|
||||
Color foo = const Color(0x12345678);
|
||||
@@ -41,4 +45,14 @@ void main() {
|
||||
expect(e != null, equals(true));
|
||||
}
|
||||
});
|
||||
|
||||
test("two colors are only == if they have the same runtime type", () {
|
||||
expect(const Color(123), equals(const Color(123)));
|
||||
expect(const Color(123), equals(new Color(123)));
|
||||
expect(const Color(123), isNot(equals(const Color(321))));
|
||||
expect(const Color(123), isNot(equals(const NotAColor(123))));
|
||||
expect(const NotAColor(123), isNot(equals(const Color(123))));
|
||||
expect(const NotAColor(123), equals(const NotAColor(123)));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user