Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasq committed Feb 10, 2019
1 parent 126a47c commit c8b0bfd
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test.js
Expand Up @@ -243,7 +243,7 @@ module.exports = {
}
if (SysBuffer.concat) {
OBuff._install();
t.ok(Buffer.concat([makeSysBuffer('A'), new OBuff('B')]) instanceof OBuff);
t.ok(Buffer.concat([makeSysBuffer('A'), makeSysBuffer('B')]) instanceof OBuff);
}

OBuffer._install();
Expand Down Expand Up @@ -278,6 +278,7 @@ module.exports = {

'should access contents with subscript notation': function(t) {
var buf = OBuffer("ABC");
t.equal(buf.length, 3);
t.equal(buf[0], 65);
t.equal(buf[1], 66);
t.equal(buf[2], 67);
Expand Down Expand Up @@ -311,6 +312,31 @@ module.exports = {
t.equal(OBuffer.byteLength("hi\u9876"), 5);
t.done();
},

'should support keys and values': function(t) {
var buf = OBuffer("ABCD");
t.equal(buf.length, 4);
var keys = [], values = [];
// keys and values return iterators, which need for..of, introduced in 0.12
try { eval("for (var key of buf.keys()) keys.push(key);") } catch (e) { }
try { eval("for (var value of buf.values()) values.push(key);") } catch (e) { }
if (keys.length > 0) t.deepEqual(keys, [0, 1, 2, 3]);
if (values.length > 0) t.deepEqual(values, [65, 66, 67, 68]);
t.done();
},

'should support read and write': function(t) {
var buf = new OBuffer("oh hello world, have a good day.");

t.equal(buf.write("hit", 3, 2, 'utf8'), 2);
t.equal(buf.slice(1, 8).toString(), 'h hillo');
t.equal(buf.toString(undefined, 3, 3+2), 'hi');

buf.writeDoubleBE(1e6, 1);
t.equal(buf.readDoubleBE(1), 1e6);

t.done();
},
},

'speed OBuffer': {
Expand Down

0 comments on commit c8b0bfd

Please sign in to comment.