Skip to content

Commit

Permalink
Add toString() to all CopyOnWrite collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmorgan committed Feb 23, 2016
1 parent daf1bb9 commit 520c516
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1

- Fix toString for result of toList, toSet, toMap.

## 1.0.0

- Fix missing generics on some return types.
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());
});
});
}

0 comments on commit 520c516

Please sign in to comment.