diff --git a/example/test.dart b/example/test.dart deleted file mode 100644 index f2d877b..0000000 --- a/example/test.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:fast_immutable_collections/fast_immutable_collections.dart'; - -void main(List args) { - IList list = const IList.empty(); - //list = list.flush; - list = list.addAll(["abc"]); - final expanded = list.expand((p0) => p0.runes); - print(expanded); -} diff --git a/lib/src/ilist/ilist.dart b/lib/src/ilist/ilist.dart index a24e1eb..e6ee13e 100644 --- a/lib/src/ilist/ilist.dart +++ b/lib/src/ilist/ilist.dart @@ -15,7 +15,12 @@ import "l_add_all.dart"; import "l_flat.dart"; @immutable -class IListEmpty extends IList { +class IListEmpty // ignore: must_be_immutable + extends IList { + /// Creates a empty list. + /// + /// IMPORTANT: You must always use the `const` keyword. + /// It's always wrong to use an `IListEmpty()` which is not constant. @literal const IListEmpty([this.config = const ConfigList()]) : super._gen(); @@ -29,7 +34,6 @@ class IListEmpty extends IList { /// Nothing happens when you flush a empty list, by definition. @override - // ignore: non_const_call_to_literal_constructor IListEmpty get flush => this; @override @@ -78,15 +82,6 @@ class IListConst // ignore: must_be_immutable [this.config = const ConfigList()]) : super._gen(); - /// Creates a empty constant list. - /// - /// IMPORTANT: You must always use the `const` keyword. - /// It's always wrong to use an `IListConst.empty()` which is not constant. - @literal - const IListConst.empty([this.config = const ConfigList()]) - : _list = const [], - super._gen(); - final List _list; @override diff --git a/test/ilist/ilist_empty_test.dart b/test/ilist/ilist_empty_test.dart new file mode 100644 index 0000000..b3753bb --- /dev/null +++ b/test/ilist/ilist_empty_test.dart @@ -0,0 +1,49 @@ +// Developed by Marcelo Glasberg (2021) https://glasberg.dev and https://github.com/marcglasberg +// and Philippe Fanaro https://github.com/psygo +// For more info, see: https://pub.dartlang.org/packages/fast_immutable_collections +import 'package:fast_immutable_collections/fast_immutable_collections.dart'; +import 'package:test/test.dart'; + +void main() { + setUp(() { + ImmutableCollection.resetAllConfigurations(); + ImmutableCollection.autoFlush = false; + }); + + + test("Runtime Type", () { + expect(const IListEmpty(), isA()); + expect(const IListEmpty(), isA()); + expect(const IListEmpty(), isA>()); + expect(const IListEmpty(), isA>()); + + expect(const IListEmpty(), isA()); + expect(const IListEmpty(), isA()); + expect(const IListEmpty(), isA>()); + expect(const IListEmpty(), isA>()); + }); + + test("Make sure the IListEmpty can be modified and later iterated", () { + IList list = const IList.empty(); + list = list.addAll(["a", "b", "c"]); + list.forEach((_) { }); + list = list.add("d"); + list.forEach((_) { }); + list = list.remove("a"); + list.forEach((_) { }); + }); + + test("Make sure the internal list is List, and not List", () { + const l1 = IListEmpty(); + expect(l1.runtimeType.toString(), 'IListEmpty'); + + const l2 = IListConst([1, 2, 3]); + expect(l2.runtimeType.toString(), 'IListConst'); + + final l3 = l1.addAll(l2); + expect(l3.runtimeType.toString(), 'IListImpl'); + + final result = l3.where((int i) => i == 2).toList(); + expect(result, [2]); + }); +}