Skip to content

Commit

Permalink
test: more organized string tests (and a new one!)
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed May 10, 2012
1 parent 0fa0c49 commit 5ff3caf
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions test/string.js
Expand Up @@ -4,14 +4,32 @@ var ref = require('../')

describe('C string', function () {

it('should return "" for a Buffer containing "\\0"', function () {
var buf = new Buffer('\0')
assert.strictEqual('', buf.readCString(0))
describe('readCString()', function () {

it('should return "" for a Buffer containing "\\0"', function () {
var buf = new Buffer('\0')
assert.strictEqual('', buf.readCString(0))
})

it('should return "hello" for a Buffer containing "hello\\0world"', function () {
var buf = new Buffer('hello\0world')
assert.strictEqual('hello', buf.readCString(0))
})

})

it('should return "hello" for a Buffer containing "hello\\0world"', function () {
var buf = new Buffer('hello\0world')
assert.strictEqual('hello', buf.readCString(0))
describe('readCString()', function () {

it('should write a C string (NULL terminated) to a Buffer', function () {
var buf = new Buffer(20)
var str = 'hello world'
buf.writeCString(str)
for (var i = 0; i < str.length; i++) {
assert.equal(str.charCodeAt(i), buf[i])
}
assert.equal(0, buf[str.length])
})

})

describe('allocCString()', function () {
Expand Down

0 comments on commit 5ff3caf

Please sign in to comment.