Initial flame_lua_runtime package
This commit is contained in:
65
test/runtime/commands/runtime_command_registry_test.dart
Normal file
65
test/runtime/commands/runtime_command_registry_test.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:flame_lua_runtime/runtime/commands/runtime_command_registry.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RuntimeCommandRegistry', () {
|
||||
test('cancels handles by id, group and scope', () {
|
||||
final registry = RuntimeCommandRegistry();
|
||||
var idCancelled = false;
|
||||
var groupCancelled = false;
|
||||
var scopeCancelled = false;
|
||||
|
||||
registry.create(id: 'intro').addCancelCallback(() {
|
||||
idCancelled = true;
|
||||
});
|
||||
registry.create(group: 'scene').addCancelCallback(() {
|
||||
groupCancelled = true;
|
||||
});
|
||||
registry.create(scope: 'panel').addCancelCallback(() {
|
||||
scopeCancelled = true;
|
||||
});
|
||||
|
||||
registry
|
||||
..cancelId('intro')
|
||||
..cancelGroup('scene')
|
||||
..cancelScope('panel');
|
||||
|
||||
expect(idCancelled, isTrue);
|
||||
expect(groupCancelled, isTrue);
|
||||
expect(scopeCancelled, isTrue);
|
||||
expect(registry.activeHandleCount, 0);
|
||||
});
|
||||
|
||||
test('completed handles ignore later cancellation', () {
|
||||
final registry = RuntimeCommandRegistry();
|
||||
var cancelled = false;
|
||||
final handle = registry.create(group: 'scene')
|
||||
..addCancelCallback(() {
|
||||
cancelled = true;
|
||||
});
|
||||
|
||||
handle.complete();
|
||||
registry.cancelGroup('scene');
|
||||
|
||||
expect(cancelled, isFalse);
|
||||
expect(registry.activeHandleCount, 0);
|
||||
});
|
||||
|
||||
test('dispose cancels all handles', () {
|
||||
final registry = RuntimeCommandRegistry();
|
||||
var cancelCount = 0;
|
||||
|
||||
registry.create(id: 'a').addCancelCallback(() {
|
||||
cancelCount++;
|
||||
});
|
||||
registry.create(group: 'b').addCancelCallback(() {
|
||||
cancelCount++;
|
||||
});
|
||||
|
||||
registry.dispose();
|
||||
|
||||
expect(cancelCount, 2);
|
||||
expect(registry.activeHandleCount, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user