-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1649 from jerch/fix_search_addon
Fix broken search addon
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2018 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { assert, expect } from 'chai'; | ||
import * as search from './search'; | ||
import { SearchHelper } from './SearchHelper'; | ||
import { ISearchHelper } from './Interfaces'; | ||
|
||
|
||
class MockTerminalPlain {} | ||
|
||
class MockTerminal { | ||
private _core: any; | ||
public searchHelper: ISearchHelper; | ||
constructor(options: any) { | ||
this._core = new (require('../../../lib/Terminal').Terminal)(options); | ||
this.searchHelper = new SearchHelper(this as any); | ||
} | ||
get core(): any { | ||
return this._core; | ||
} | ||
pushWriteData(): void { | ||
this._core._innerWrite(); | ||
} | ||
} | ||
|
||
describe('search addon', function(): void { | ||
describe('apply', () => { | ||
it('should register findNext and findPrevious', () => { | ||
search.apply(<any>MockTerminalPlain); | ||
assert.equal(typeof (<any>MockTerminalPlain).prototype.findNext, 'function'); | ||
assert.equal(typeof (<any>MockTerminalPlain).prototype.findPrevious, 'function'); | ||
}); | ||
}); | ||
it('Searchhelper - should find correct position', function(): void { | ||
search.apply(<any>MockTerminal); | ||
const term = new MockTerminal({cols: 20, rows: 3}); | ||
term.core.write('Hello World\r\ntest\n123....hello'); | ||
term.pushWriteData(); | ||
const hello0 = (term.searchHelper as any)._findInLine('Hello', 0); | ||
const hello1 = (term.searchHelper as any)._findInLine('Hello', 1); | ||
const hello2 = (term.searchHelper as any)._findInLine('Hello', 2); | ||
expect(hello0).eql({col: 0, row: 0, term: 'Hello'}); | ||
expect(hello1).eql(undefined); | ||
expect(hello2).eql({col: 11, row: 2, term: 'Hello'}); | ||
}); | ||
}); |