You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
987 B

4 years ago
  1. var test = require('tape');
  2. var bindexOf = require('../');
  3. test("can haz working",function(t){
  4. var newLineBuffer = new Buffer("\n");
  5. var b = new Buffer("hi\nho\nsilver");
  6. t.equals(bindexOf(new Buffer('a'), new Buffer('abc')), -1, 'should not match')
  7. t.equals(bindexOf(new Buffer('aaa'), new Buffer('aa'), 2), -1, 'should not match with 2 offset')
  8. t.equals(bindexOf(new Buffer('aaa'), new Buffer('aa')), 0, 'should match')
  9. t.equals(bindexOf(b,newLineBuffer),2,'should find newlines');
  10. // you can also start from index
  11. t.equals(bindexOf(b,newLineBuffer,3),5,"should find newlines after offset");
  12. // no match === -1
  13. t.equals(bindexOf(b,newLineBuffer,6),-1,"should not find newlines where none are.");
  14. t.end();
  15. })
  16. test("can handle overlapping matches",function(t){
  17. console.log(1,'aaaba'.indexOf('aaba'))
  18. console.log(2,bindexOf(new Buffer('aaaba'), new Buffer('aaba')))
  19. console.log(3,(new Buffer('aaaba')).indexOf(new Buffer('aaba')))
  20. t.end()
  21. })