diff --git a/lib/src/tags_impl.dart b/lib/src/tags_impl.dart index 1de9e59..4708b3b 100644 --- a/lib/src/tags_impl.dart +++ b/lib/src/tags_impl.dart @@ -5,7 +5,7 @@ import 'package:tekartik_common_utils/string_utils.dart'; /// Tags are a list or trimmed string. abstract class Tags { /// Tags from a list of strings. - factory Tags.fromList({List? tags}) { + factory Tags.fromList(List? tags) { return _Tags(tags); } @@ -84,14 +84,6 @@ abstract class TagsCondition { /// Private String _toInnerText(); - /// Private - factory TagsCondition._any(List conditions) { - assert(conditions.isNotEmpty); - if (conditions.length == 1) { - return conditions.first; - } - return _TagsConditionAny(conditions); - } factory TagsCondition._or( TagsCondition condition1, TagsCondition condition2) { if (condition2 is _TagsConditionAny) { @@ -105,15 +97,6 @@ abstract class TagsCondition { } return _TagsConditionAny([condition1, condition2]); } - - factory TagsCondition._all(List conditions) { - assert(conditions.isNotEmpty); - if (conditions.length == 1) { - return conditions.first; - } - return _TagsConditionAll(conditions); - } - factory TagsCondition._and( TagsCondition condition1, TagsCondition condition2) { if (condition2 is _TagsConditionAll) { diff --git a/test/tags_test.dart b/test/tags_test.dart index 5f3981b..2030cbd 100644 --- a/test/tags_test.dart +++ b/test/tags_test.dart @@ -4,17 +4,27 @@ import 'package:tekartik_common_utils/src/tags_impl.dart' import 'package:tekartik_common_utils/tags.dart'; import 'package:test/test.dart' hide Tags; -Tags _t(String text) => Tags.fromText(text); +Tags _t(String? text) => Tags.fromText(text); TagsCondition _c(String expression) => TagsCondition(expression); Future main() async { group('tags', () { test('tags', () { + expect(_t(null).toText(), ''); + expect(_t(null).toTextOrNull(), isNull); + expect(_t(null).toList(), []); + expect(_t(null).toListOrNull(), isNull); expect(_t('test').toText(), 'test'); expect(_t(' test ').toText(), 'test'); - expect(_t('test1, test2').toText(), 'test1,test2'); - expect(_t(' test1, test2 ').toText(), 'test1,test2'); + var tags = _t('test1, test2'); + expect(tags.toText(), 'test1,test2'); + expect(tags.toTextOrNull(), 'test1,test2'); + expect(tags.toList(), ['test1', 'test2']); + expect(tags.toListOrNull(), ['test1', 'test2']); + expect(Tags.fromList(null).toText(), ''); + expect(Tags.fromList(['test1']).toText(), 'test1'); + expect(Tags.fromList(['test1', 'test2']).toText(), 'test1,test2'); }); test('simple', () { var tags = _t('test');