Skip to content

Commit

Permalink
fix: tags implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Oct 14, 2024
1 parent 5ecd6f4 commit b07738c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
19 changes: 1 addition & 18 deletions lib/src/tags_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? tags}) {
factory Tags.fromList(List<String>? tags) {
return _Tags(tags);
}

Expand Down Expand Up @@ -84,14 +84,6 @@ abstract class TagsCondition {
/// Private
String _toInnerText();

/// Private
factory TagsCondition._any(List<TagsCondition> 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) {
Expand All @@ -105,15 +97,6 @@ abstract class TagsCondition {
}
return _TagsConditionAny([condition1, condition2]);
}

factory TagsCondition._all(List<TagsCondition> 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) {
Expand Down
16 changes: 13 additions & 3 deletions test/tags_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main() async {
group('tags', () {
test('tags', () {
expect(_t(null).toText(), '');
expect(_t(null).toTextOrNull(), isNull);
expect(_t(null).toList(), <String>[]);
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');
Expand Down

0 comments on commit b07738c

Please sign in to comment.