test.js 987 B

12345678910111213141516171819202122232425262728293031323334353637
  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. })