// Copyright 2016 The Chromium 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); } class NotEquals { const NotEquals(); @override bool operator ==(dynamic other) => false; @override int get hashCode => 0; } void main() { testWidgets('Keys', (WidgetTester tester) async { expect(new ValueKey(nonconst(3)) == new ValueKey(nonconst(3)), isTrue); expect(new ValueKey(nonconst(3)) == new ValueKey(nonconst(3)), isFalse); expect(new ValueKey(nonconst(3)) == new ValueKey(nonconst(2)), isFalse); expect(const ValueKey(double.nan) == const ValueKey(double.nan), isFalse); expect(new Key(nonconst('')) == new ValueKey(nonconst('')), isTrue); expect(new ValueKey(nonconst('')) == new ValueKey(nonconst('')), isTrue); expect(new TestValueKey(nonconst('')) == new ValueKey(nonconst('')), isFalse); expect(new TestValueKey(nonconst('')) == new TestValueKey(nonconst('')), isTrue); expect(new ValueKey(nonconst('')) == new ValueKey(nonconst('')), isFalse); expect(new TestValueKey(nonconst('')) == new TestValueKey(nonconst('')), isFalse); expect(new UniqueKey() == new UniqueKey(), isFalse); final LocalKey k = new UniqueKey(); expect(new UniqueKey() == new UniqueKey(), isFalse); expect(k == k, isTrue); expect(new ValueKey(k) == new ValueKey(k), isTrue); expect(new ValueKey(k) == new ValueKey(k), isFalse); expect(new ObjectKey(k) == new ObjectKey(k), isTrue); final NotEquals constNotEquals = nonconst(const NotEquals()); expect(new ValueKey(constNotEquals) == new ValueKey(constNotEquals), isFalse); expect(new ObjectKey(constNotEquals) == new ObjectKey(constNotEquals), isTrue); final Object constObject = nonconst(const Object()); expect(new ObjectKey(constObject) == new ObjectKey(constObject), isTrue); expect(new ObjectKey(new Object()) == new ObjectKey(new Object()), isFalse); expect(const ValueKey(true), hasOneLineDescription); expect(new UniqueKey(), hasOneLineDescription); expect(const ObjectKey(true), hasOneLineDescription); expect(new GlobalKey(), hasOneLineDescription); expect(new GlobalKey(debugLabel: 'hello'), hasOneLineDescription); expect(const GlobalObjectKey(true), hasOneLineDescription); }); }