@@ -14,9 +14,11 @@ class MockTerminalPlain {}
1414class MockTerminal {
1515 private _core : any ;
1616 public searchHelper : TestSearchHelper ;
17+ public cols : number ;
1718 constructor ( options : any ) {
1819 this . _core = new ( require ( '../../../lib/Terminal' ) . Terminal ) ( options ) ;
1920 this . searchHelper = new TestSearchHelper ( this as any ) ;
21+ this . cols = options . cols ;
2022 }
2123 get core ( ) : any {
2224 return this . _core ;
@@ -32,53 +34,88 @@ class TestSearchHelper extends SearchHelper {
3234 }
3335}
3436
35- describe ( 'search addon' , function ( ) : void {
37+ describe ( 'search addon' , ( ) => {
3638 describe ( 'apply' , ( ) => {
3739 it ( 'should register findNext and findPrevious' , ( ) => {
3840 search . apply ( < any > MockTerminalPlain ) ;
3941 assert . equal ( typeof ( < any > MockTerminalPlain ) . prototype . findNext , 'function' ) ;
4042 assert . equal ( typeof ( < any > MockTerminalPlain ) . prototype . findPrevious , 'function' ) ;
4143 } ) ;
4244 } ) ;
43- it ( 'Searchhelper - should find correct position' , function ( ) : void {
44- search . apply ( < any > MockTerminal ) ;
45- const term = new MockTerminal ( { cols : 20 , rows : 3 } ) ;
46- term . core . write ( 'Hello World\r\ntest\n123....hello' ) ;
47- term . pushWriteData ( ) ;
48- const hello0 = term . searchHelper . findInLine ( 'Hello' , 0 ) ;
49- const hello1 = term . searchHelper . findInLine ( 'Hello' , 1 ) ;
50- const hello2 = term . searchHelper . findInLine ( 'Hello' , 2 ) ;
51- expect ( hello0 ) . eql ( { col : 0 , row : 0 , term : 'Hello' } ) ;
52- expect ( hello1 ) . eql ( undefined ) ;
53- expect ( hello2 ) . eql ( { col : 11 , row : 2 , term : 'Hello' } ) ;
54- } ) ;
55- it ( 'should respect search regex' , function ( ) : void {
56- search . apply ( < any > MockTerminal ) ;
57- const term = new MockTerminal ( { cols : 10 , rows : 4 } ) ;
58- term . core . write ( 'abcdefghijklmnopqrstuvwxyz\r\n~/dev ' ) ;
59- /*
60- abcdefghij
61- klmnopqrst
62- uvwxyz
63- ~/dev
64- */
65- term . pushWriteData ( ) ;
66- const searchOptions = {
67- regex : true ,
68- wholeWord : false ,
69- caseSensitive : false
70- } ;
71- const hello0 = term . searchHelper . findInLine ( 'dee*' , 0 , searchOptions ) ;
72- term . searchHelper . findInLine ( 'jkk*' , 0 , searchOptions ) ;
73- term . searchHelper . findInLine ( 'mnn*' , 1 , searchOptions ) ;
74- const tilda0 = term . searchHelper . findInLine ( '^~' , 3 , searchOptions ) ;
75- const tilda1 = term . searchHelper . findInLine ( '^[~]' , 3 , searchOptions ) ;
76- const tilda2 = term . searchHelper . findInLine ( '^\\~' , 3 , searchOptions ) ;
77- expect ( hello0 ) . eql ( { col : 3 , row : 0 , term : 'de' } ) ;
78- // TODO: uncomment this test when line wrap search is checked in expect(hello1).eql({col: 9, row: 0, term: 'jk'});
79- // TODO: uncomment this test when line wrap search is checked in expect(hello2).eql(undefined);
80- expect ( tilda0 ) . eql ( { col : 0 , row : 3 , term : '~' } ) ;
81- expect ( tilda1 ) . eql ( { col : 0 , row : 3 , term : '~' } ) ;
82- expect ( tilda2 ) . eql ( { col : 0 , row : 3 , term : '~' } ) ;
45+ describe ( 'find' , ( ) => {
46+ it ( 'Searchhelper - should find correct position' , ( ) => {
47+ search . apply ( < any > MockTerminal ) ;
48+ const term = new MockTerminal ( { cols : 20 , rows : 3 } ) ;
49+ term . core . write ( 'Hello World\r\ntest\n123....hello' ) ;
50+ term . pushWriteData ( ) ;
51+ const hello0 = term . searchHelper . findInLine ( 'Hello' , 0 ) ;
52+ const hello1 = term . searchHelper . findInLine ( 'Hello' , 1 ) ;
53+ const hello2 = term . searchHelper . findInLine ( 'Hello' , 2 ) ;
54+ expect ( hello0 ) . eql ( { col : 0 , row : 0 , term : 'Hello' } ) ;
55+ expect ( hello1 ) . eql ( undefined ) ;
56+ expect ( hello2 ) . eql ( { col : 11 , row : 2 , term : 'Hello' } ) ;
57+ } ) ;
58+ it ( 'should find search term accross line wrap' , ( ) => {
59+ search . apply ( < any > MockTerminal ) ;
60+ const term = new MockTerminal ( { cols : 10 , rows : 5 } ) ;
61+ term . core . write ( 'texttextHellotext\r\n' ) ;
62+ term . core . write ( 'texttexttextHellotext' ) ;
63+ term . pushWriteData ( ) ;
64+ /*
65+ texttextHe
66+ llotext
67+ texttextte
68+ xtHellotex
69+ t
70+ */
71+
72+ const hello0 = ( term . searchHelper as any ) . _findInLine ( 'Hello' , 0 ) ;
73+ const hello1 = ( term . searchHelper as any ) . _findInLine ( 'Hello' , 1 ) ;
74+ const hello2 = ( term . searchHelper as any ) . _findInLine ( 'Hello' , 2 ) ;
75+ const hello3 = ( term . searchHelper as any ) . _findInLine ( 'Hello' , 3 ) ;
76+ const llo = ( term . searchHelper as any ) . _findInLine ( 'llo' , 1 ) ;
77+ expect ( hello0 ) . eql ( { col : 8 , row : 0 , term : 'Hello' } ) ;
78+ expect ( hello1 ) . eql ( undefined ) ;
79+ expect ( hello2 ) . eql ( { col : 2 , row : 3 , term : 'Hello' } ) ;
80+ expect ( hello3 ) . eql ( undefined ) ;
81+ expect ( llo ) . eql ( undefined ) ;
82+ } ) ;
83+ it ( 'should respect search regex' , ( ) => {
84+ search . apply ( < any > MockTerminal ) ;
85+ const term = new MockTerminal ( { cols : 10 , rows : 4 } ) ;
86+ term . core . write ( 'abcdefghijklmnopqrstuvwxyz\r\n~/dev ' ) ;
87+ /*
88+ abcdefghij
89+ klmnopqrst
90+ uvwxyz
91+ ~/dev
92+ */
93+ term . pushWriteData ( ) ;
94+ const searchOptions = {
95+ regex : true ,
96+ wholeWord : false ,
97+ caseSensitive : false
98+ } ;
99+ const hello0 = term . searchHelper . findInLine ( 'dee*' , 0 , searchOptions ) ;
100+ const hello1 = term . searchHelper . findInLine ( 'jkk*' , 0 , searchOptions ) ;
101+ const hello2 = term . searchHelper . findInLine ( 'mnn*' , 1 , searchOptions ) ;
102+ const tilda0 = term . searchHelper . findInLine ( '^~' , 3 , searchOptions ) ;
103+ const tilda1 = term . searchHelper . findInLine ( '^[~]' , 3 , searchOptions ) ;
104+ const tilda2 = term . searchHelper . findInLine ( '^\\~' , 3 , searchOptions ) ;
105+ expect ( hello0 ) . eql ( { col : 3 , row : 0 , term : 'de' } ) ;
106+ expect ( hello1 ) . eql ( { col : 9 , row : 0 , term : 'jk' } ) ;
107+ expect ( hello2 ) . eql ( undefined ) ;
108+ expect ( tilda0 ) . eql ( { col : 0 , row : 3 , term : '~' } ) ;
109+ expect ( tilda1 ) . eql ( { col : 0 , row : 3 , term : '~' } ) ;
110+ expect ( tilda2 ) . eql ( { col : 0 , row : 3 , term : '~' } ) ;
111+ } ) ;
112+ it ( 'should not select empty lines' , ( ) => {
113+ search . apply ( < any > MockTerminal ) ;
114+ const term = new MockTerminal ( { cols : 20 , rows : 3 } ) ;
115+ term . core . write ( ' ' ) ;
116+ term . pushWriteData ( ) ;
117+ const line = term . searchHelper . findInLine ( '^.*$' , 0 , { regex : true } ) ;
118+ expect ( line ) . eql ( undefined ) ;
119+ } ) ;
83120 } ) ;
84121} ) ;
0 commit comments