Skip to content

Commit

Permalink
test: remove test repetition
Browse files Browse the repository at this point in the history
Remove loops executing the same tests multiple times.

PR-URL: #1874
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
Trott committed Jun 14, 2015
1 parent 4285265 commit 88d7904
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,35 +271,31 @@ assert.equal(writeTest.toString(), 'nodejs');

var asciiString = 'hello world';
var offset = 100;
for (var j = 0; j < 500; j++) {

for (var i = 0; i < asciiString.length; i++) {
b[i] = asciiString.charCodeAt(i);
}
var asciiSlice = b.toString('ascii', 0, asciiString.length);
assert.equal(asciiString, asciiSlice);

var written = b.write(asciiString, offset, 'ascii');
assert.equal(asciiString.length, written);
var asciiSlice = b.toString('ascii', offset, offset + asciiString.length);
assert.equal(asciiString, asciiSlice);

var sliceA = b.slice(offset, offset + asciiString.length);
var sliceB = b.slice(offset, offset + asciiString.length);
for (var i = 0; i < asciiString.length; i++) {
assert.equal(sliceA[i], sliceB[i]);
}

// TODO utf8 slice tests
for (var i = 0; i < asciiString.length; i++) {
b[i] = asciiString.charCodeAt(i);
}
var asciiSlice = b.toString('ascii', 0, asciiString.length);
assert.equal(asciiString, asciiSlice);

var written = b.write(asciiString, offset, 'ascii');
assert.equal(asciiString.length, written);
var asciiSlice = b.toString('ascii', offset, offset + asciiString.length);
assert.equal(asciiString, asciiSlice);

var sliceA = b.slice(offset, offset + asciiString.length);
var sliceB = b.slice(offset, offset + asciiString.length);
for (var i = 0; i < asciiString.length; i++) {
assert.equal(sliceA[i], sliceB[i]);
}

// TODO utf8 slice tests

for (var j = 0; j < 100; j++) {
var slice = b.slice(100, 150);
assert.equal(50, slice.length);
for (var i = 0; i < 50; i++) {
assert.equal(b[100 + i], slice[i]);
}

var slice = b.slice(100, 150);
assert.equal(50, slice.length);
for (var i = 0; i < 50; i++) {
assert.equal(b[100 + i], slice[i]);
}


Expand Down

0 comments on commit 88d7904

Please sign in to comment.