Initial flame_lua_runtime package
This commit is contained in:
77
test/runtime/models/runtime_event_command_test.dart
Normal file
77
test/runtime/models/runtime_event_command_test.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
import 'package:flame_lua_runtime/runtime/models/runtime_command.dart';
|
||||
import 'package:flame_lua_runtime/runtime/models/runtime_event.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RuntimeEvent', () {
|
||||
test('serializes only present fields', () {
|
||||
final event = RuntimeEvent(
|
||||
type: 'tap',
|
||||
target: 'dice_button',
|
||||
handler: 'roll_dice',
|
||||
x: 10,
|
||||
y: 20,
|
||||
data: {'pointer': 1},
|
||||
);
|
||||
|
||||
expect(event.toMap(), {
|
||||
'type': 'tap',
|
||||
'target': 'dice_button',
|
||||
'handler': 'roll_dice',
|
||||
'x': 10,
|
||||
'y': 20,
|
||||
'data': {'pointer': 1},
|
||||
});
|
||||
});
|
||||
|
||||
test('omits null and empty optional fields', () {
|
||||
expect(const RuntimeEvent(type: 'animation_done').toMap(), {
|
||||
'type': 'animation_done',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('RuntimeCommand', () {
|
||||
test('parses command payload without type and target', () {
|
||||
final command = RuntimeCommand.fromMap({
|
||||
'type': 'move_path',
|
||||
'target': 'piece_red_1',
|
||||
'duration': 0.5,
|
||||
'onComplete': 'done',
|
||||
});
|
||||
|
||||
expect(command.type, 'move_path');
|
||||
expect(command.target, 'piece_red_1');
|
||||
expect(command.payload, {'duration': 0.5, 'onComplete': 'done'});
|
||||
});
|
||||
|
||||
test('rejects invalid command shape', () {
|
||||
expect(() => RuntimeCommand.fromMap({'type': ''}), throwsFormatException);
|
||||
expect(
|
||||
() => RuntimeCommand.fromMap({'type': 'toast', 'target': 1}),
|
||||
throwsFormatException,
|
||||
);
|
||||
expect(
|
||||
() => RuntimeCommand.fromMap({'type': 'unknown'}),
|
||||
throwsFormatException,
|
||||
);
|
||||
expect(
|
||||
() => RuntimeCommand.fromMap({
|
||||
'type': 'move_to',
|
||||
'target': 'piece',
|
||||
'x': 1,
|
||||
'y': 2,
|
||||
'duraton': 0.5,
|
||||
}),
|
||||
throwsFormatException,
|
||||
);
|
||||
expect(
|
||||
() => RuntimeCommand.fromMap({
|
||||
'type': 'preload_resources',
|
||||
'groups': 'pieces',
|
||||
}),
|
||||
throwsFormatException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user