// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; class TestValueKey extends ValueKey { const TestValueKey(T value) : super(value); } @immutable class NotEquals { const NotEquals(); @override bool operator ==(Object other) => false; @override int get hashCode => 0; } void main() { testWidgets('Keys', (WidgetTester tester) async { expect(ValueKey(nonconst(3)) == ValueKey(nonconst(3)), isTrue); expect(ValueKey(nonconst(3)) == ValueKey(nonconst(3)), isFalse); expect(ValueKey(nonconst(3)) == ValueKey(nonconst(2)), isFalse); expect(const ValueKey(double.nan) == const ValueKey(double.nan), isFalse); expect(Key(nonconst('')) == ValueKey(nonconst('')), isTrue); expect(ValueKey(nonconst('')) == ValueKey(nonconst('')), isTrue); expect(TestValueKey(nonconst('')) == ValueKey(nonconst('')), isFalse); expect(TestValueKey(nonconst('')) == TestValueKey(nonconst('')), isTrue); expect(ValueKey(nonconst('')) == ValueKey(nonconst('')), isFalse); expect(TestValueKey(nonconst('')) == TestValueKey(nonconst('')), isFalse); expect(UniqueKey() == UniqueKey(), isFalse); final UniqueKey k = UniqueKey(); expect(UniqueKey() == UniqueKey(), isFalse); expect(k == k, isTrue); expect(ValueKey(k) == ValueKey(k), isTrue); expect(ValueKey(k) == ValueKey(k), isFalse); expect(ObjectKey(k) == ObjectKey(k), isTrue); final NotEquals constNotEquals = nonconst(const NotEquals()); expect(ValueKey(constNotEquals) == ValueKey(constNotEquals), isFalse); expect(ObjectKey(constNotEquals) == ObjectKey(constNotEquals), isTrue); final Object constObject = nonconst(const Object()); expect(ObjectKey(constObject) == ObjectKey(constObject), isTrue); expect(ObjectKey(nonconst(Object())) == ObjectKey(nonconst(Object())), isFalse); expect(const ValueKey(true), hasOneLineDescription); expect(UniqueKey(), hasOneLineDescription); expect(const ObjectKey(true), hasOneLineDescription); expect(GlobalKey(), hasOneLineDescription); expect(GlobalKey(debugLabel: 'hello'), hasOneLineDescription); expect(const GlobalObjectKey(true), hasOneLineDescription); }); }