Showing
1 changed file
with
42 additions
and
0 deletions
test/enums/address_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/address_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$AddressType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, AddressType>{ | ||
| 8 | + 0: AddressType.unknown, | ||
| 9 | + 1: AddressType.work, | ||
| 10 | + 2: AddressType.home, | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + for (final MapEntry<int, AddressType> entry in values.entries) { | ||
| 14 | + final AddressType result = AddressType.fromRawValue(entry.key); | ||
| 15 | + | ||
| 16 | + expect(result, entry.value); | ||
| 17 | + } | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + test('invalid raw value creates unknown address type', () { | ||
| 21 | + final AddressType negative = AddressType.fromRawValue(-1); | ||
| 22 | + final AddressType outOfRange = AddressType.fromRawValue(3); | ||
| 23 | + | ||
| 24 | + expect(negative, AddressType.unknown); | ||
| 25 | + expect(outOfRange, AddressType.unknown); | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + test('can be converted to raw value', () { | ||
| 29 | + const values = <AddressType, int>{ | ||
| 30 | + AddressType.unknown: 0, | ||
| 31 | + AddressType.work: 1, | ||
| 32 | + AddressType.home: 2, | ||
| 33 | + }; | ||
| 34 | + | ||
| 35 | + for (final MapEntry<AddressType, int> entry in values.entries) { | ||
| 36 | + final int result = entry.key.rawValue; | ||
| 37 | + | ||
| 38 | + expect(result, entry.value); | ||
| 39 | + } | ||
| 40 | + }); | ||
| 41 | + }); | ||
| 42 | +} |
-
Please register or login to post a comment