Skip to content

Commit

Permalink
option tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-givertzman committed Nov 20, 2023
1 parent 6fd2b5e commit 4491b60
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions test/unit/core/option/option_fold_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:hmi_core/hmi_core_option.dart';

class ForTestOptionOnly {
final String value;
ForTestOptionOnly(this.value);
}

void main() {
group('Option fold', () {
group('Option fold strong typed', () {
test('calls onSome function if it is instance of Some', () {
for(int i=-50; i<=50; i++) {
final Option<int> option = Some(i);
Expand All @@ -23,4 +27,38 @@ void main() {
expect(foldResult, equals('None'));
});
});
}
group('Option fold different types', () {
final testData = [
0x7FFFFFFFFFFFFFFF,
-0x8000000000000000,
ForTestOptionOnly("value"),
true,
false,
double.maxFinite,
double.minPositive
-double.maxFinite,
];
test('calls onSome function if it is instance of Some', () {
for(final value in testData) {
final Option option = Some(value);
final foldResult = switch(option) {
Some(:final value) => value,
None() => None,
};
expect(foldResult, equals(value));
}
});
test('calls onNone function if it is instance of None', () {
const Option option = None();
final foldResult = switch(option) {
Some(:final value) => value,
None() => None,
};
expect(foldResult, equals(None));
});
});
}




0 comments on commit 4491b60

Please sign in to comment.