Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toString() to all CopyOnWrite collections. #48

Merged
merged 1 commit into from
Feb 23, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.0.1

- Make map operator[] take Object instead of K, as SDK collections do.
- Fix toString for result of toList, toSet, toMap.

## 1.0.0

Expand Down
3 changes: 3 additions & 0 deletions lib/src/internal/copy_on_write_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class CopyOnWriteList<E> implements List<E> {
_list.replaceRange(start, end, iterable);
}

@override
String toString() => _list.toString();

// Internal.

void _maybeCopyBeforeWrite() {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/internal/copy_on_write_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class CopyOnWriteMap<K, V> implements Map<K, V> {
return _map.remove(key);
}

@override
String toString() => _map.toString();

// Internal.

void _maybeCopyBeforeWrite() {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/internal/copy_on_write_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class CopyOnWriteSet<E> implements Set<E> {
_set.retainAll(elements);
}

@override
String toString() => _set.toString();

// Internal.

void _maybeCopyBeforeWrite() {
Expand Down
7 changes: 7 additions & 0 deletions test/all_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

library built_collection.test.all_tests;

import 'internal/copy_on_write_list_test.dart' as copy_on_write_list_test;
import 'internal/copy_on_write_map_test.dart' as copy_on_write_map_test;
import 'internal/copy_on_write_set_test.dart' as copy_on_write_set_test;
import 'list/built_list_test.dart' as built_list_test;
import 'list/list_builder_test.dart' as list_builder_test;
import 'list_multimap/built_list_multimap_test.dart'
Expand All @@ -19,6 +22,10 @@ import 'set_multimap/set_multimap_builder_test.dart'
as set_multimap_builder_test;

void main() {
copy_on_write_list_test.main();
copy_on_write_map_test.main();
copy_on_write_set_test.main();

built_list_test.main();
list_builder_test.main();

Expand Down
15 changes: 15 additions & 0 deletions test/internal/copy_on_write_list_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2016, Google Inc. 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:built_collection/src/internal/copy_on_write_list.dart';
import 'package:unittest/unittest.dart';

void main() {
group('CopyOnWriteList', () {
test('has toString equal to List.toString', () {
final list = <int>[1, 2, 3];
expect(new CopyOnWriteList(list, false).toString(), list.toString());
});
});
}
15 changes: 15 additions & 0 deletions test/internal/copy_on_write_map_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2016, Google Inc. 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:built_collection/src/internal/copy_on_write_map.dart';
import 'package:unittest/unittest.dart';

void main() {
group('CopyOnWriteMap', () {
test('has toString equal to Map.toString', () {
final map = <int, String>{1: 'one', 2: 'two', 3: 'three'};
expect(new CopyOnWriteMap(map).toString(), map.toString());
});
});
}
15 changes: 15 additions & 0 deletions test/internal/copy_on_write_set_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2016, Google Inc. 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:built_collection/src/internal/copy_on_write_set.dart';
import 'package:unittest/unittest.dart';

void main() {
group('CopyOnWriteSet', () {
test('has toString equal to Set.toString', () {
final set = new Set<int>.from([1, 2, 3]);
expect(new CopyOnWriteSet(set).toString(), set.toString());
});
});
}