Navaron Bracke

add TorchState test

  1 +import 'package:flutter_test/flutter_test.dart';
  2 +import 'package:mobile_scanner/src/enums/torch_state.dart';
  3 +
  4 +void main() {
  5 + group('$TorchState tests', () {
  6 + test('can be created from raw value', () {
  7 + const values = <int, TorchState>{
  8 + 0: TorchState.off,
  9 + 1: TorchState.on,
  10 + };
  11 +
  12 + for (final MapEntry<int, TorchState> entry in values.entries) {
  13 + final TorchState result = TorchState.fromRawValue(entry.key);
  14 +
  15 + expect(result, entry.value);
  16 + }
  17 + });
  18 +
  19 + test('invalid raw value throws argument error', () {
  20 + const int negative = -1;
  21 + const int outOfRange = 2;
  22 +
  23 + expect(() => TorchState.fromRawValue(negative), throwsArgumentError);
  24 + expect(() => TorchState.fromRawValue(outOfRange), throwsArgumentError);
  25 + });
  26 +
  27 + test('can be converted to raw value', () {
  28 + const values = <TorchState, int>{
  29 + TorchState.off: 0,
  30 + TorchState.on: 1,
  31 + };
  32 +
  33 + for (final MapEntry<TorchState, int> entry in values.entries) {
  34 + final int result = entry.key.rawValue;
  35 +
  36 + expect(result, entry.value);
  37 + }
  38 + });
  39 + });
  40 +}