Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AJ ONeal
committed
Mar 23, 2011
1 parent
d03e647
commit 244e1e5
Showing
1 changed file
with
33 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
require('bufferjs/indexOf'); | ||
var assert = require('assert'); | ||
|
||
// Test the static version, Buffer needle | ||
function test1() { | ||
var haystack = new Buffer(10); | ||
var needle = new Buffer(1); | ||
needle[0] = haystack[0] = 255; | ||
assert.equal(Buffer.indexOf(haystack, needle), 0); | ||
assert.equal(Buffer.indexOf(haystack, new Buffer(haystack.length)), -1); | ||
} | ||
|
||
// Test the OO version, String needle | ||
function test2() { | ||
var haystack = new Buffer(20); | ||
var needle = '\r\n'; | ||
var index = 5; | ||
haystack.write(needle, index); | ||
assert.equal(haystack.indexOf(needle), index); | ||
assert.equal(haystack.indexOf('should not be found'), -1); | ||
} | ||
|
||
|
||
test1(); | ||
test2(); | ||
|
||
console.log("Done. `indexOf` tests passed!"); | ||
(function () { | ||
"use strict"; | ||
|
||
require('bufferjs/indexOf'); | ||
|
||
var assert = require('assert'); | ||
|
||
// Test the static version, Buffer needle | ||
function test1() { | ||
var haystack = new Buffer(10) | ||
, needle = new Buffer(1); | ||
|
||
needle[0] = haystack[0] = 255; | ||
assert.equal(Buffer.indexOf(haystack, needle), 0); | ||
assert.equal(Buffer.indexOf(haystack, new Buffer(haystack.length)), -1); | ||
} | ||
|
||
// Test the OO version, String needle | ||
function test2() { | ||
var haystack = new Buffer(20) | ||
, needle = '\r\n' | ||
, index = 5; | ||
|
||
haystack.write(needle, index); | ||
assert.equal(haystack.indexOf(needle), index); | ||
assert.equal(haystack.indexOf('should not be found'), -1); | ||
} | ||
|
||
test1(); | ||
test2(); | ||
|
||
console.log("Done. `indexOf` tests passed!"); | ||
}()); |