Showing
1 changed file
with
62 additions
and
0 deletions
test/enums/barcode_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/barcode_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$BarcodeType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, BarcodeType>{ | ||
| 8 | + 0: BarcodeType.unknown, | ||
| 9 | + 1: BarcodeType.contactInfo, | ||
| 10 | + 2: BarcodeType.email, | ||
| 11 | + 3: BarcodeType.isbn, | ||
| 12 | + 4: BarcodeType.phone, | ||
| 13 | + 5: BarcodeType.product, | ||
| 14 | + 6: BarcodeType.sms, | ||
| 15 | + 7: BarcodeType.text, | ||
| 16 | + 8: BarcodeType.url, | ||
| 17 | + 9: BarcodeType.wifi, | ||
| 18 | + 10: BarcodeType.geo, | ||
| 19 | + 11: BarcodeType.calendarEvent, | ||
| 20 | + 12: BarcodeType.driverLicense, | ||
| 21 | + }; | ||
| 22 | + | ||
| 23 | + for (final MapEntry<int, BarcodeType> entry in values.entries) { | ||
| 24 | + final BarcodeType result = BarcodeType.fromRawValue(entry.key); | ||
| 25 | + | ||
| 26 | + expect(result, entry.value); | ||
| 27 | + } | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + test('invalid raw value creates unknown barcode type', () { | ||
| 31 | + final BarcodeType negative = BarcodeType.fromRawValue(-1); | ||
| 32 | + final BarcodeType outOfRange = BarcodeType.fromRawValue(13); | ||
| 33 | + | ||
| 34 | + expect(negative, BarcodeType.unknown); | ||
| 35 | + expect(outOfRange, BarcodeType.unknown); | ||
| 36 | + }); | ||
| 37 | + | ||
| 38 | + test('can be converted to raw value', () { | ||
| 39 | + const values = <BarcodeType, int>{ | ||
| 40 | + BarcodeType.unknown: 0, | ||
| 41 | + BarcodeType.contactInfo: 1, | ||
| 42 | + BarcodeType.email: 2, | ||
| 43 | + BarcodeType.isbn: 3, | ||
| 44 | + BarcodeType.phone: 4, | ||
| 45 | + BarcodeType.product: 5, | ||
| 46 | + BarcodeType.sms: 6, | ||
| 47 | + BarcodeType.text: 7, | ||
| 48 | + BarcodeType.url: 8, | ||
| 49 | + BarcodeType.wifi: 9, | ||
| 50 | + BarcodeType.geo: 10, | ||
| 51 | + BarcodeType.calendarEvent: 11, | ||
| 52 | + BarcodeType.driverLicense: 12, | ||
| 53 | + }; | ||
| 54 | + | ||
| 55 | + for (final MapEntry<BarcodeType, int> entry in values.entries) { | ||
| 56 | + final int result = entry.key.rawValue; | ||
| 57 | + | ||
| 58 | + expect(result, entry.value); | ||
| 59 | + } | ||
| 60 | + }); | ||
| 61 | + }); | ||
| 62 | +} |
-
Please register or login to post a comment