aboutsummaryrefslogtreecommitdiff
path: root/test/shared/settings
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 03:21:38 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-07 12:31:13 +0000
commitda3ce77aa0a50568ee4ddb423d07bc50422bd79c (patch)
tree67a74ee266972c49eb8918da9a581de813766d7d /test/shared/settings
parent8428671a0acf47a4a90b6b1f39cf94401f1e5520 (diff)
Move Key to settings
Diffstat (limited to 'test/shared/settings')
-rw-r--r--test/shared/settings/Key.test.ts92
-rw-r--r--test/shared/settings/KeySequence.test.ts72
2 files changed, 164 insertions, 0 deletions
diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts
new file mode 100644
index 0000000..8222d5a
--- /dev/null
+++ b/test/shared/settings/Key.test.ts
@@ -0,0 +1,92 @@
+import { expect } from 'chai'
+import Key from '../../../src/shared/settings/Key';
+
+describe("Key", () => {
+ describe('fromMapKey', () => {
+ it('return for X', () => {
+ let key = Key.fromMapKey('x');
+ expect(key.key).to.equal('x');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('return for Shift+X', () => {
+ let key = Key.fromMapKey('X');
+ expect(key.key).to.equal('X');
+ expect(key.shift).to.be.true;
+ expect(key.ctrl).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('return for Ctrl+X', () => {
+ let key = Key.fromMapKey('<C-X>');
+ expect(key.key).to.equal('x');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Ctrl+Meta+X', () => {
+ let key = Key.fromMapKey('<C-M-X>');
+ expect(key.key).to.equal('x');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.true;
+ });
+
+ it('returns for Ctrl+Shift+x', () => {
+ let key = Key.fromMapKey('<C-S-x>');
+ expect(key.key).to.equal('X');
+ expect(key.shift).to.be.true;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Shift+Esc', () => {
+ let key = Key.fromMapKey('<S-Esc>');
+ expect(key.key).to.equal('Esc');
+ expect(key.shift).to.be.true;
+ expect(key.ctrl).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Ctrl+Esc', () => {
+ let key = Key.fromMapKey('<C-Esc>');
+ expect(key.key).to.equal('Esc');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Ctrl+Esc', () => {
+ let key = Key.fromMapKey('<C-Space>');
+ expect(key.key).to.equal('Space');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+ });
+
+ describe('equals', () => {
+ expect(new Key({
+ key: 'x', shift: false, ctrl: true, alt: false, meta: false,
+ }).equals(new Key({
+ key: 'x', shift: false, ctrl: true, alt: false, meta: false,
+ }))).to.be.true;
+
+ expect(new Key({
+ key: 'x', shift: false, ctrl: false, alt: false, meta: false,
+ }).equals(new Key({
+ key: 'X', shift: true, ctrl: false, alt: false, meta: false,
+ }))).to.be.false;
+ });
+});
diff --git a/test/shared/settings/KeySequence.test.ts b/test/shared/settings/KeySequence.test.ts
new file mode 100644
index 0000000..361cbd1
--- /dev/null
+++ b/test/shared/settings/KeySequence.test.ts
@@ -0,0 +1,72 @@
+import KeySequence from '../../../src/shared/settings/KeySequence';
+import { expect } from 'chai'
+import Key from "../../../src/shared/settings/Key";
+
+describe("KeySequence", () => {
+ describe('#push', () => {
+ it('append a key to the sequence', () => {
+ let seq = new KeySequence([]);
+ seq.push(Key.fromMapKey('g'));
+ seq.push(Key.fromMapKey('<S-U>'));
+
+ 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 = new KeySequence([
+ Key.fromMapKey('g'),
+ Key.fromMapKey('<S-U>'),
+ ]);
+
+ expect(seq.startsWith(new KeySequence([
+ ]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('g'),
+ ]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('g'), Key.fromMapKey('<S-U>'),
+ ]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('g'), Key.fromMapKey('<S-U>'), Key.fromMapKey('x'),
+ ]))).to.be.false;
+ 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 = new KeySequence([]);
+
+ expect(seq.startsWith(new KeySequence([]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('h'),
+ ]))).to.be.false;
+ })
+ });
+
+ describe('#fromMapKeys', () => {
+ it('returns mapped keys for Shift+Esc', () => {
+ 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 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');
+ });
+ })
+});