[6a3a178] | 1 | var test = require('tape');
|
---|
| 2 | var bindexOf = require('../');
|
---|
| 3 |
|
---|
| 4 | test("can haz working",function(t){
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | var newLineBuffer = new Buffer("\n");
|
---|
| 8 |
|
---|
| 9 | var b = new Buffer("hi\nho\nsilver");
|
---|
| 10 |
|
---|
| 11 | t.equals(bindexOf(new Buffer('a'), new Buffer('abc')), -1, 'should not match')
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | t.equals(bindexOf(new Buffer('aaa'), new Buffer('aa'), 2), -1, 'should not match with 2 offset')
|
---|
| 15 | t.equals(bindexOf(new Buffer('aaa'), new Buffer('aa')), 0, 'should match')
|
---|
| 16 |
|
---|
| 17 | t.equals(bindexOf(b,newLineBuffer),2,'should find newlines');
|
---|
| 18 |
|
---|
| 19 | // you can also start from index
|
---|
| 20 |
|
---|
| 21 | t.equals(bindexOf(b,newLineBuffer,3),5,"should find newlines after offset");
|
---|
| 22 |
|
---|
| 23 | // no match === -1
|
---|
| 24 |
|
---|
| 25 | t.equals(bindexOf(b,newLineBuffer,6),-1,"should not find newlines where none are.");
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | t.end();
|
---|
| 29 | })
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | test("can handle overlapping matches",function(t){
|
---|
| 33 | console.log(1,'aaaba'.indexOf('aaba'))
|
---|
| 34 | console.log(2,bindexOf(new Buffer('aaaba'), new Buffer('aaba')))
|
---|
| 35 | console.log(3,(new Buffer('aaaba')).indexOf(new Buffer('aaba')))
|
---|
| 36 | t.end()
|
---|
| 37 | })
|
---|