2017-04-20 19:17:05 -04:00
|
|
|
const test = require('tap').test;
|
|
|
|
const Keyboard = require('../../src/io/keyboard');
|
|
|
|
const Runtime = require('../../src/engine/runtime');
|
2016-10-21 18:31:07 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('spec', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const k = new Keyboard(rt);
|
2016-10-21 18:31:07 -04:00
|
|
|
|
|
|
|
t.type(k, 'object');
|
|
|
|
t.type(k.postData, 'function');
|
|
|
|
t.type(k.getKeyIsDown, 'function');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('space', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const k = new Keyboard(rt);
|
2016-10-21 18:31:07 -04:00
|
|
|
|
|
|
|
k.postData({
|
|
|
|
keyCode: 32,
|
|
|
|
isDown: true
|
|
|
|
});
|
|
|
|
t.strictDeepEquals(k._keysPressed, [32]);
|
|
|
|
t.strictEquals(k.getKeyIsDown('space'), true);
|
|
|
|
t.strictEquals(k.getKeyIsDown('any'), true);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('letter', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const k = new Keyboard(rt);
|
2016-10-21 18:31:07 -04:00
|
|
|
|
|
|
|
k.postData({
|
|
|
|
keyCode: 65,
|
|
|
|
isDown: true
|
|
|
|
});
|
|
|
|
t.strictDeepEquals(k._keysPressed, [65]);
|
|
|
|
t.strictEquals(k.getKeyIsDown('a'), true);
|
|
|
|
t.strictEquals(k.getKeyIsDown('any'), true);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('number', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const k = new Keyboard(rt);
|
2016-10-21 18:31:07 -04:00
|
|
|
|
|
|
|
k.postData({
|
|
|
|
keyCode: 49,
|
|
|
|
isDown: true
|
|
|
|
});
|
|
|
|
t.strictDeepEquals(k._keysPressed, [49]);
|
|
|
|
t.strictEquals(k.getKeyIsDown(49), true);
|
|
|
|
t.strictEquals(k.getKeyIsDown('any'), true);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('keyup', t => {
|
|
|
|
const rt = new Runtime();
|
|
|
|
const k = new Keyboard(rt);
|
2016-10-21 18:31:07 -04:00
|
|
|
|
|
|
|
k.postData({
|
|
|
|
keyCode: 37,
|
|
|
|
isDown: true
|
|
|
|
});
|
|
|
|
k.postData({
|
|
|
|
keyCode: 37,
|
|
|
|
isDown: false
|
|
|
|
});
|
|
|
|
t.strictDeepEquals(k._keysPressed, []);
|
|
|
|
t.strictEquals(k.getKeyIsDown(37), false);
|
|
|
|
t.strictEquals(k.getKeyIsDown('any'), false);
|
|
|
|
t.end();
|
|
|
|
});
|