aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-12-10 21:45:16 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-12-13 22:09:11 +0900
commit38a69e4ca319f9db3c54a5cb69cd5645f12369d5 (patch)
treee4a4279cb4c30df68e3c292154e2152dc9531815 /test
parentc399b992e6665f194ebe08a48aae1ede32c6767f (diff)
Add prefix functions in KeySequence
Diffstat (limited to 'test')
-rw-r--r--test/content/domains/KeySequence.test.ts (renamed from test/shared/settings/KeySequence.test.ts)65
1 files changed, 64 insertions, 1 deletions
diff --git a/test/shared/settings/KeySequence.test.ts b/test/content/domains/KeySequence.test.ts
index 8a7a350..bc16189 100644
--- a/test/shared/settings/KeySequence.test.ts
+++ b/test/content/domains/KeySequence.test.ts
@@ -1,4 +1,4 @@
-import KeySequence from '../../../src/shared/settings/KeySequence';
+import KeySequence from '../../../src/content/domains/KeySequence';
import { expect } from 'chai'
import Key from "../../../src/shared/settings/Key";
@@ -62,6 +62,69 @@ describe("KeySequence", () => {
})
});
+ describe('#repeatCount', () => {
+ it('returns repeat count with a numeric prefix', () => {
+ let seq = new KeySequence([
+ new Key({ key: '1' }), new Key({ key: '0' }) ,
+ new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ ]);
+ expect(seq.repeatCount()).to.equal(10);
+
+ seq = new KeySequence([
+ new Key({ key: '0' }), new Key({ key: '5' }) ,
+ new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ ]);
+ expect(seq.repeatCount()).to.equal(5);
+ });
+
+ it('returns 1 if no numeric prefix', () => {
+ let seq = new KeySequence([
+ new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ ]);
+ expect(seq.repeatCount()).to.equal(1);
+
+ seq = new KeySequence([]);
+ expect(seq.repeatCount()).to.equal(1);
+ });
+
+ it('returns whole keys if digits only sequence', () => {
+ let seq = new KeySequence([
+ new Key({ key: '1' }), new Key({ key: '0' }) ,
+ ]);
+ expect(seq.repeatCount()).to.equal(10);
+
+ seq = new KeySequence([
+ new Key({ key: '0' }), new Key({ key: '5' }) ,
+ ]);
+ expect(seq.repeatCount()).to.equal(5);
+ });
+ });
+
+ describe('#trimNumericPrefix', () => {
+ it('removes numeric prefix', () => {
+ let seq = new KeySequence([
+ new Key({ key: '1' }), new Key({ key: '0' }) ,
+ new Key({ key: 'g' }), new Key({ key: 'g' }) , new Key({ key: '3' }) ,
+ ]).trimNumericPrefix();
+ expect(seq.keys.map(key => key.key)).to.deep.equal(['g', 'g', '3']);
+ });
+
+ it('returns empty if keys contains only digis', () => {
+ let seq = new KeySequence([
+ new Key({ key: '1' }), new Key({ key: '0' }) ,
+ ]).trimNumericPrefix();
+ expect(seq.trimNumericPrefix().keys).to.be.empty;
+ });
+
+ it('returns itself if no numeric prefix', () => {
+ let seq = new KeySequence([
+ new Key({ key: 'g' }), new Key({ key: 'g' }) , new Key({ key: '3' }) ,
+ ]).trimNumericPrefix();
+
+ expect(seq.keys.map(key => key.key)).to.deep.equal(['g', 'g', '3']);
+ });
+ });
+
describe('#splitNumericPrefix', () => {
it('splits numeric prefix', () => {
expect(KeySequence.fromMapKeys('10gg').splitNumericPrefix()).to.deep.equal([