v1.0.0 - Initial release (#1)
CI and Release / format (push) Successful in 34s
CI and Release / analyze (push) Successful in 26s
CI and Release / test (push) Successful in 48s
CI and Release / pana (push) Successful in 2m9s
CI and Release / version-and-changelog (push) Successful in 20s
CI and Release / publish (push) Failing after 13s

Initial release 🥳

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2026-05-13 13:06:34 +02:00
parent 894f670cfd
commit 221faa9c97
11 changed files with 779 additions and 0 deletions
+138
View File
@@ -0,0 +1,138 @@
import 'package:list_or/list_or.dart';
import 'package:test/test.dart';
void main() {
group('ListOr Initialization', () {
test('creates from a single value', () {
final list = ListOr<String>('hello');
expect(list.length, equals(1));
expect(list.first, equals('hello'));
expect(list, equals(['hello']));
});
test('creates from a List', () {
final list = ListOr<int>([1, 2, 3]);
expect(list.length, equals(3));
expect(list, equals([1, 2, 3]));
});
test('creates from a Set (Iterable)', () {
final list = ListOr<int>({4, 5, 6});
expect(list.length, equals(3));
expect(list, equals([4, 5, 6]));
});
test('handles null correctly when T is nullable', () {
final list = ListOr<int?>(null);
expect(list.length, equals(1));
expect(list.first, isNull);
expect(list, equals([null]));
});
test('throws ArgumentError when null is passed but T is non-nullable', () {
expect(
() => ListOr<int>(null),
throwsA(
isA<ArgumentError>().having(
(e) => e.message,
'message',
contains('does not accept null values'),
),
),
);
});
test('throws ArgumentError on incompatible types', () {
expect(
() => ListOr<String>(123),
throwsA(
isA<ArgumentError>().having(
(e) => e.message,
'message',
contains('Value must be of type'),
),
),
);
});
});
group('ListOr Mutations (Bug Fix Verification)', () {
test('can add to a single-initialized list without throwing', () {
final list = ListOr<String>('Apple');
list.add('Banana'); // This would throw prior to the explicit override fix
expect(list, equals(['Apple', 'Banana']));
});
test('can addAll from another iterable', () {
final list = ListOr<int>(1);
list.addAll([2, 3, 4]);
expect(list, equals([1, 2, 3, 4]));
});
test('can insert at a specific index', () {
final list = ListOr<String>(['A', 'C']);
list.insert(1, 'B');
expect(list, equals(['A', 'B', 'C']));
});
test('can update elements using index operator', () {
final list = ListOr<int>([10, 20, 30]);
list[1] = 99;
expect(list, equals([10, 99, 30]));
});
test('can remove a specific element', () {
final list = ListOr<String>(['A', 'B', 'C']);
final result = list.remove('B');
expect(result, isTrue);
expect(list, equals(['A', 'C']));
});
test('can remove at a specific index', () {
final list = ListOr<int>([1, 2, 3]);
final removed = list.removeAt(0);
expect(removed, equals(1));
expect(list, equals([2, 3]));
});
test('can clear the list entirely', () {
final list = ListOr<String>(['A', 'B']);
list.clear();
expect(list, isEmpty);
expect(list.length, equals(0));
});
});
group('ListOr toString formatting', () {
test('formats a single element as just the element string', () {
final list = ListOr<String>('hello');
expect(list.toString(), equals('hello'));
});
test('formats multiple elements with standard list brackets', () {
final list = ListOr<int>([1, 2, 3]);
expect(list.toString(), equals('[1, 2, 3]'));
});
test('formats empty list with standard empty brackets', () {
final list = ListOr<String>(<String>[]);
expect(list.toString(), equals('[]'));
});
test('formats single null element correctly', () {
final list = ListOr<String?>(null);
expect(list.toString(), equals('null'));
});
});
}