bit_field_test.dart 1.54 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
6
import 'package:flutter_test/flutter_test.dart';
7

8
// ignore: unused_field
9
enum _TestEnum { a, b, c, d, e, f, g, h }
10 11 12

void main() {
  test('BitField control test', () {
13
    final BitField<_TestEnum> field = BitField<_TestEnum>(8);
14 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

    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);
41
  }, skip: isBrowser); // [intended] BitField is not supported when compiled to Javascript.
42 43

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

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

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

    expect(field2[_TestEnum.d], isFalse);
51
  }, skip: isBrowser); // [intended] BitField is not supported when compiled to Javascript.
52
}