Skip to content

Commit

Permalink
stylized
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ ONeal committed Mar 23, 2011
1 parent d03e647 commit 244e1e5
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions examples/indexOf-test.js
@@ -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!");
}());

0 comments on commit 244e1e5

Please sign in to comment.