feat: disallowed adding components to `ComponentController` (#121)

* feat: disallowed adding components to a ComponentController

* docs: rephrased text

* refactor: fixed variable typo

* feat: included addAll test
pull/127/head
Alejandro Santiago 4 years ago committed by GitHub
parent 40d0fd0995
commit e6fd5f90fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,6 +23,11 @@ abstract class ComponentController<T extends Component> extends Component {
); );
await super.addToParent(parent); await super.addToParent(parent);
} }
@override
Future<void> add(Component component) {
throw Exception('ComponentController cannot add other components.');
}
} }
/// Mixin that attaches a single [ComponentController] to a [Component]. /// Mixin that attaches a single [ComponentController] to a [Component].

@ -31,6 +31,7 @@ void main() {
); );
}, },
); );
flameTester.test( flameTester.test(
'throws AssertionError when not attached to controlled component', 'throws AssertionError when not attached to controlled component',
(game) async { (game) async {
@ -44,6 +45,35 @@ void main() {
); );
}, },
); );
flameTester.test(
'throws Exception when adding a component',
(game) async {
final component = ControlledComponent();
final controller = TestComponentController(component);
await expectLater(
() async => controller.add(Component()),
throwsException,
);
},
);
flameTester.test(
'throws Exception when adding multiple components',
(game) async {
final component = ControlledComponent();
final controller = TestComponentController(component);
await expectLater(
() async => controller.addAll([
Component(),
Component(),
]),
throwsException,
);
},
);
}); });
group('Controls', () { group('Controls', () {

Loading…
Cancel
Save