LCOV - code coverage report

Current view
top level - src/converters - converter.dart
Test
lcov.info
Date
2025-03-26
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines4040100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import '../exceptions/worker_exception.dart';
2import '../typedefs.dart';
3
4abstract class Converter {
528 const Converter();
6
711 static bool isNumber<T>() => (T == int || T == double);
8
910 static bool isIdentity<T>(Cast<T> cast) => (cast == identity<T>);
10
1120 static T identity<T>(dynamic x) => (x is T)
12 ? x
131 : throw WorkerException(
142 'TypeError: ${x.runtimeType} is not a subtype of $T');
15
168 static List<T> _castList<T>(dynamic x) => (x is List<T>)
17 ? x
182 : ((x is List) ? x.cast<T>() : (x as Iterable).cast<T>().toList());
19
202 static Cast<List<T>> _mapList<T>(Cast<T> op) =>
216 (x) => (x as Iterable).map(op).toList();
22
234 static Set<T> _castSet<T>(dynamic x) => (x is Set<T>)
24 ? x
255 : ((x is Set) ? x.cast<T>() : (x as Iterable).cast<T>().toSet());
26
271 static Cast<Set<T>> _mapSet<T>(Cast<T> op) =>
283 (x) => (x as Iterable).map(op).toSet();
29
304 static Map<K, V> _castMap<K, V>(dynamic x) =>
315 (x is Map<K, V>) ? x : (x as Map).cast<K, V>();
32
331 static Cast<Map<K, V>> _mapMap<K, V>(Cast<K> kop, Cast<V> vop) =>
346 (x) => (x as Map).map((k, v) => MapEntry(kop(k), vop(v)));
35
363 static Cast<T?> allowNull<T extends Object>(Cast<T> op) =>
377 isIdentity(op) ? identity<T?> : ((x) => (x == null) ? null : op(x));
38
39 // non-nullable value
40 Cast<T> value<T extends Object>();
41
42 // list (of non-nullable T)
434 Cast<List<T>> list<T extends Object>([Cast<T>? cast]) {
444 final op = cast ?? value<T>();
456 return isIdentity<T>(op) ? _castList<T> : _mapList(op);
46 }
47
48 // list (of nullable T)
491 Cast<List<T?>> nlist<T extends Object>([Cast<T>? cast]) {
501 final op = allowNull(cast ?? value<T>());
512 return isIdentity<T?>(op) ? _castList<T?> : _mapList(op);
52 }
53
54 // set (of non-nullable T)
552 Cast<Set<T>> set<T extends Object>([Cast<T>? cast]) {
562 final op = cast ?? value<T>();
573 return isIdentity<T>(op) ? _castSet<T> : _mapSet<T>(op);
58 }
59
60 // set (of nullable T)
611 Cast<Set<T?>> nset<T extends Object>([Cast<T>? cast]) {
622 var op = allowNull(cast ?? value<T>());
632 return isIdentity<T?>(op) ? _castSet<T?> : _mapSet<T?>(op);
64 }
65
66 // map (of non-nullable K, V)
673 Cast<Map<K, V>> map<K extends Object, V extends Object>(
68 {Cast<K>? kcast, Cast<V>? vcast}) {
696 final kop = kcast ?? value<K>(), vop = vcast ?? value<V>();
706 return (isIdentity<K>(kop) && isIdentity<V>(vop))
71 ? _castMap<K, V>
721 : _mapMap<K, V>(kop, vop);
73 }
74
75 // map (of non-nullable K, nullable V)
762 Cast<Map<K, V?>> nmap<K extends Object, V extends Object>(
77 {Cast<K>? kcast, Cast<V>? vcast}) {
786 final kop = kcast ?? value<K>(), vop = allowNull(vcast ?? value<V>());
794 return (isIdentity<K>(kop) && isIdentity<V?>(vop))
80 ? _castMap<K, V?>
811 : _mapMap<K, V?>(kop, vop);
82 }
83}
Choose Features