| Index: packages/collection/test/combined_wrapper/list_test.dart
|
| diff --git a/packages/collection/test/combined_wrapper/list_test.dart b/packages/collection/test/combined_wrapper/list_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1a00f32421aab770eba53f07ca5ae82f0b8f694e
|
| --- /dev/null
|
| +++ b/packages/collection/test/combined_wrapper/list_test.dart
|
| @@ -0,0 +1,67 @@
|
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
| +// for details. 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:collection/collection.dart';
|
| +import 'package:test/test.dart';
|
| +
|
| +import '../unmodifiable_collection_test.dart' as common;
|
| +
|
| +void main() {
|
| + var list1 = [1, 2, 3];
|
| + var list2 = [4, 5, 6];
|
| + var list3 = [7, 8, 9];
|
| + var concat = []..addAll(list1)..addAll(list2)..addAll(list3);
|
| +
|
| + // In every way possible this should test the same as an UnmodifiableListView.
|
| + common.testUnmodifiableList(
|
| + concat, new CombinedListView([list1, list2, list3]), 'combineLists');
|
| +
|
| + common.testUnmodifiableList(concat,
|
| + new CombinedListView([list1, [], list2, [], list3, []]), 'combineLists');
|
| +
|
| + test('should function as an empty list when no lists are passed', () {
|
| + var empty = new CombinedListView([]);
|
| + expect(empty, isEmpty);
|
| + expect(empty.length, 0);
|
| + expect(() => empty[0], throwsRangeError);
|
| + });
|
| +
|
| + test('should function as an empty list when only empty lists are passed', () {
|
| + var empty = new CombinedListView([[], [], []]);
|
| + expect(empty, isEmpty);
|
| + expect(empty.length, 0);
|
| + expect(() => empty[0], throwsRangeError);
|
| + });
|
| +
|
| + test('should reflect underlying changes back to the combined list', () {
|
| + var backing1 = <int>[];
|
| + var backing2 = <int>[];
|
| + var combined = new CombinedListView([backing1, backing2]);
|
| + expect(combined, isEmpty);
|
| + backing1.addAll(list1);
|
| + expect(combined, list1);
|
| + backing2.addAll(list2);
|
| + expect(combined, backing1.toList()..addAll(backing2));
|
| + });
|
| +
|
| + test('should reflect underlying changes from the list of lists', () {
|
| + var listOfLists = <List<int>>[];
|
| + var combined = new CombinedListView(listOfLists);
|
| + expect(combined, isEmpty);
|
| + listOfLists.add(list1);
|
| + expect(combined, list1);
|
| + listOfLists.add(list2);
|
| + expect(combined, []..addAll(list1)..addAll(list2));
|
| + listOfLists.clear();
|
| + expect(combined, isEmpty);
|
| + });
|
| +
|
| + test('should reflect underlying changes with a single list', () {
|
| + var backing1 = <int>[];
|
| + var combined = new CombinedListView([backing1]);
|
| + expect(combined, isEmpty);
|
| + backing1.addAll(list1);
|
| + expect(combined, list1);
|
| + });
|
| +}
|
|
|