From dd1e291ef318737cd12762b914d48bd4c3924ed2 Mon Sep 17 00:00:00 2001 From: brianc Date: Wed, 29 Dec 2010 20:33:36 -0600 Subject: [PATCH] resize internal buffer on cstring --- test/unit/writer-tests.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/writer-tests.js b/test/unit/writer-tests.js index 3632311..5652975 100644 --- a/test/unit/writer-tests.js +++ b/test/unit/writer-tests.js @@ -44,6 +44,7 @@ p.addInt16 = function(num) { p.addCString = function(string) { var string = string || ""; var len = Buffer.byteLength(string) + 1; + this._ensure(len); this.offset += len; this.buffer.write(string); this.buffer[this.offset] = 0; //add null terminator @@ -120,4 +121,17 @@ test('cString', function() { assert.equalBuffers(result, [0]) }) + test('writes non-empty cstring', function() { + var subject = new ElasticBuffer(); + var result = subject.addCString("!!!").join(); + assert.equalBuffers(result, [33, 33, 33, 0]); + }) + + test('resizes if reached end', function() { + var subject = new ElasticBuffer(3); + var result = subject.addCString("!!!").join(); + assert.equalBuffers(result, [33, 33, 33, 0]); + }) + + })