aboutsummaryrefslogtreecommitdiff
path: root/test/shared
diff options
context:
space:
mode:
Diffstat (limited to 'test/shared')
-rw-r--r--test/shared/SettingData.test.ts156
-rw-r--r--test/shared/operations.test.ts55
-rw-r--r--test/shared/settings/Blacklist.test.ts210
-rw-r--r--test/shared/settings/Key.test.ts120
-rw-r--r--test/shared/settings/Keymaps.test.ts81
-rw-r--r--test/shared/settings/Properties.test.ts21
-rw-r--r--test/shared/settings/Search.test.ts90
-rw-r--r--test/shared/settings/Settings.test.ts40
-rw-r--r--test/shared/urls.test.ts108
9 files changed, 489 insertions, 392 deletions
diff --git a/test/shared/SettingData.test.ts b/test/shared/SettingData.test.ts
index 0632176..283daa5 100644
--- a/test/shared/SettingData.test.ts
+++ b/test/shared/SettingData.test.ts
@@ -1,46 +1,48 @@
import SettingData, {
- FormKeymaps, JSONTextSettings, FormSettings,
-} from '../../src/shared/SettingData';
-import Settings from '../../src/shared/settings/Settings';
-import { expect } from 'chai';
-import Keymaps from '../../src/shared/settings/Keymaps';
+ FormKeymaps,
+ JSONTextSettings,
+ FormSettings,
+} from "../../src/shared/SettingData";
+import Settings from "../../src/shared/settings/Settings";
+import { expect } from "chai";
+import Keymaps from "../../src/shared/settings/Keymaps";
-describe('shared/SettingData', () => {
- describe('FormKeymaps', () => {
- describe('#valueOF to #toKeymaps', () => {
- it('parses form keymaps and convert to operations', () => {
+describe("shared/SettingData", () => {
+ describe("FormKeymaps", () => {
+ describe("#valueOF to #toKeymaps", () => {
+ it("parses form keymaps and convert to operations", () => {
const data = {
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
};
const keymaps = FormKeymaps.fromJSON(data).toKeymaps().toJSON();
expect(keymaps).to.deep.equal({
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
});
});
});
- describe('#fromKeymaps to #toJSON', () => {
- it('create from a Keymaps and create a JSON object', () => {
+ describe("#fromKeymaps to #toJSON", () => {
+ it("create from a Keymaps and create a JSON object", () => {
const keymaps: Keymaps = Keymaps.fromJSON({
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
});
const form = FormKeymaps.fromKeymaps(keymaps).toJSON();
expect(form).to.deep.equal({
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
});
});
});
});
- describe('JSONSettings', () => {
- describe('#valueOf to #toSettings', () => {
- it('parse object and create a Settings', () => {
+ describe("JSONSettings", () => {
+ describe("#valueOf to #toSettings", () => {
+ it("parse object and create a Settings", () => {
const o = `{
"keymaps": {},
"search": {
@@ -62,8 +64,8 @@ describe('shared/SettingData', () => {
});
});
- describe('#fromSettings to #toJSON', () => {
- it('create from a Settings and create a JSON string', () => {
+ describe("#fromSettings to #toJSON", () => {
+ it("create from a Settings and create a JSON string", () => {
const o = Settings.fromJSON({
keymaps: {},
search: {
@@ -75,7 +77,7 @@ describe('shared/SettingData', () => {
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
@@ -86,67 +88,65 @@ describe('shared/SettingData', () => {
});
});
- describe('FormSettings', () => {
- describe('#valueOf to #toSettings', () => {
- it('parse object and create a Settings', () => {
+ describe("FormSettings", () => {
+ describe("#valueOf to #toSettings", () => {
+ it("parse object and create a Settings", () => {
const data = {
keymaps: {
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
},
search: {
default: "google",
- engines: [
- ["google", "https://google.com/search?q={}"],
- ]
+ engines: [["google", "https://google.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
- blacklist: []
+ blacklist: [],
};
const settings = FormSettings.fromJSON(data).toSettings();
expect(settings.toJSON()).to.deep.equal({
keymaps: {
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
},
search: {
default: "google",
engines: {
- "google": "https://google.com/search?q={}"
- }
+ google: "https://google.com/search?q={}",
+ },
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
- blacklist: []
+ blacklist: [],
});
});
});
- describe('#fromSettings to #toJSON', () => {
- it('create from a Settings and create a JSON string', () => {
+ describe("#fromSettings to #toJSON", () => {
+ it("create from a Settings and create a JSON string", () => {
const data: Settings = Settings.fromJSON({
keymaps: {
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
},
search: {
default: "google",
engines: {
- "google": "https://google.com/search?q={}"
- }
+ google: "https://google.com/search?q={}",
+ },
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
@@ -154,19 +154,17 @@ describe('shared/SettingData', () => {
const json = FormSettings.fromSettings(data).toJSON();
expect(json).to.deep.equal({
keymaps: {
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
},
search: {
default: "google",
- engines: [
- ["google", "https://google.com/search?q={}"],
- ]
+ engines: [["google", "https://google.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
@@ -174,11 +172,11 @@ describe('shared/SettingData', () => {
});
});
- describe('SettingData', () => {
- describe('#valueOf to #toJSON', () => {
- it('parse object from json source', () => {
+ describe("SettingData", () => {
+ describe("#valueOf to #toJSON", () => {
+ it("parse object from json source", () => {
const data = {
- source: 'json',
+ source: "json",
json: `{
"keymaps": {},
"search": {
@@ -197,54 +195,50 @@ describe('shared/SettingData', () => {
};
const j = SettingData.fromJSON(data).toJSON();
- expect(j.source).to.equal('json');
- expect(j.json).to.be.a('string');
+ expect(j.source).to.equal("json");
+ expect(j.json).to.be.a("string");
});
- it('parse object from form source', () => {
+ it("parse object from form source", () => {
const data = {
- source: 'form',
+ source: "form",
form: {
keymaps: {},
search: {
default: "yahoo",
- engines: [
- ['yahoo', 'https://yahoo.com/search?q={}'],
- ],
+ engines: [["yahoo", "https://yahoo.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
},
};
const j = SettingData.fromJSON(data).toJSON();
- expect(j.source).to.equal('form');
+ expect(j.source).to.equal("form");
expect(j.form).to.deep.equal({
keymaps: {},
search: {
default: "yahoo",
- engines: [
- ['yahoo', 'https://yahoo.com/search?q={}'],
- ],
+ engines: [["yahoo", "https://yahoo.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
});
});
- describe('#toSettings', () => {
- it('parse object from json source', () => {
+ describe("#toSettings", () => {
+ it("parse object from json source", () => {
const data = {
- source: 'json',
+ source: "json",
json: `{
"keymaps": {},
"search": {
@@ -263,31 +257,29 @@ describe('shared/SettingData', () => {
};
const settings = SettingData.fromJSON(data).toSettings();
- expect(settings.search.defaultEngine).to.equal('google');
+ expect(settings.search.defaultEngine).to.equal("google");
});
- it('parse object from form source', () => {
+ it("parse object from form source", () => {
const data = {
- source: 'form',
+ source: "form",
form: {
keymaps: {},
search: {
default: "yahoo",
- engines: [
- ['yahoo', 'https://yahoo.com/search?q={}'],
- ],
+ engines: [["yahoo", "https://yahoo.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
},
};
const settings = SettingData.fromJSON(data).toSettings();
- expect(settings.search.defaultEngine).to.equal('yahoo');
+ expect(settings.search.defaultEngine).to.equal("yahoo");
});
});
});
diff --git a/test/shared/operations.test.ts b/test/shared/operations.test.ts
index fbb6193..449b25e 100644
--- a/test/shared/operations.test.ts
+++ b/test/shared/operations.test.ts
@@ -1,41 +1,48 @@
-import * as operations from 'shared/operations';
+import * as operations from "../../src/shared/operations";
+import { expect } from "chai";
-describe('operations', () => {
- describe('#valueOf', () => {
- it('returns an Operation', () => {
- const op: operations.Operation = operations.valueOf({
+describe("operations", () => {
+ describe("#valueOf", () => {
+ it("returns an Operation", () => {
+ const op = operations.valueOf({
type: operations.SCROLL_VERTICALLY,
count: 10,
- });
+ }) as operations.ScrollVerticallyOperation;
expect(op.type).to.equal(operations.SCROLL_VERTICALLY);
expect(op.count).to.equal(10);
});
- it('throws an Error on missing required parameter', () => {
- expect(() => operations.valueOf({
- type: operations.SCROLL_VERTICALLY,
- })).to.throw(TypeError);
+ it("throws an Error on missing required parameter", () => {
+ expect(() =>
+ operations.valueOf({
+ type: operations.SCROLL_VERTICALLY,
+ })
+ ).to.throw(TypeError);
});
- it('fills default valus of optional parameter', () => {
- const op: operations.Operation = operations.valueOf({
+ it("fills default valus of optional parameter", () => {
+ const op = operations.valueOf({
type: operations.COMMAND_SHOW_OPEN,
- });
+ }) as operations.CommandShowOpenOperation;
- expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN)
+ expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN);
expect(op.alter).to.be.false;
});
- it('throws an Error on mismatch of parameter', () => {
- expect(() => operations.valueOf({
- type: operations.SCROLL_VERTICALLY,
- count: '10',
- })).to.throw(TypeError);
+ it("throws an Error on mismatch of parameter", () => {
+ expect(() =>
+ operations.valueOf({
+ type: operations.SCROLL_VERTICALLY,
+ count: "10",
+ })
+ ).to.throw(TypeError);
- expect(() => valueOf({
- type: operations.COMMAND_SHOW_OPEN,
- alter: 'true',
- })).to.throw(TypeError);
+ expect(() =>
+ operations.valueOf({
+ type: operations.COMMAND_SHOW_OPEN,
+ alter: "true",
+ })
+ ).to.throw(TypeError);
});
});
-})
+});
diff --git a/test/shared/settings/Blacklist.test.ts b/test/shared/settings/Blacklist.test.ts
index bcddf18..1ccb32a 100644
--- a/test/shared/settings/Blacklist.test.ts
+++ b/test/shared/settings/Blacklist.test.ts
@@ -1,140 +1,178 @@
-import Blacklist, { BlacklistItem } from '../../../src/shared/settings/Blacklist';
-import { expect } from 'chai';
-import Key from '../../../src/shared/settings/Key';
-
-describe('BlacklistItem', () => {
- describe('#fromJSON', () => {
- it('parses string pattern', () => {
- const item = BlacklistItem.fromJSON('example.com');
- expect(item.pattern).to.equal('example.com');
+import Blacklist, {
+ BlacklistItem,
+} from "../../../src/shared/settings/Blacklist";
+import { expect } from "chai";
+import Key from "../../../src/shared/settings/Key";
+
+describe("BlacklistItem", () => {
+ describe("#fromJSON", () => {
+ it("parses string pattern", () => {
+ const item = BlacklistItem.fromJSON("example.com");
+ expect(item.pattern).to.equal("example.com");
expect(item.partial).to.be.false;
});
- it('parses partial blacklist item', () => {
- const item = BlacklistItem.fromJSON({ url: 'example.com', keys: ['j', 'k']});
- expect(item.pattern).to.equal('example.com');
+ it("parses partial blacklist item", () => {
+ const item = BlacklistItem.fromJSON({
+ url: "example.com",
+ keys: ["j", "k"],
+ });
+ expect(item.pattern).to.equal("example.com");
expect(item.partial).to.be.true;
- expect(item.keys).to.deep.equal(['j', 'k']);
+ expect(item.keys).to.deep.equal(["j", "k"]);
});
});
- describe('#matches', () => {
+ describe("#matches", () => {
it('matches by "*"', () => {
- const item = BlacklistItem.fromJSON('*');
- expect(item.matches(new URL('https://github.com/abc'))).to.be.true;
+ const item = BlacklistItem.fromJSON("*");
+ expect(item.matches(new URL("https://github.com/abc"))).to.be.true;
});
- it('matches by hostname', () => {
- const item = BlacklistItem.fromJSON('github.com');
- expect(item.matches(new URL('https://github.com'))).to.be.true;
- expect(item.matches(new URL('https://gist.github.com'))).to.be.false;
- expect(item.matches(new URL('https://github.com/ueokande'))).to.be.true;
- expect(item.matches(new URL('https://github.org'))).to.be.false;
- expect(item.matches(new URL('https://google.com/search?q=github.org'))).to.be.false;
+ it("matches by hostname", () => {
+ const item = BlacklistItem.fromJSON("github.com");
+ expect(item.matches(new URL("https://github.com"))).to.be.true;
+ expect(item.matches(new URL("https://gist.github.com"))).to.be.false;
+ expect(item.matches(new URL("https://github.com/ueokande"))).to.be.true;
+ expect(item.matches(new URL("https://github.org"))).to.be.false;
+ expect(item.matches(new URL("https://google.com/search?q=github.org"))).to
+ .be.false;
});
- it('matches by hostname with wildcard', () => {
- const item = BlacklistItem.fromJSON('*.github.com');
+ it("matches by hostname with wildcard", () => {
+ const item = BlacklistItem.fromJSON("*.github.com");
- expect(item.matches(new URL('https://github.com'))).to.be.false;
- expect(item.matches(new URL('https://gist.github.com'))).to.be.true;
+ expect(item.matches(new URL("https://github.com"))).to.be.false;
+ expect(item.matches(new URL("https://gist.github.com"))).to.be.true;
});
- it('matches by path', () => {
- const item = BlacklistItem.fromJSON('github.com/abc');
+ it("matches by path", () => {
+ const item = BlacklistItem.fromJSON("github.com/abc");
- expect(item.matches(new URL('https://github.com/abc'))).to.be.true;
- expect(item.matches(new URL('https://github.com/abcdef'))).to.be.false;
- expect(item.matches(new URL('https://gist.github.com/abc'))).to.be.false;
+ expect(item.matches(new URL("https://github.com/abc"))).to.be.true;
+ expect(item.matches(new URL("https://github.com/abcdef"))).to.be.false;
+ expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false;
});
- it('matches by path with wildcard', () => {
- const item = BlacklistItem.fromJSON('github.com/abc*');
+ it("matches by path with wildcard", () => {
+ const item = BlacklistItem.fromJSON("github.com/abc*");
- expect(item.matches(new URL('https://github.com/abc'))).to.be.true;
- expect(item.matches(new URL('https://github.com/abcdef'))).to.be.true;
- expect(item.matches(new URL('https://gist.github.com/abc'))).to.be.false;
+ expect(item.matches(new URL("https://github.com/abc"))).to.be.true;
+ expect(item.matches(new URL("https://github.com/abcdef"))).to.be.true;
+ expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false;
});
- it('matches address and port', () => {
- const item = BlacklistItem.fromJSON('127.0.0.1:8888');
+ it("matches address and port", () => {
+ const item = BlacklistItem.fromJSON("127.0.0.1:8888");
- expect(item.matches(new URL('http://127.0.0.1:8888/'))).to.be.true;
- expect(item.matches(new URL('http://127.0.0.1:8888/hello'))).to.be.true;
+ expect(item.matches(new URL("http://127.0.0.1:8888/"))).to.be.true;
+ expect(item.matches(new URL("http://127.0.0.1:8888/hello"))).to.be.true;
});
- it('matches with partial blacklist', () => {
- const item = BlacklistItem.fromJSON({ url: 'google.com', keys: ['j', 'k'] });
+ it("matches with partial blacklist", () => {
+ const item = BlacklistItem.fromJSON({
+ url: "google.com",
+ keys: ["j", "k"],
+ });
- expect(item.matches(new URL('https://google.com'))).to.be.true;
- expect(item.matches(new URL('https://yahoo.com'))).to.be.false;
- })
+ expect(item.matches(new URL("https://google.com"))).to.be.true;
+ expect(item.matches(new URL("https://yahoo.com"))).to.be.false;
+ });
});
- describe('#includesPartialKeys', () => {
- it('matches with partial keys', () => {
- const item = BlacklistItem.fromJSON({url: 'google.com', keys: ['j', 'k', '<C-U>']});
-
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('j'))).to.be.true;
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('<C-U>'))).to.be.true;
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('z'))).to.be.false;
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('u'))).to.be.false;
- expect(item.includeKey(new URL('http://maps.google.com/'), Key.fromMapKey('j'))).to.be.false;
- })
+ describe("#includesPartialKeys", () => {
+ it("matches with partial keys", () => {
+ const item = BlacklistItem.fromJSON({
+ url: "google.com",
+ keys: ["j", "k", "<C-U>"],
+ });
+
+ expect(
+ item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("j"))
+ ).to.be.true;
+ expect(
+ item.includeKey(
+ new URL("http://google.com/maps"),
+ Key.fromMapKey("<C-U>")
+ )
+ ).to.be.true;
+ expect(
+ item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("z"))
+ ).to.be.false;
+ expect(
+ item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("u"))
+ ).to.be.false;
+ expect(
+ item.includeKey(new URL("http://maps.google.com/"), Key.fromMapKey("j"))
+ ).to.be.false;
+ });
});
});
-describe('Blacklist', () => {
- describe('#fromJSON', () => {
- it('parses string list', () => {
- const blacklist = Blacklist.fromJSON(['example.com', 'example.org']);
- expect(blacklist.toJSON()).to.deep.equals([
- 'example.com', 'example.org',
- ]);
+describe("Blacklist", () => {
+ describe("#fromJSON", () => {
+ it("parses string list", () => {
+ const blacklist = Blacklist.fromJSON(["example.com", "example.org"]);
+ expect(blacklist.toJSON()).to.deep.equals(["example.com", "example.org"]);
});
- it('parses mixed blacklist', () => {
+ it("parses mixed blacklist", () => {
const blacklist = Blacklist.fromJSON([
- { url: 'example.com', keys: ['j', 'k']},
- 'example.org',
+ { url: "example.com", keys: ["j", "k"] },
+ "example.org",
]);
expect(blacklist.toJSON()).to.deep.equals([
- { url: 'example.com', keys: ['j', 'k']},
- 'example.org',
+ { url: "example.com", keys: ["j", "k"] },
+ "example.org",
]);
});
- it('parses empty blacklist', () => {
+ it("parses empty blacklist", () => {
const blacklist = Blacklist.fromJSON([]);
expect(blacklist.toJSON()).to.deep.equals([]);
});
});
- describe('#includesEntireBlacklist', () => {
- it('matches a url with entire blacklist', () => {
- const blacklist = Blacklist.fromJSON(['google.com', '*.github.com']);
- expect(blacklist.includesEntireBlacklist(new URL('https://google.com'))).to.be.true;
- expect(blacklist.includesEntireBlacklist(new URL('https://github.com'))).to.be.false;
- expect(blacklist.includesEntireBlacklist(new URL('https://gist.github.com'))).to.be.true;
+ describe("#includesEntireBlacklist", () => {
+ it("matches a url with entire blacklist", () => {
+ const blacklist = Blacklist.fromJSON(["google.com", "*.github.com"]);
+ expect(blacklist.includesEntireBlacklist(new URL("https://google.com")))
+ .to.be.true;
+ expect(blacklist.includesEntireBlacklist(new URL("https://github.com")))
+ .to.be.false;
+ expect(
+ blacklist.includesEntireBlacklist(new URL("https://gist.github.com"))
+ ).to.be.true;
});
- it('does not matches with partial blacklist', () => {
- const blacklist = Blacklist.fromJSON(['google.com', { url: 'yahoo.com', keys: ['j', 'k'] }]);
- expect(blacklist.includesEntireBlacklist(new URL('https://google.com'))).to.be.true;
- expect(blacklist.includesEntireBlacklist(new URL('https://yahoo.com'))).to.be.false;
+ it("does not matches with partial blacklist", () => {
+ const blacklist = Blacklist.fromJSON([
+ "google.com",
+ { url: "yahoo.com", keys: ["j", "k"] },
+ ]);
+ expect(blacklist.includesEntireBlacklist(new URL("https://google.com")))
+ .to.be.true;
+ expect(blacklist.includesEntireBlacklist(new URL("https://yahoo.com"))).to
+ .be.false;
});
});
- describe('#includesKeys', () => {
- it('matches with entire blacklist or keys in the partial blacklist', () => {
+ describe("#includesKeys", () => {
+ it("matches with entire blacklist or keys in the partial blacklist", () => {
const blacklist = Blacklist.fromJSON([
- 'google.com',
- { url: 'github.com', keys: ['j', 'k'] },
+ "google.com",
+ { url: "github.com", keys: ["j", "k"] },
]);
- expect(blacklist.includeKey(new URL('https://google.com'), Key.fromMapKey('j'))).to.be.false;
- expect(blacklist.includeKey(new URL('https://github.com'), Key.fromMapKey('j'))).to.be.true;
- expect(blacklist.includeKey(new URL('https://github.com'), Key.fromMapKey('a'))).to.be.false;
+ expect(
+ blacklist.includeKey(new URL("https://google.com"), Key.fromMapKey("j"))
+ ).to.be.false;
+ expect(
+ blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("j"))
+ ).to.be.true;
+ expect(
+ blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("a"))
+ ).to.be.false;
});
});
});
diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts
index b8538f8..47af1d9 100644
--- a/test/shared/settings/Key.test.ts
+++ b/test/shared/settings/Key.test.ts
@@ -1,74 +1,74 @@
-import { expect } from 'chai'
-import Key from '../../../src/shared/settings/Key';
+import { expect } from "chai";
+import Key from "../../../src/shared/settings/Key";
describe("Key", () => {
- describe('fromMapKey', () => {
- it('return for X', () => {
- const key = Key.fromMapKey('x');
- expect(key.key).to.equal('x');
+ describe("fromMapKey", () => {
+ it("return for X", () => {
+ const 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', () => {
- const key = Key.fromMapKey('X');
- expect(key.key).to.equal('X');
+ it("return for Shift+X", () => {
+ const 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', () => {
- const key = Key.fromMapKey('<C-X>');
- expect(key.key).to.equal('x');
+ it("return for Ctrl+X", () => {
+ const 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', () => {
- const key = Key.fromMapKey('<C-M-X>');
- expect(key.key).to.equal('x');
+ it("returns for Ctrl+Meta+X", () => {
+ const 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', () => {
- const key = Key.fromMapKey('<C-S-x>');
- expect(key.key).to.equal('X');
+ it("returns for Ctrl+Shift+x", () => {
+ const 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', () => {
- const key = Key.fromMapKey('<S-Esc>');
- expect(key.key).to.equal('Esc');
+ it("returns for Shift+Esc", () => {
+ const 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', () => {
- const key = Key.fromMapKey('<C-Esc>');
- expect(key.key).to.equal('Esc');
+ it("returns for Ctrl+Esc", () => {
+ const 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', () => {
- const key = Key.fromMapKey('<C-Space>');
- expect(key.key).to.equal('Space');
+ it("returns for Ctrl+Esc", () => {
+ const 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;
@@ -76,30 +76,54 @@ describe("Key", () => {
});
});
- describe('idDigit', () => {
- it('returns true if the key is a digit', () => {
- expect(new Key({ key: '0' }).isDigit()).to.be.true;
- expect(new Key({ key: '9' }).isDigit()).to.be.true;
- expect(new Key({ key: '9', alt: true }).isDigit()).to.be.false;
+ describe("idDigit", () => {
+ it("returns true if the key is a digit", () => {
+ expect(new Key({ key: "0" }).isDigit()).to.be.true;
+ expect(new Key({ key: "9" }).isDigit()).to.be.true;
+ expect(new Key({ key: "9", alt: true }).isDigit()).to.be.false;
- expect(new Key({ key: 'a' }).isDigit()).to.be.false;
- expect(new Key({ key: '0' }).isDigit()).to.be.false;
- })
+ expect(new Key({ key: "a" }).isDigit()).to.be.false;
+ expect(new Key({ key: "0" }).isDigit()).to.be.false;
+ });
});
- describe('equals', () => {
- it('returns true if the keys are equivalent', () => {
- 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;
+ describe("equals", () => {
+ it("returns true if the keys are equivalent", () => {
+ 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;
- })
+ 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/Keymaps.test.ts b/test/shared/settings/Keymaps.test.ts
index dcea6e4..264684d 100644
--- a/test/shared/settings/Keymaps.test.ts
+++ b/test/shared/settings/Keymaps.test.ts
@@ -1,65 +1,80 @@
-import Keymaps from '../../../src/shared/settings/Keymaps';
-import { expect } from 'chai';
+import Keymaps from "../../../src/shared/settings/Keymaps";
+import { expect } from "chai";
-describe('Keymaps', () => {
- describe('#valueOf', () => {
- it('returns empty object by empty settings', () => {
+describe("Keymaps", () => {
+ describe("#valueOf", () => {
+ it("returns empty object by empty settings", () => {
const keymaps = Keymaps.fromJSON({}).toJSON();
expect(keymaps).to.be.empty;
});
- it('returns keymaps by valid settings', () => {
+ it("returns keymaps by valid settings", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
}).toJSON();
- expect(keymaps['k']).to.deep.equal({ type: "scroll.vertically", count: -1 });
- expect(keymaps['j']).to.deep.equal({ type: "scroll.vertically", count: 1 });
+ expect(keymaps["k"]).to.deep.equal({
+ type: "scroll.vertically",
+ count: -1,
+ });
+ expect(keymaps["j"]).to.deep.equal({
+ type: "scroll.vertically",
+ count: 1,
+ });
});
- it('throws a TypeError by invalid settings', () => {
- expect(() => Keymaps.fromJSON({
- k: { type: "invalid.operation" },
- })).to.throw(TypeError);
+ it("throws a TypeError by invalid settings", () => {
+ expect(() =>
+ Keymaps.fromJSON({
+ k: { type: "invalid.operation" },
+ })
+ ).to.throw(TypeError);
});
});
- describe('#combine', () => {
- it('returns combined keymaps', () => {
+ describe("#combine", () => {
+ it("returns combined keymaps", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
- }).combine(Keymaps.fromJSON({
- n: { type: "find.next" },
- N: { type: "find.prev" },
- }));
+ }).combine(
+ Keymaps.fromJSON({
+ n: { type: "find.next" },
+ N: { type: "find.prev" },
+ })
+ );
- const entries = keymaps.entries().sort(([name1], [name2]) => name1.localeCompare(name2));
+ const entries = keymaps
+ .entries()
+ .sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).deep.equals([
- ['j', { type: "scroll.vertically", count: 1 }],
- ['k', { type: "scroll.vertically", count: -1 }],
- ['n', { type: "find.next" }],
- ['N', { type: "find.prev" }],
+ ["j", { type: "scroll.vertically", count: 1 }],
+ ["k", { type: "scroll.vertically", count: -1 }],
+ ["n", { type: "find.next" }],
+ ["N", { type: "find.prev" }],
]);
});
- it('overrides current keymaps', () => {
+ it("overrides current keymaps", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
- }).combine(Keymaps.fromJSON({
- n: { type: "find.next" },
- j: { type: "find.prev" },
- }));
+ }).combine(
+ Keymaps.fromJSON({
+ n: { type: "find.next" },
+ j: { type: "find.prev" },
+ })
+ );
- const entries = keymaps.entries().sort(([name1], [name2]) => name1.localeCompare(name2));
+ const entries = keymaps
+ .entries()
+ .sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).deep.equals([
- ['j', { type: "find.prev" }],
- ['k', { type: "scroll.vertically", count: -1 }],
- ['n', { type: "find.next" }],
+ ["j", { type: "find.prev" }],
+ ["k", { type: "scroll.vertically", count: -1 }],
+ ["n", { type: "find.next" }],
]);
});
});
});
-
diff --git a/test/shared/settings/Properties.test.ts b/test/shared/settings/Properties.test.ts
index 4639839..6007e84 100644
--- a/test/shared/settings/Properties.test.ts
+++ b/test/shared/settings/Properties.test.ts
@@ -1,30 +1,29 @@
-import Properties from '../../../src/shared/settings/Properties';
-import { expect } from 'chai';
+import Properties from "../../../src/shared/settings/Properties";
+import { expect } from "chai";
-describe('Properties', () => {
- describe('#propertiesValueOf', () => {
- it('returns with default properties by empty settings', () => {
+describe("Properties", () => {
+ describe("#propertiesValueOf", () => {
+ it("returns with default properties by empty settings", () => {
const props = Properties.fromJSON({});
expect(props).to.deep.equal({
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
- })
+ complete: "sbh",
+ });
});
- it('returns properties by valid settings', () => {
+ it("returns properties by valid settings", () => {
const props = Properties.fromJSON({
hintchars: "abcdefgh",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
});
expect(props).to.deep.equal({
hintchars: "abcdefgh",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
});
});
});
});
-
diff --git a/test/shared/settings/Search.test.ts b/test/shared/settings/Search.test.ts
index 8bd8d89..1feb14b 100644
--- a/test/shared/settings/Search.test.ts
+++ b/test/shared/settings/Search.test.ts
@@ -1,55 +1,63 @@
-import Search from '../../../src/shared/settings/Search';
-import { expect } from 'chai';
+import Search from "../../../src/shared/settings/Search";
+import { expect } from "chai";
-describe('Search', () => {
- it('returns search settings by valid settings', () => {
+describe("Search", () => {
+ it("returns search settings by valid settings", () => {
const search = Search.fromJSON({
- default: 'google',
+ default: "google",
engines: {
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
- }
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
+ },
});
- expect(search.defaultEngine).to.equal('google')
+ expect(search.defaultEngine).to.equal("google");
expect(search.engines).to.deep.equals({
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
});
expect(search.toJSON()).to.deep.equal({
- default: 'google',
+ default: "google",
engines: {
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
- }
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
+ },
});
});
- it('throws a TypeError by invalid settings', () => {
- expect(() => Search.fromJSON({
- default: 'wikipedia',
- engines: {
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
- }
- })).to.throw(TypeError);
- expect(() => Search.fromJSON({
- default: 'g o o g l e',
- engines: {
- 'g o o g l e': 'https://google.com/search?q={}',
- }
- })).to.throw(TypeError);
- expect(() => Search.fromJSON({
- default: 'google',
- engines: {
- 'google': 'https://google.com/search',
- }
- })).to.throw(TypeError);
- expect(() => Search.fromJSON({
- default: 'google',
- engines: {
- 'google': 'https://google.com/search?q={}&r={}',
- }
- })).to.throw(TypeError);
+ it("throws a TypeError by invalid settings", () => {
+ expect(() =>
+ Search.fromJSON({
+ default: "wikipedia",
+ engines: {
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
+ },
+ })
+ ).to.throw(TypeError);
+ expect(() =>
+ Search.fromJSON({
+ default: "g o o g l e",
+ engines: {
+ "g o o g l e": "https://google.com/search?q={}",
+ },
+ })
+ ).to.throw(TypeError);
+ expect(() =>
+ Search.fromJSON({
+ default: "google",
+ engines: {
+ google: "https://google.com/search",
+ },
+ })
+ ).to.throw(TypeError);
+ expect(() =>
+ Search.fromJSON({
+ default: "google",
+ engines: {
+ google: "https://google.com/search?q={}&r={}",
+ },
+ })
+ ).to.throw(TypeError);
});
});
diff --git a/test/shared/settings/Settings.test.ts b/test/shared/settings/Settings.test.ts
index 658132c..4ecfe77 100644
--- a/test/shared/settings/Settings.test.ts
+++ b/test/shared/settings/Settings.test.ts
@@ -1,19 +1,19 @@
-import Settings from '../../../src/shared/settings/Settings';
-import { expect } from 'chai';
+import Settings from "../../../src/shared/settings/Settings";
+import { expect } from "chai";
-describe('Settings', () => {
- describe('#valueOf', () => {
- it('returns settings by valid settings', () => {
+describe("Settings", () => {
+ describe("#valueOf", () => {
+ it("returns settings by valid settings", () => {
const x = Settings.fromJSON({
keymaps: {},
- "search": {
- "default": "google",
- "engines": {
- "google": "https://google.com/search?q={}",
- }
+ search: {
+ default: "google",
+ engines: {
+ google: "https://google.com/search?q={}",
+ },
},
- "properties": {},
- "blacklist": []
+ properties: {},
+ blacklist: [],
});
expect({
@@ -27,28 +27,28 @@ describe('Settings', () => {
default: "google",
engines: {
google: "https://google.com/search?q={}",
- }
+ },
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
- blacklist: []
+ blacklist: [],
});
});
- it('sets default settings', () => {
+ it("sets default settings", () => {
const value = Settings.fromJSON({});
expect(value.keymaps.toJSON()).to.not.be.empty;
expect(value.properties.toJSON()).to.not.be.empty;
- expect(value.search.defaultEngine).to.be.a('string');
- expect(value.search.engines).to.be.an('object');
+ expect(value.search.defaultEngine).to.be.a("string");
+ expect(value.search.engines).to.be.an("object");
expect(value.blacklist.toJSON()).to.be.empty;
});
- it('throws a TypeError with an unknown field', () => {
- expect(() => Settings.fromJSON({ name: 'alice' })).to.throw(TypeError)
+ it("throws a TypeError with an unknown field", () => {
+ expect(() => Settings.fromJSON({ name: "alice" })).to.throw(TypeError);
});
});
});
diff --git a/test/shared/urls.test.ts b/test/shared/urls.test.ts
index 6206d03..f264ad9 100644
--- a/test/shared/urls.test.ts
+++ b/test/shared/urls.test.ts
@@ -1,64 +1,78 @@
-import * as parsers from '../../src/shared/urls';
-import { expect } from 'chai';
-import Search from '../../src/shared/settings/Search';
+import * as parsers from "../../src/shared/urls";
+import { expect } from "chai";
+import Search from "../../src/shared/settings/Search";
describe("shared/commands/parsers", () => {
- describe('#searchUrl', () => {
+ describe("#searchUrl", () => {
const config = Search.fromJSON({
- default: 'google',
+ default: "google",
engines: {
- google: 'https://google.com/search?q={}',
- yahoo: 'https://yahoo.com/search?q={}',
- }
+ google: "https://google.com/search?q={}",
+ yahoo: "https://yahoo.com/search?q={}",
+ },
});
- it('convertes search url', () => {
- expect(parsers.searchUrl('google.com', config))
- .to.equal('http://google.com');
- expect(parsers.searchUrl('google apple', config))
- .to.equal('https://google.com/search?q=apple');
- expect(parsers.searchUrl('yahoo apple', config))
- .to.equal('https://yahoo.com/search?q=apple');
- expect(parsers.searchUrl('google apple banana', config))
- .to.equal('https://google.com/search?q=apple%20banana');
- expect(parsers.searchUrl('yahoo C++CLI', config))
- .to.equal('https://yahoo.com/search?q=C%2B%2BCLI');
+ it("convertes search url", () => {
+ expect(parsers.searchUrl("google.com", config)).to.equal(
+ "http://google.com"
+ );
+ expect(parsers.searchUrl("google apple", config)).to.equal(
+ "https://google.com/search?q=apple"
+ );
+ expect(parsers.searchUrl("yahoo apple", config)).to.equal(
+ "https://yahoo.com/search?q=apple"
+ );
+ expect(parsers.searchUrl("google apple banana", config)).to.equal(
+ "https://google.com/search?q=apple%20banana"
+ );
+ expect(parsers.searchUrl("yahoo C++CLI", config)).to.equal(
+ "https://yahoo.com/search?q=C%2B%2BCLI"
+ );
});
- it('user default search engine', () => {
- expect(parsers.searchUrl('apple banana', config))
- .to.equal('https://google.com/search?q=apple%20banana');
+ it("user default search engine", () => {
+ expect(parsers.searchUrl("apple banana", config)).to.equal(
+ "https://google.com/search?q=apple%20banana"
+ );
});
- it('searches with a word containing a colon', () => {
- expect(parsers.searchUrl('foo:', config))
- .to.equal('https://google.com/search?q=foo%3A');
- expect(parsers.searchUrl('std::vector', config))
- .to.equal('https://google.com/search?q=std%3A%3Avector');
+ it("searches with a word containing a colon", () => {
+ expect(parsers.searchUrl("foo:", config)).to.equal(
+ "https://google.com/search?q=foo%3A"
+ );
+ expect(parsers.searchUrl("std::vector", config)).to.equal(
+ "https://google.com/search?q=std%3A%3Avector"
+ );
});
- it('localhost urls', () => {
- expect(parsers.searchUrl('localhost', config))
- .to.equal('http://localhost');
- expect(parsers.searchUrl('http://localhost', config))
- .to.equal('http://localhost/');
- expect(parsers.searchUrl('localhost:8080', config))
- .to.equal('http://localhost:8080');
- expect(parsers.searchUrl('localhost:80nan', config))
- .to.equal('https://google.com/search?q=localhost%3A80nan');
- expect(parsers.searchUrl('localhost 8080', config))
- .to.equal('https://google.com/search?q=localhost%208080');
- expect(parsers.searchUrl('localhost:80/build', config))
- .to.equal('http://localhost:80/build')
- })
+ it("localhost urls", () => {
+ expect(parsers.searchUrl("localhost", config)).to.equal(
+ "http://localhost"
+ );
+ expect(parsers.searchUrl("http://localhost", config)).to.equal(
+ "http://localhost/"
+ );
+ expect(parsers.searchUrl("localhost:8080", config)).to.equal(
+ "http://localhost:8080"
+ );
+ expect(parsers.searchUrl("localhost:80nan", config)).to.equal(
+ "https://google.com/search?q=localhost%3A80nan"
+ );
+ expect(parsers.searchUrl("localhost 8080", config)).to.equal(
+ "https://google.com/search?q=localhost%208080"
+ );
+ expect(parsers.searchUrl("localhost:80/build", config)).to.equal(
+ "http://localhost:80/build"
+ );
+ });
});
- describe('#normalizeUrl', () => {
- it('normalize urls', () => {
- expect(parsers.normalizeUrl('https://google.com/'))
- .to.equal('https://google.com/');
- expect(parsers.normalizeUrl('google.com'))
- .to.equal('http://google.com');
+ describe("#normalizeUrl", () => {
+ it("normalize urls", () => {
+ expect(parsers.normalizeUrl("https://google.com/")).to.equal(
+ "https://google.com/"
+ );
+ expect(parsers.normalizeUrl("google.com")).to.equal("http://google.com");
});
});
});