Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
deerawan committed Jul 26, 2019
1 parent ecfb152 commit 53fd29c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions src/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ export class Dash {

constructor(OS: string, option: DashOption) {
this.OS = OS;

this.URIHandler = {
darwin: 'open -g',
linux: 'zeal',
// Same technique as Silverlake Software's "Search Docsets" extension,
// which is written by Velocity's developer and is tested to work with current Velocity on W10.
win32: 'cmd.exe /c start "" ',
}[this.OS] || 'zeal';

this.URIHandler =
{
darwin: 'open -g',
linux: 'zeal',
// Same technique as Silverlake Software's "Search Docsets" extension,
// which is written by Velocity's developer and is tested to work with current Velocity on W10.
win32: 'cmd.exe /c start "" ', // TODO: do we need extra space?
}[this.OS] || 'zeal';

this.option = option;
}
Expand All @@ -25,11 +26,14 @@ export class Dash {
* @return {string} dash handler and uri
*/
getCommand(query: string, docsets: string[] = []): string {
const keys = (docsets || []).map(docset => `${this.option.exactDocset ? "exact:" : ""}${docset}`).join(",");
const keys = (docsets || [])
.map(docset => `${this.option.exactDocset ? 'exact:' : ''}${docset}`)
.join(',');
const encodedQuery = encodeURIComponent(query);
return `${this.URIHandler} "dash-plugin://query=${encodedQuery}${keys?`&keys=${keys}`:``}"`;
return `${this.URIHandler} "dash-plugin://query=${encodedQuery}${keys
? `&keys=${keys}`
: ``}"`;
}

}

export interface DashOption {
Expand Down
4 changes: 2 additions & 2 deletions test/dash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ suite('Dash Tests', () => {

assert.equal(
uri,
'cmd.exe /c start "" dash-plugin://query=size^&keys=exact:css,exact:less'
'cmd.exe /c start "" "dash-plugin://query=size&keys=exact:css,exact:less"'
);
});

test('Get command with no keys for Windows', () => {
const dash = new Dash('win32', dashOptionExactDocsetEnabled);
const uri = dash.getCommand('size');

assert.equal(uri, 'cmd.exe /c start "" dash-plugin://query=size');
assert.equal(uri, 'cmd.exe /c start "" "dash-plugin://query=size"');
});

test('Get command with keys for Linux', () => {
Expand Down

0 comments on commit 53fd29c

Please sign in to comment.