File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ class ReplHistory {
142142 if ( this [ kHistory ] . length === 0 || this [ kHistory ] [ 0 ] !== normalizedLine ) {
143143 if ( this [ kRemoveHistoryDuplicates ] ) {
144144 // Remove older history line if identical to new one
145- const dupIndex = ArrayPrototypeIndexOf ( this [ kHistory ] , line ) ;
145+ const dupIndex = ArrayPrototypeIndexOf ( this [ kHistory ] , normalizedLine ) ;
146146 if ( dupIndex !== - 1 ) ArrayPrototypeSplice ( this [ kHistory ] , dupIndex , 1 ) ;
147147 }
148148
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+
5+ if ( process . env . TERM === 'dumb' ) {
6+ common . skip ( 'skipping - dumb terminal' ) ;
7+ }
8+
9+ const assert = require ( 'assert' ) ;
10+ const readline = require ( 'readline' ) ;
11+ const { EventEmitter } = require ( 'events' ) ;
12+
13+ class FakeInput extends EventEmitter {
14+ resume ( ) { }
15+ pause ( ) { }
16+ write ( ) { }
17+ end ( ) { }
18+ }
19+ FakeInput . prototype . readable = true ;
20+
21+ {
22+ const fi = new FakeInput ( ) ;
23+ const rli = new readline . Interface ( {
24+ input : fi ,
25+ output : fi ,
26+ terminal : true ,
27+ removeHistoryDuplicates : true ,
28+ } ) ;
29+
30+ function submitLine ( line ) {
31+ rli . line = line ;
32+ fi . emit ( 'keypress' , '' , { name : 'enter' } ) ;
33+ }
34+
35+ submitLine ( 'line1\nline2' ) ;
36+ submitLine ( 'other' ) ;
37+ submitLine ( 'line1\nline2' ) ;
38+
39+ assert . strictEqual ( rli . history . length , 2 ) ;
40+ assert . strictEqual ( rli . history [ 0 ] , 'line2\rline1' ) ;
41+ assert . strictEqual ( rli . history [ 1 ] , 'other' ) ;
42+
43+ rli . close ( ) ;
44+ }
You can’t perform that action at this time.
0 commit comments