Skip to content

Commit d14ff4b

Browse files
committed
fixed tests, reorganized tests, fixed docs
1 parent 1460876 commit d14ff4b

10 files changed

+110
-134
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.0.2
4+
5+
* Updated docs due to changes in `singleOrNull` and `singleOrNullWhere` API
6+
* Fixed tests for `singleOrNull` and `singleOrNullWhere`
7+
38
## 2.0.1
49

510
* Added collection dependency

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This package will help you to reduce the amount of boilerplate code by adding fo
1717

1818
* getter `lastOrNull` and method `lastOrNullWhere` for getting last value, and if it will not be found returns `null`
1919

20-
* getter `singleOrNull` and method `singleOrNullWhere` for getting single value, and if it will not be found returns `null`, and if there will be too many elements it'll throw the `StateError`
20+
* getter `singleOrNull` and method `singleOrNullWhere` for getting single value, and if it will not be found returns `null`, and if there will be too many elements it'll also return `null`
2121

2222
* method `mapList`, which maps collection and casts it to `List`
2323

lib/src/iterable.common.extension.dart

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ extension IterableCommonExtension<T> on Iterable<T> {
2525

2626
/// Checks that this iterable has only one element, and returns that element.
2727
///
28-
/// If `this` has no element, the result is [null].
29-
/// Throws a [StateError] if `this` has more than one element.
28+
/// Returns [null] if there are either no elements or more than one element.
3029
T? get singleOrNull => this.singleWhereOrNull((_) => true);
3130

3231
/// Returns the first element that satisfies the given predicate [test].
@@ -50,10 +49,8 @@ extension IterableCommonExtension<T> on Iterable<T> {
5049

5150
/// Returns the single element that satisfies [test].
5251
///
53-
/// Checks elements to see if `test(element)` returns true.
54-
/// If exactly one element satisfies [test], that element is returned.
55-
/// If more than one matching element is found, throws [StateError].
56-
/// If no matching element is found, returns [null].
52+
/// Returns [null] if there are either no elements or more than one element
53+
/// satisfying [test].
5754
T? singleOrNullWhere(bool test(T element)) => this.singleWhereOrNull(test);
5855

5956
/// Maps [Iterable] and casts it to a [List].

pubspec.lock

+30-51
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ packages:
77
name: _fe_analyzer_shared
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "14.0.0"
10+
version: "18.0.0"
1111
analyzer:
1212
dependency: transitive
1313
description:
1414
name: analyzer
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "0.41.2"
17+
version: "1.2.0"
1818
args:
1919
dependency: transitive
2020
description:
2121
name: args
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.5.2"
24+
version: "2.0.0"
2525
async:
2626
dependency: transitive
2727
description:
@@ -63,56 +63,56 @@ packages:
6363
name: convert
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "2.1.1"
66+
version: "3.0.0"
6767
coverage:
6868
dependency: transitive
6969
description:
7070
name: coverage
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "0.15.2"
73+
version: "1.0.2"
7474
crypto:
7575
dependency: transitive
7676
description:
7777
name: crypto
7878
url: "https://pub.dartlang.org"
7979
source: hosted
80-
version: "2.1.3"
81-
glob:
80+
version: "3.0.0"
81+
file:
8282
dependency: transitive
8383
description:
84-
name: glob
84+
name: file
8585
url: "https://pub.dartlang.org"
8686
source: hosted
87-
version: "1.2.0"
88-
http:
87+
version: "6.1.0"
88+
glob:
8989
dependency: transitive
9090
description:
91-
name: http
91+
name: glob
9292
url: "https://pub.dartlang.org"
9393
source: hosted
94-
version: "0.12.0+2"
94+
version: "2.0.0"
9595
http_multi_server:
9696
dependency: transitive
9797
description:
9898
name: http_multi_server
9999
url: "https://pub.dartlang.org"
100100
source: hosted
101-
version: "2.1.0"
101+
version: "3.0.0"
102102
http_parser:
103103
dependency: transitive
104104
description:
105105
name: http_parser
106106
url: "https://pub.dartlang.org"
107107
source: hosted
108-
version: "3.1.3"
108+
version: "4.0.0"
109109
io:
110110
dependency: transitive
111111
description:
112112
name: io
113113
url: "https://pub.dartlang.org"
114114
source: hosted
115-
version: "0.3.3"
115+
version: "1.0.0"
116116
js:
117117
dependency: transitive
118118
description:
@@ -147,42 +147,21 @@ packages:
147147
name: mime
148148
url: "https://pub.dartlang.org"
149149
source: hosted
150-
version: "0.9.6+3"
151-
node_interop:
152-
dependency: transitive
153-
description:
154-
name: node_interop
155-
url: "https://pub.dartlang.org"
156-
source: hosted
157-
version: "1.0.3"
158-
node_io:
159-
dependency: transitive
160-
description:
161-
name: node_io
162-
url: "https://pub.dartlang.org"
163-
source: hosted
164-
version: "1.0.1+2"
150+
version: "1.0.0"
165151
node_preamble:
166152
dependency: transitive
167153
description:
168154
name: node_preamble
169155
url: "https://pub.dartlang.org"
170156
source: hosted
171-
version: "1.4.8"
157+
version: "2.0.0"
172158
package_config:
173159
dependency: transitive
174160
description:
175161
name: package_config
176162
url: "https://pub.dartlang.org"
177163
source: hosted
178-
version: "1.9.3"
179-
package_resolver:
180-
dependency: transitive
181-
description:
182-
name: package_resolver
183-
url: "https://pub.dartlang.org"
184-
source: hosted
185-
version: "1.0.10"
164+
version: "2.0.0"
186165
path:
187166
dependency: transitive
188167
description:
@@ -210,35 +189,35 @@ packages:
210189
name: pub_semver
211190
url: "https://pub.dartlang.org"
212191
source: hosted
213-
version: "1.4.2"
192+
version: "2.0.0"
214193
shelf:
215194
dependency: transitive
216195
description:
217196
name: shelf
218197
url: "https://pub.dartlang.org"
219198
source: hosted
220-
version: "0.7.5"
199+
version: "1.1.0"
221200
shelf_packages_handler:
222201
dependency: transitive
223202
description:
224203
name: shelf_packages_handler
225204
url: "https://pub.dartlang.org"
226205
source: hosted
227-
version: "1.0.4"
206+
version: "3.0.0"
228207
shelf_static:
229208
dependency: transitive
230209
description:
231210
name: shelf_static
232211
url: "https://pub.dartlang.org"
233212
source: hosted
234-
version: "0.2.8"
213+
version: "1.0.0"
235214
shelf_web_socket:
236215
dependency: transitive
237216
description:
238217
name: shelf_web_socket
239218
url: "https://pub.dartlang.org"
240219
source: hosted
241-
version: "0.2.3"
220+
version: "1.0.1"
242221
source_map_stack_trace:
243222
dependency: transitive
244223
description:
@@ -294,21 +273,21 @@ packages:
294273
name: test
295274
url: "https://pub.dartlang.org"
296275
source: hosted
297-
version: "1.16.5"
276+
version: "1.16.8"
298277
test_api:
299278
dependency: transitive
300279
description:
301280
name: test_api
302281
url: "https://pub.dartlang.org"
303282
source: hosted
304-
version: "0.2.19"
283+
version: "0.3.0"
305284
test_core:
306285
dependency: transitive
307286
description:
308287
name: test_core
309288
url: "https://pub.dartlang.org"
310289
source: hosted
311-
version: "0.3.15"
290+
version: "0.3.19"
312291
typed_data:
313292
dependency: transitive
314293
description:
@@ -322,21 +301,21 @@ packages:
322301
name: vm_service
323302
url: "https://pub.dartlang.org"
324303
source: hosted
325-
version: "2.1.1"
304+
version: "6.1.0+1"
326305
watcher:
327306
dependency: transitive
328307
description:
329308
name: watcher
330309
url: "https://pub.dartlang.org"
331310
source: hosted
332-
version: "0.9.7+12"
311+
version: "1.0.0"
333312
web_socket_channel:
334313
dependency: transitive
335314
description:
336315
name: web_socket_channel
337316
url: "https://pub.dartlang.org"
338317
source: hosted
339-
version: "1.1.0"
318+
version: "2.0.0"
340319
webkit_inspection_protocol:
341320
dependency: transitive
342321
description:
@@ -350,6 +329,6 @@ packages:
350329
name: yaml
351330
url: "https://pub.dartlang.org"
352331
source: hosted
353-
version: "2.2.0"
332+
version: "3.1.0"
354333
sdks:
355334
dart: ">=2.12.0 <3.0.0"

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: flinq
22
version: 2.0.1
33
homepage: https://github.com/marchdev-tk/flinq
4+
issue_tracker: https://github.com/marchdev-tk/flinq/issues
45
description: Extended capabilities for collections. It's a bunch of shortcuts to avoid unnecesary boilerplate work with collections.
56

67
environment:

test/flinq_test.dart

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'src/iterable.comparable.test.dart';
6-
import 'src/iterable.common.test.dart';
7-
import 'src/iterable.math.test.dart';
8-
import 'src/iterable.set.test.dart';
5+
import 'package:test/test.dart';
6+
import 'package:flinq/flinq.dart';
97

8+
part 'src/iterable.comparable.test.dart';
9+
part 'src/iterable.common.test.dart';
10+
part 'src/iterable.math.test.dart';
11+
part 'src/iterable.set.test.dart';
12+
13+
final Iterable<int> _emptyCollection = <int>[];
14+
final Iterable<int> _oneItemCollection = <int>[7];
15+
final Iterable<int> _manyCollection = <int>[4, 3, 6, 1, 9, 5];
1016
/// to run tests use `pub run test`
11-
void main() {
17+
void main() {
1218
iterableCommonTests();
1319
iterableComparableTests();
1420
iterableMathTests();

test/src/iterable.common.test.dart

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:test/test.dart';
6-
import 'package:flinq/flinq.dart';
7-
8-
final Iterable<int> _emptyCollection = <int>[];
9-
final Iterable<int> _oneItemCollection = <int>[7];
10-
final Iterable<int> _manyCollection = <int>[4, 3, 6, 1, 9, 5];
5+
part of '../flinq_test.dart';
116

127
void iterableCommonTests() {
138
firstOrNullTests();
@@ -65,8 +60,7 @@ void singleOrNullTests() {
6560
);
6661
test(
6762
'Iterable.singleOrNull on collection with many elements',
68-
() => expect(
69-
() => _manyCollection.singleOrNull, throwsA(TypeMatcher<StateError>())),
63+
() => expect(_manyCollection.singleOrNull, null),
7064
);
7165
}
7266

@@ -135,8 +129,7 @@ void singleOrNullWhereTests() {
135129
);
136130
test(
137131
'Iterable.singleOrNullWhere on collection with many elements, too many',
138-
() => expect(() => _manyCollection.singleOrNullWhere((_) => _ > 3),
139-
throwsA(TypeMatcher<StateError>())),
132+
() => expect(_manyCollection.singleOrNull, null),
140133
);
141134
}
142135

test/src/iterable.comparable.test.dart

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:test/test.dart';
6-
import 'package:flinq/flinq.dart';
7-
8-
final Iterable<int> _emptyCollection = <int>[];
9-
final Iterable<int> _oneItemCollection = <int>[7];
10-
final Iterable<int> _manyCollection = <int>[4, 3, 6, 1, 9, 5];
5+
part of '../flinq_test.dart';
116

127
void iterableComparableTests() {
138
minTests();

test/src/iterable.math.test.dart

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:test/test.dart';
6-
import 'package:flinq/flinq.dart';
7-
8-
final Iterable<int> _emptyCollection = <int>[];
9-
final Iterable<int> _oneItemCollection = <int>[7];
10-
final Iterable<int> _manyCollection = <int>[4, 3, 6, 1, 9, 5];
5+
part of '../flinq_test.dart';
116

127
void iterableMathTests() {
138
sumTests();

0 commit comments

Comments
 (0)