@ -354,12 +354,35 @@ assert.equal(b.lastIndexOf('b', {}), 1);
assert . equal ( b . lastIndexOf ( 'b' , [ ] ) , - 1 ) ;
assert . equal ( b . lastIndexOf ( 'b' , [ ] ) , - 1 ) ;
assert . equal ( b . lastIndexOf ( 'b' , [ 2 ] ) , 1 ) ;
assert . equal ( b . lastIndexOf ( 'b' , [ 2 ] ) , 1 ) ;
// Test needles longer than the haystack.
assert . strictEqual ( b . lastIndexOf ( 'aaaaaaaaaaaaaaa' , 'ucs2' ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( 'aaaaaaaaaaaaaaa' , 'utf8' ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( 'aaaaaaaaaaaaaaa' , 'binary' ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( Buffer . from ( 'aaaaaaaaaaaaaaa' ) ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( 'aaaaaaaaaaaaaaa' , 2 , 'ucs2' ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( 'aaaaaaaaaaaaaaa' , 3 , 'utf8' ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( 'aaaaaaaaaaaaaaa' , 5 , 'binary' ) , - 1 ) ;
assert . strictEqual ( b . lastIndexOf ( Buffer . from ( 'aaaaaaaaaaaaaaa' ) , 7 ) , - 1 ) ;
// 你好 expands to a total of 6 bytes using UTF-8 and 4 bytes using UTF-16
assert . strictEqual ( buf_bc . lastIndexOf ( '你好' , 'ucs2' ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( '你好' , 'utf8' ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( '你好' , 'binary' ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( Buffer . from ( '你好' ) ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( '你好' , 2 , 'ucs2' ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( '你好' , 3 , 'utf8' ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( '你好' , 5 , 'binary' ) , - 1 ) ;
assert . strictEqual ( buf_bc . lastIndexOf ( Buffer . from ( '你好' ) , 7 ) , - 1 ) ;
// Test lastIndexOf on a longer buffer:
// Test lastIndexOf on a longer buffer:
var bufferString = new Buffer ( 'a man a plan a canal panama' ) ;
var bufferString = new Buffer ( 'a man a plan a canal panama' ) ;
assert . equal ( 15 , bufferString . lastIndexOf ( 'canal' ) ) ;
assert . equal ( 15 , bufferString . lastIndexOf ( 'canal' ) ) ;
assert . equal ( 21 , bufferString . lastIndexOf ( 'panama' ) ) ;
assert . equal ( 21 , bufferString . lastIndexOf ( 'panama' ) ) ;
assert . equal ( 0 , bufferString . lastIndexOf ( 'a man a plan a canal panama' ) ) ;
assert . equal ( 0 , bufferString . lastIndexOf ( 'a man a plan a canal panama' ) ) ;
assert . equal ( - 1 , bufferString . lastIndexOf ( 'a man a plan a canal mexico' ) ) ;
assert . equal ( - 1 , bufferString . lastIndexOf ( 'a man a plan a canal mexico' ) ) ;
assert . equal ( - 1 , bufferString . lastIndexOf ( 'a man a plan a canal mexico city' ) ) ;
assert . equal ( - 1 , bufferString . lastIndexOf ( Buffer . from ( 'a' . repeat ( 1000 ) ) ) ) ;
assert . equal ( 0 , bufferString . lastIndexOf ( 'a man a plan' , 4 ) ) ;
assert . equal ( 13 , bufferString . lastIndexOf ( 'a ' ) ) ;
assert . equal ( 13 , bufferString . lastIndexOf ( 'a ' ) ) ;
assert . equal ( 13 , bufferString . lastIndexOf ( 'a ' , 13 ) ) ;
assert . equal ( 13 , bufferString . lastIndexOf ( 'a ' , 13 ) ) ;
assert . equal ( 6 , bufferString . lastIndexOf ( 'a ' , 12 ) ) ;
assert . equal ( 6 , bufferString . lastIndexOf ( 'a ' , 12 ) ) ;