Comparing version 0.0.2 to 0.0.3
@@ -64,2 +64,3 @@ | ||
FlexBuffer.prototype.delete = function(start, end) { | ||
checkParams(start, end, this.tail); | ||
var copy = this.buffer.slice(end, this.tail).copy(this.buffer, start) | ||
@@ -69,2 +70,9 @@ this.tail = this.tail - end + start | ||
var checkParams = function (start, end, size) { | ||
if (end > size || start > size || start < 0 || end < 0 || start > end) { | ||
throw new Error("Start and end not valid. start:["+start+"], end:["+end+"], size:["+size+"]"); | ||
} | ||
} | ||
FlexBuffer.prototype.deleteAndGet = function(start, end) { | ||
@@ -71,0 +79,0 @@ var b = new Buffer(end - start); |
@@ -6,3 +6,3 @@ { | ||
"description": "Buffer optimized", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main" : "./flexbuffer", | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/mercadolibre/flexbuffer-node", |
@@ -286,2 +286,87 @@ var should = require('should'); | ||
it ("exception con start y end erroneos", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(0,10); | ||
} catch (e) { | ||
done(); | ||
return; | ||
} | ||
should.fail('expected an error!'); | ||
}); | ||
it ("exception con start negativo", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(-1,10); | ||
} catch (e) { | ||
done(); | ||
return; | ||
} | ||
should.fail('expected an error!'); | ||
}); | ||
it ("exception con end negativo", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(0,-1); | ||
} catch (e) { | ||
done(); | ||
return; | ||
} | ||
should.fail('expected an error!'); | ||
}); | ||
it ("exception con start y end erroneos", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(0,10); | ||
} catch (e) { | ||
done(); | ||
return; | ||
} | ||
should.fail('expected an error!'); | ||
}); | ||
it ("exception start > end", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(9,8); | ||
} catch (e) { | ||
done(); | ||
return; | ||
} | ||
should.fail('expected an error!'); | ||
}); | ||
it ("exception con start muy grande", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(10,11); | ||
} catch (e) { | ||
done(); | ||
return; | ||
} | ||
should.fail('expected an error!'); | ||
}); | ||
it ("no errores con start and end validos", function (done) { | ||
var flexbuffer = new fbuffers.FlexBuffer(); | ||
flexbuffer.write("123456789"); | ||
try { | ||
flexbuffer.deleteAndGet(0,9); | ||
} catch (e) { | ||
should.fail('No deberia dar error!', e); | ||
return; | ||
} | ||
done(); | ||
}); | ||
}); |
14289
398