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