aboutsummaryrefslogtreecommitdiff
path: root/test/content
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-03 12:32:32 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 12:58:59 +0000
commitb496cea5827165bd23a503231f94f708a976cad4 (patch)
treef6d8ec1bd42c8d6d43143c1b62d48b9f4a1d62c4 /test/content
parent62a86c525378610444a9976dd4409ea207174d20 (diff)
Make KeySequence class
Diffstat (limited to 'test/content')
-rw-r--r--test/content/domains/KeySequence.test.ts57
-rw-r--r--test/content/repositories/KeymapRepository.test.ts8
2 files changed, 32 insertions, 33 deletions
diff --git a/test/content/domains/KeySequence.test.ts b/test/content/domains/KeySequence.test.ts
index 9afc360..62af165 100644
--- a/test/content/domains/KeySequence.test.ts
+++ b/test/content/domains/KeySequence.test.ts
@@ -1,49 +1,48 @@
-import KeySequence, * as utils from '../../../src/content/domains/KeySequence';
+import KeySequence from '../../../src/content/domains/KeySequence';
import Key from '../../../src/content/domains/Key';
import { expect } from 'chai'
describe("KeySequence", () => {
describe('#push', () => {
it('append a key to the sequence', () => {
- let seq = KeySequence.from([]);
+ let seq = new KeySequence([]);
seq.push(Key.fromMapKey('g'));
seq.push(Key.fromMapKey('<S-U>'));
- let array = seq.getKeyArray();
- expect(array[0].key).to.equal('g');
- expect(array[1].key).to.equal('U');
- expect(array[1].shift).to.be.true;
+ expect(seq.keys[0].key).to.equal('g');
+ expect(seq.keys[1].key).to.equal('U');
+ expect(seq.keys[1].shift).to.be.true;
})
});
describe('#startsWith', () => {
it('returns true if the key sequence starts with param', () => {
- let seq = KeySequence.from([
+ let seq = new KeySequence([
Key.fromMapKey('g'),
Key.fromMapKey('<S-U>'),
]);
- expect(seq.startsWith(KeySequence.from([
+ expect(seq.startsWith(new KeySequence([
]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
+ expect(seq.startsWith(new KeySequence([
Key.fromMapKey('g'),
]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
+ expect(seq.startsWith(new KeySequence([
Key.fromMapKey('g'), Key.fromMapKey('<S-U>'),
]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
+ expect(seq.startsWith(new KeySequence([
Key.fromMapKey('g'), Key.fromMapKey('<S-U>'), Key.fromMapKey('x'),
]))).to.be.false;
- expect(seq.startsWith(KeySequence.from([
+ expect(seq.startsWith(new KeySequence([
Key.fromMapKey('h'),
]))).to.be.false;
});
it('returns true if the empty sequence starts with an empty sequence', () => {
- let seq = KeySequence.from([]);
+ let seq = new KeySequence([]);
- expect(seq.startsWith(KeySequence.from([]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
+ expect(seq.startsWith(new KeySequence([]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
Key.fromMapKey('h'),
]))).to.be.false;
})
@@ -51,23 +50,23 @@ describe("KeySequence", () => {
describe('#fromMapKeys', () => {
it('returns mapped keys for Shift+Esc', () => {
- let keyArray = utils.fromMapKeys('<S-Esc>').getKeyArray();
- expect(keyArray).to.have.lengthOf(1);
- expect(keyArray[0].key).to.equal('Esc');
- expect(keyArray[0].shift).to.be.true;
+ let keys = KeySequence.fromMapKeys('<S-Esc>').keys;
+ expect(keys).to.have.lengthOf(1);
+ expect(keys[0].key).to.equal('Esc');
+ expect(keys[0].shift).to.be.true;
});
it('returns mapped keys for a<C-B><A-C>d<M-e>', () => {
- let keyArray = utils.fromMapKeys('a<C-B><A-C>d<M-e>').getKeyArray();
- expect(keyArray).to.have.lengthOf(5);
- expect(keyArray[0].key).to.equal('a');
- expect(keyArray[1].ctrl).to.be.true;
- expect(keyArray[1].key).to.equal('b');
- expect(keyArray[2].alt).to.be.true;
- expect(keyArray[2].key).to.equal('c');
- expect(keyArray[3].key).to.equal('d');
- expect(keyArray[4].meta).to.be.true;
- expect(keyArray[4].key).to.equal('e');
+ let keys = KeySequence.fromMapKeys('a<C-B><A-C>d<M-e>').keys;
+ expect(keys).to.have.lengthOf(5);
+ expect(keys[0].key).to.equal('a');
+ expect(keys[1].ctrl).to.be.true;
+ expect(keys[1].key).to.equal('b');
+ expect(keys[2].alt).to.be.true;
+ expect(keys[2].key).to.equal('c');
+ expect(keys[3].key).to.equal('d');
+ expect(keys[4].meta).to.be.true;
+ expect(keys[4].key).to.equal('e');
});
})
});
diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts
index 8f0be67..da5624e 100644
--- a/test/content/repositories/KeymapRepository.test.ts
+++ b/test/content/repositories/KeymapRepository.test.ts
@@ -16,7 +16,7 @@ describe('KeymapRepositoryImpl', () => {
sut.enqueueKey(Key.fromMapKey('b');
let sequence = sut.enqueueKey(Key.fromMapKey('c'));
- let keys = sequence.getKeyArray();
+ let keys = sequence.keys;
expect(keys[0].equals(Key.fromMapKey('a'))).to.be.true;
expect(keys[1].equals(Key.fromMapKey('b'))).to.be.true;
expect(keys[2].equals(Key.fromMapKey('c'))).to.be.true;
@@ -25,9 +25,9 @@ describe('KeymapRepositoryImpl', () => {
describe('#clear()', () => {
it('clears keys', () => {
- sut.enqueueKey(Key.fromMapKey('a');
- sut.enqueueKey(Key.fromMapKey('b');
- sut.enqueueKey(Key.fromMapKey('c');
+ sut.enqueueKey(Key.fromMapKey('a'));
+ sut.enqueueKey(Key.fromMapKey('b'));
+ sut.enqueueKey(Key.fromMapKey('c'));
sut.clear();
let sequence = sut.enqueueKey(Key.fromMapKey('a'));