Showing
1 changed file
with
66 additions
and
0 deletions
test/enums/barcode_format_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$BarcodeFormat tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, BarcodeFormat>{ | ||
| 8 | + -1: BarcodeFormat.unknown, | ||
| 9 | + 0: BarcodeFormat.all, | ||
| 10 | + 1: BarcodeFormat.code128, | ||
| 11 | + 2: BarcodeFormat.code39, | ||
| 12 | + 4: BarcodeFormat.code93, | ||
| 13 | + 8: BarcodeFormat.codebar, | ||
| 14 | + 16: BarcodeFormat.dataMatrix, | ||
| 15 | + 32: BarcodeFormat.ean13, | ||
| 16 | + 64: BarcodeFormat.ean8, | ||
| 17 | + 128: BarcodeFormat.itf, | ||
| 18 | + 256: BarcodeFormat.qrCode, | ||
| 19 | + 512: BarcodeFormat.upcA, | ||
| 20 | + 1024: BarcodeFormat.upcE, | ||
| 21 | + 2048: BarcodeFormat.pdf417, | ||
| 22 | + 4096: BarcodeFormat.aztec, | ||
| 23 | + }; | ||
| 24 | + | ||
| 25 | + for (final MapEntry<int, BarcodeFormat> entry in values.entries) { | ||
| 26 | + final BarcodeFormat result = BarcodeFormat.fromRawValue(entry.key); | ||
| 27 | + | ||
| 28 | + expect(result, entry.value); | ||
| 29 | + } | ||
| 30 | + }); | ||
| 31 | + | ||
| 32 | + test('invalid raw value creates unknown barcode format', () { | ||
| 33 | + final BarcodeFormat negative = BarcodeFormat.fromRawValue(-2); | ||
| 34 | + final BarcodeFormat outOfRange = BarcodeFormat.fromRawValue(4097); | ||
| 35 | + | ||
| 36 | + expect(negative, BarcodeFormat.unknown); | ||
| 37 | + expect(outOfRange, BarcodeFormat.unknown); | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + test('can be converted to raw value', () { | ||
| 41 | + const values = <BarcodeFormat, int>{ | ||
| 42 | + BarcodeFormat.unknown: -1, | ||
| 43 | + BarcodeFormat.all: 0, | ||
| 44 | + BarcodeFormat.code128: 1, | ||
| 45 | + BarcodeFormat.code39: 2, | ||
| 46 | + BarcodeFormat.code93: 4, | ||
| 47 | + BarcodeFormat.codebar: 8, | ||
| 48 | + BarcodeFormat.dataMatrix: 16, | ||
| 49 | + BarcodeFormat.ean13: 32, | ||
| 50 | + BarcodeFormat.ean8: 64, | ||
| 51 | + BarcodeFormat.itf: 128, | ||
| 52 | + BarcodeFormat.qrCode: 256, | ||
| 53 | + BarcodeFormat.upcA: 512, | ||
| 54 | + BarcodeFormat.upcE: 1024, | ||
| 55 | + BarcodeFormat.pdf417: 2048, | ||
| 56 | + BarcodeFormat.aztec: 4096, | ||
| 57 | + }; | ||
| 58 | + | ||
| 59 | + for (final MapEntry<BarcodeFormat, int> entry in values.entries) { | ||
| 60 | + final int result = entry.key.rawValue; | ||
| 61 | + | ||
| 62 | + expect(result, entry.value); | ||
| 63 | + } | ||
| 64 | + }); | ||
| 65 | + }); | ||
| 66 | +} |
-
Please register or login to post a comment