From ced24a04c0962a3f05d8ca202bae08a2a8f63d59 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 13:27:18 +0100 Subject: [PATCH 1/8] Set/Map - Allow access to native dart collections --- lib/src/collection/list_empty.dart | 6 +++--- lib/src/collection/map.dart | 3 +++ lib/src/collection/map_empty.dart | 3 +++ lib/src/collection/map_mutable.dart | 3 +++ lib/src/collection/set.dart | 3 +++ lib/src/collection/set_empty.dart | 3 +++ lib/src/collection/set_mutable.dart | 3 +++ lib/src/k_map.dart | 5 +++++ lib/src/k_set.dart | 5 +++++ test/collection/list_empty_test.dart | 5 +++++ test/collection/list_test.dart | 6 ++++++ test/collection/map_empty_test.dart | 9 +++++++-- test/collection/map_test.dart | 12 ++++++++++++ test/collection/set_test.dart | 6 ++++++ 14 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 test/collection/map_test.dart diff --git a/lib/src/collection/list_empty.dart b/lib/src/collection/list_empty.dart index 1c91613d..06c58201 100644 --- a/lib/src/collection/list_empty.dart +++ b/lib/src/collection/list_empty.dart @@ -7,6 +7,9 @@ import 'package:dart_kollection/src/extension/list_extension_mixin.dart'; class EmptyList with KIterableExtensionsMixin, KCollectionExtensionMixin, KListExtensionsMixin implements KList { + @override + List get list => []; + @override bool contains(T element) => false; @@ -65,9 +68,6 @@ class EmptyList @override Iterable get iter => DartEmptyIterable(); - - @override - List get list => []; } class _EmptyIterator extends KListIterator { diff --git a/lib/src/collection/map.dart b/lib/src/collection/map.dart index 69a24d1d..588b4506 100644 --- a/lib/src/collection/map.dart +++ b/lib/src/collection/map.dart @@ -12,6 +12,9 @@ class DartMap with KMapExtensionsMixin implements KMap { _map = Map.unmodifiable(map), super(); + @override + Map get map => _map; + @override bool containsKey(K key) => _map.containsKey(key); diff --git a/lib/src/collection/map_empty.dart b/lib/src/collection/map_empty.dart index 8f50be22..6da3df11 100644 --- a/lib/src/collection/map_empty.dart +++ b/lib/src/collection/map_empty.dart @@ -2,6 +2,9 @@ import 'package:dart_kollection/dart_kollection.dart'; import 'package:dart_kollection/src/extension/map_extensions_mixin.dart'; class EmptyMap with KMapExtensionsMixin implements KMap { + @override + Map get map => {}; + @override operator [](K key) => null; diff --git a/lib/src/collection/map_mutable.dart b/lib/src/collection/map_mutable.dart index 0c96cb2f..550717d5 100644 --- a/lib/src/collection/map_mutable.dart +++ b/lib/src/collection/map_mutable.dart @@ -22,6 +22,9 @@ class DartMutableMap _map = map, super(); + @override + Map get map => _map; + @override bool containsKey(K key) => _map.containsKey(key); diff --git a/lib/src/collection/set.dart b/lib/src/collection/set.dart index 058b1a32..2d36b10c 100644 --- a/lib/src/collection/set.dart +++ b/lib/src/collection/set.dart @@ -14,6 +14,9 @@ class DartSet with KIterableExtensionsMixin, KCollectionExtensionMixin @override Iterable get iter => _set; + @override + Set get set => _set; + @override bool contains(T element) => _set.contains(element); diff --git a/lib/src/collection/set_empty.dart b/lib/src/collection/set_empty.dart index a53ae608..1ecbda3b 100644 --- a/lib/src/collection/set_empty.dart +++ b/lib/src/collection/set_empty.dart @@ -4,6 +4,9 @@ import 'package:dart_kollection/src/extension/collection_extension_mixin.dart'; import 'package:dart_kollection/src/extension/iterable_extension_mixin.dart'; class EmptySet with KIterableExtensionsMixin, KCollectionExtensionMixin implements KSet { + @override + Set get set => Set(); + @override bool contains(T element) => false; diff --git a/lib/src/collection/set_mutable.dart b/lib/src/collection/set_mutable.dart index 702e83f7..00dbf9cd 100644 --- a/lib/src/collection/set_mutable.dart +++ b/lib/src/collection/set_mutable.dart @@ -24,6 +24,9 @@ class DartMutableSet @override Iterable get iter => _set; + @override + Set get set => _set; + @override bool contains(T element) => _set.contains(element); diff --git a/lib/src/k_map.dart b/lib/src/k_map.dart index 6d8d54e8..5c5df7d9 100644 --- a/lib/src/k_map.dart +++ b/lib/src/k_map.dart @@ -10,6 +10,11 @@ import 'package:dart_kollection/dart_kollection.dart'; * @param V the type of map values. The map is covariant on its value type. */ abstract class KMap implements KMapExtension { + /** + * dart interop list for time critical operations such as sorting + */ + Map get map; + // Query Operations /** * Returns the number of key/value pairs in the map. diff --git a/lib/src/k_set.dart b/lib/src/k_set.dart index bc6c6632..f19da5b2 100644 --- a/lib/src/k_set.dart +++ b/lib/src/k_set.dart @@ -7,6 +7,11 @@ import 'package:dart_kollection/dart_kollection.dart'; * @param E the type of elements contained in the set. The set is covariant on its element type. */ abstract class KSet implements KCollection { + /** + * dart interop list for time critical operations such as sorting + */ + Set get set; + // Query Operations @override int get size; diff --git a/test/collection/list_empty_test.dart b/test/collection/list_empty_test.dart index 88b779b3..1caa795a 100644 --- a/test/collection/list_empty_test.dart +++ b/test/collection/list_empty_test.dart @@ -85,5 +85,10 @@ void main() { expect(() => empty.subList(-1, -1), throwsA(TypeMatcher())); expect(() => empty.subList(2, 10), throwsA(TypeMatcher())); }); + + test("access dart list", () { + List list = emptyList().list; + expect(list.length, 0); + }); }); } diff --git a/test/collection/list_test.dart b/test/collection/list_test.dart index 615ce7fa..e5e35264 100644 --- a/test/collection/list_test.dart +++ b/test/collection/list_test.dart @@ -106,5 +106,11 @@ void main() { expect(() => list.subList(3, 1), throwsA(TypeMatcher())); expect(() => list.subList(2, 10), throwsA(TypeMatcher())); }); + + test("access dart list", () { + List list = listOf(["a", "b", "c"]).list; + expect(list.length, 3); + expect(list, equals(["a", "b", "c"])); + }); }); } diff --git a/test/collection/map_empty_test.dart b/test/collection/map_empty_test.dart index 1996aa3e..4262a0ba 100644 --- a/test/collection/map_empty_test.dart +++ b/test/collection/map_empty_test.dart @@ -2,7 +2,7 @@ import 'package:dart_kollection/dart_kollection.dart'; import 'package:test/test.dart'; void main() { - group('empty list', () { + group('empty map', () { test("has no elements", () { final empty = emptyMap(); expect(empty.size, equals(0)); @@ -46,7 +46,7 @@ void main() { expect(empty.get(null), isNull); }); - test("is equals to another empty list", () { + test("is equals to another empty map", () { final empty0 = emptyMap(); final empty1 = emptyMap(); @@ -69,5 +69,10 @@ void main() { expect(empty0, equals(empty1)); expect(empty0.hashCode, equals(empty1.hashCode)); }); + + test("access dart map", () { + final Map map = emptyMap().map; + expect(map.length, 0); + }); }); } diff --git a/test/collection/map_test.dart b/test/collection/map_test.dart new file mode 100644 index 00000000..a112c8b5 --- /dev/null +++ b/test/collection/map_test.dart @@ -0,0 +1,12 @@ +import 'package:dart_kollection/dart_kollection.dart'; +import 'package:test/test.dart'; + +void main() { + group('basic methods', () { + test("access dart map", () { + Map map = mapOf({"a": 1, "b": 2}).map; + expect(map.length, 2); + expect(map, equals({"a": 1, "b": 2})); + }); + }); +} diff --git a/test/collection/set_test.dart b/test/collection/set_test.dart index e1ed8a24..b3b4b2a2 100644 --- a/test/collection/set_test.dart +++ b/test/collection/set_test.dart @@ -77,5 +77,11 @@ void main() { expect(set0, isNot(equals(set3))); }); + + test("access dart set", () { + Set set = setOf(["a", "b", "c"]).set; + expect(set.length, 3); + expect(set, equals(Set.from(["a", "b", "c"]))); + }); }); } From cdc55c17ebf2d70d2a70644c0a5b28c74d65ca03 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 14:01:42 +0100 Subject: [PATCH 2/8] Fix comment --- lib/src/k_map.dart | 2 +- lib/src/k_set.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/k_map.dart b/lib/src/k_map.dart index 5c5df7d9..eb73ab3f 100644 --- a/lib/src/k_map.dart +++ b/lib/src/k_map.dart @@ -11,7 +11,7 @@ import 'package:dart_kollection/dart_kollection.dart'; */ abstract class KMap implements KMapExtension { /** - * dart interop list for time critical operations such as sorting + * dart interop map for time critical operations such as sorting */ Map get map; diff --git a/lib/src/k_set.dart b/lib/src/k_set.dart index f19da5b2..e484566e 100644 --- a/lib/src/k_set.dart +++ b/lib/src/k_set.dart @@ -8,7 +8,7 @@ import 'package:dart_kollection/dart_kollection.dart'; */ abstract class KSet implements KCollection { /** - * dart interop list for time critical operations such as sorting + * dart interop set for time critical operations such as sorting */ Set get set; From efb547fd67a8bd01bb80efb04a144c4a9b5e79e1 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 14:58:40 +0100 Subject: [PATCH 3/8] Allow code coverage report pub global run coverage:collect_coverage --port=8111 -o coverage.json --resume-isolates --wait-paused & dart --observe=8111 test/rxdart_test.dart & pub global run coverage:format_coverage --package-root=packages --report-on lib --in coverage.json --out lcov.info --lcov --- test/dart_kollection_test.dart | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/dart_kollection_test.dart diff --git a/test/dart_kollection_test.dart b/test/dart_kollection_test.dart new file mode 100644 index 00000000..c40bcdf6 --- /dev/null +++ b/test/dart_kollection_test.dart @@ -0,0 +1,20 @@ +import 'collection/iterable_extensions_test.dart' as iterable_extensions_test; +import 'collection/list_mutable_test.dart' as list_mutable_test; +import 'collection/list_test.dart' as list_test; +import 'collection/map_empty_test.dart' as map_empty_test; +import 'collection/map_extensions_test.dart' as map_extensions_test; +import 'collection/map_test.dart' as map_test; +import 'collection/set_test.dart' as set_test; +import 'collections_test.dart' as collections_test; + +main() { + collections_test.main(); + iterable_extensions_test.main(); + list_test.main(); + list_mutable_test.main(); + list_test.main(); + map_empty_test.main(); + map_extensions_test.main(); + map_test.main(); + set_test.main(); +} From ef99d109b40b8ef7e841cd2c8de9193d4a1c81f1 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 15:01:43 +0100 Subject: [PATCH 4/8] Add travis config --- travis.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 travis.yml diff --git a/travis.yml b/travis.yml new file mode 100644 index 00000000..1fd80d6d --- /dev/null +++ b/travis.yml @@ -0,0 +1,20 @@ +language: dart +# Speed up builds by using containerization. +sudo: false +dart: + - 2.1.0 +with_content_shell: false +before_install: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start +script: + - set -e + - sh tool/check_format.sh + - dartanalyzer --fatal-infos --fatal-warnings ./ + - pub run test test/dart_kollection_test.dart + - pub global activate coverage + - pub global run coverage:collect_coverage --port=8111 -o coverage.json --resume-isolates --wait-paused & + - dart --observe=8111 test/dart_kollection_test.dart + - pub global run coverage:format_coverage --package-root=packages --report-on lib --in coverage.json --out lcov.info --lcov +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file From 1b0619c96af4b5548ee04dba3fcdacbb2886824e Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 15:05:56 +0100 Subject: [PATCH 5/8] Remove comment --- travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/travis.yml b/travis.yml index 1fd80d6d..bd5cd306 100644 --- a/travis.yml +++ b/travis.yml @@ -1,5 +1,4 @@ language: dart -# Speed up builds by using containerization. sudo: false dart: - 2.1.0 From eb7992f7519d893fd8c643dfbac7baff59bd48bb Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 15:08:39 +0100 Subject: [PATCH 6/8] Revert "Remove comment" This reverts commit 1b0619c96af4b5548ee04dba3fcdacbb2886824e. --- travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/travis.yml b/travis.yml index bd5cd306..1fd80d6d 100644 --- a/travis.yml +++ b/travis.yml @@ -1,4 +1,5 @@ language: dart +# Speed up builds by using containerization. sudo: false dart: - 2.1.0 From 11982ce9901e342a02a1ff8d337b5cf90d2ddfdd Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 15:17:57 +0100 Subject: [PATCH 7/8] Add formatting check --- tool/check_format.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 tool/check_format.sh diff --git a/tool/check_format.sh b/tool/check_format.sh new file mode 100755 index 00000000..f8dcf72d --- /dev/null +++ b/tool/check_format.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# Determine which files have been modified and should be run through the formatter +dart_files=$(git diff --cached --name-only --diff-filter=ACM | grep '.dart$') +[ -z "$dart_files" ] && exit 0 + +# Run dartfmt to check if the modified files are properly formatted. +unformatted=$(dartfmt -n ${dart_files}) +[ -z "$unformatted" ] && exit 0 + +# If the files are not properly formatted. Print message and fail. +echo >&2 "The following dart files must be formatted with dartfmt. Please run: dartfmt -w ./**/*.dart from the root of the git repository." +for fn in ${unformatted}; do + echo >&2 "./$fn" +done + +exit 1 \ No newline at end of file From ae6faecfa38bd00be62b1aaa26ea04704ade7f51 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Thu, 29 Nov 2018 15:20:34 +0100 Subject: [PATCH 8/8] Fix packages --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bd5cd306..6baf06bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,6 @@ script: - pub global activate coverage - pub global run coverage:collect_coverage --port=8111 -o coverage.json --resume-isolates --wait-paused & - dart --observe=8111 test/dart_kollection_test.dart - - pub global run coverage:format_coverage --package-root=packages --report-on lib --in coverage.json --out lcov.info --lcov + - pub global run coverage:format_coverage --packages=.packages --report-on lib --in coverage.json --out lcov.info --lcov after_success: - bash <(curl -s https://codecov.io/bash) \ No newline at end of file