bit_field_test.dart 1.37 KB
Newer Older
1 2 3 4
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
@TestOn('!chrome')

7
import 'package:flutter/foundation.dart';
8
import '../flutter_test_alternative.dart';
9

10
enum _TestEnum { a, b, c, d, e, f, g, h, }
11 12 13

void main() {
  test('BitField control test', () {
14
    final BitField<_TestEnum> field = BitField<_TestEnum>(8);
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

    expect(field[_TestEnum.d], isFalse);

    field[_TestEnum.d] = true;
    field[_TestEnum.e] = true;

    expect(field[_TestEnum.c], isFalse);
    expect(field[_TestEnum.d], isTrue);
    expect(field[_TestEnum.e], isTrue);

    field[_TestEnum.e] = false;

    expect(field[_TestEnum.c], isFalse);
    expect(field[_TestEnum.d], isTrue);
    expect(field[_TestEnum.e], isFalse);

    field.reset();

    expect(field[_TestEnum.c], isFalse);
    expect(field[_TestEnum.d], isFalse);
    expect(field[_TestEnum.e], isFalse);

    field.reset(true);

    expect(field[_TestEnum.c], isTrue);
    expect(field[_TestEnum.d], isTrue);
    expect(field[_TestEnum.e], isTrue);
  });

  test('BitField.filed control test', () {
45
    final BitField<_TestEnum> field1 = BitField<_TestEnum>.filled(8, true);
46 47 48

    expect(field1[_TestEnum.d], isTrue);

49
    final BitField<_TestEnum> field2 = BitField<_TestEnum>.filled(8, false);
50 51 52 53

    expect(field2[_TestEnum.d], isFalse);
  });
}