Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test syntax cleanup
  • Loading branch information
einaros committed Jan 1, 2012
1 parent ebee5c3 commit 09355ed
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 132 deletions.
22 changes: 11 additions & 11 deletions test/BufferPool.test.js
Expand Up @@ -6,16 +6,16 @@ describe('BufferPool', function() {
it('allocates pool', function() {
var db = new BufferPool(1000);
db.size.should.eql(1000);
})
})
});
});
describe('#get', function() {
it('grows the pool if necessary', function() {
var db = new BufferPool(1000);
var buf = db.get(2000);
db.size.should.be.above(1000);
db.used.should.eql(2000);
buf.length.should.eql(2000);
})
});
it('grows the pool after the first call, if necessary', function() {
var db = new BufferPool(1000);
var buf = db.get(1000);
Expand All @@ -26,29 +26,29 @@ describe('BufferPool', function() {
db.used.should.eql(2000);
db.size.should.be.above(1000);
buf2.length.should.eql(1000);
})
});
it('grows the pool according to the growStrategy if necessary', function() {
var db = new BufferPool(1000, function(db, length) {
return db.size + 2345;
});
var buf = db.get(2000);
db.size.should.eql(3345);
buf.length.should.eql(2000);
})
});
it('doesnt grow the pool if theres enough room available', function() {
var db = new BufferPool(1000);
var buf = db.get(1000);
db.size.should.eql(1000);
buf.length.should.eql(1000);
})
})
});
});
describe('#reset', function() {
it('shinks the pool', function() {
var db = new BufferPool(1000);
var buf = db.get(2000);
db.reset(true);
db.size.should.eql(1000);
})
});
it('shrinks the pool according to the shrinkStrategy', function() {
var db = new BufferPool(1000, function(db, length) {
return db.used + length;
Expand All @@ -58,6 +58,6 @@ describe('BufferPool', function() {
var buf = db.get(2000);
db.reset(true);
db.size.should.eql(0);
})
})
})
});
});
});
30 changes: 15 additions & 15 deletions test/Receiver.test.js
Expand Up @@ -16,7 +16,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse close message', function() {
var p = new Parser();
var packet = '88 00';
Expand All @@ -28,7 +28,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotClose.should.be.ok;
})
});
it('can parse masked text message', function() {
var p = new Parser();
var packet = '81 93 34 83 a8 68 01 b9 92 52 4f a1 c6 09 59 e6 8a 52 16 e6 cb 00 5b a1 d5';
Expand All @@ -41,7 +41,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse a masked text message longer than 125 bytes', function() {
var p = new Parser();
var message = 'A';
Expand All @@ -56,7 +56,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse a really long masked text message', function() {
var p = new Parser();
var message = 'A';
Expand All @@ -71,7 +71,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse a fragmented masked text message of 300 bytes', function() {
var p = new Parser();
var message = 'A';
Expand All @@ -90,7 +90,7 @@ describe('Receiver', function() {
p.add(getBufferFromHexString(packet1));
p.add(getBufferFromHexString(packet2));
gotData.should.be.ok;
})
});
it('can parse a ping message', function() {
var p = new Parser();
var message = 'Hello';
Expand All @@ -104,7 +104,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotPing.should.be.ok;
})
});
it('can parse a ping with no data', function() {
var p = new Parser();
var packet = '89 00';
Expand All @@ -116,7 +116,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotPing.should.be.ok;
})
});
it('can parse a fragmented masked text message of 300 bytes with a ping in the middle', function() {
var p = new Parser();
var message = 'A';
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('Receiver', function() {
p.add(getBufferFromHexString(packet2));
gotData.should.be.ok;
gotPing.should.be.ok;
})
});
it('can parse a fragmented masked text message of 300 bytes with a ping in the middle, which is delievered over sevaral tcp packets', function() {
var p = new Parser();
var message = 'A';
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('Receiver', function() {
}
gotData.should.be.ok;
gotPing.should.be.ok;
})
});
it('can parse a 100 byte long masked binary message', function() {
var p = new Parser();
var length = 100;
Expand All @@ -199,7 +199,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse a 256 byte long masked binary message', function() {
var p = new Parser();
var length = 256;
Expand All @@ -216,7 +216,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse a 200kb long masked binary message', function() {
var p = new Parser();
var length = 200 * 1024;
Expand All @@ -233,7 +233,7 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
});
it('can parse a 200kb long unmasked binary message', function() {
var p = new Parser();
var length = 200 * 1024;
Expand All @@ -250,6 +250,6 @@ describe('Receiver', function() {

p.add(getBufferFromHexString(packet));
gotData.should.be.ok;
})
})
});
});

14 changes: 7 additions & 7 deletions test/Sender.test.js
Expand Up @@ -8,21 +8,21 @@ describe('Sender', function() {
sendBufferCacheSize: 10
});
sender._sendCache.length.should.eql(10);
})
});

it('keeps a send cache equal to null if options.sendBufferCacheSize is 0', function() {
var sender = new Sender(null, {
sendBufferCacheSize: 0
});
(typeof sender._sendCache).should.eql('undefined');
})
});

it('keeps a send cache equal to null if options.sendBufferCacheSize is -1', function() {
var sender = new Sender(null, {
sendBufferCacheSize: -1
});
(typeof sender._sendCache).should.eql('undefined');
})
});

describe('#frameAndSend', function() {
it('does not modify a masked binary buffer', function() {
Expand All @@ -34,13 +34,13 @@ describe('Sender', function() {
buf[2].should.eql(3);
buf[3].should.eql(4);
buf[4].should.eql(5);
})
});

it('does not modify a masked text buffer', function() {
var sender = new Sender({ write: function() {} });
var text = 'hi there';
sender.frameAndSend(1, text, true, true);
text.should.eql('hi there');
})
})
})
});
});
});
12 changes: 6 additions & 6 deletions test/Validation.test.js
Expand Up @@ -7,18 +7,18 @@ describe('Validation', function() {
it('should return true for a valid utf8 string', function() {
var validBuffer = new Buffer('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque gravida mattis rhoncus. Donec iaculis, metus quis varius accumsan, erat mauris condimentum diam, et egestas erat enim ut ligula. Praesent sollicitudin tellus eget dolor euismod euismod. Nullam ac augue nec neque varius luctus. Curabitur elit mi, consequat ultricies adipiscing mollis, scelerisque in erat. Phasellus facilisis fermentum ullamcorper. Nulla et sem eu arcu pharetra pellentesque. Praesent consectetur tempor justo, vel iaculis dui ullamcorper sit amet. Integer tristique viverra ullamcorper. Vivamus laoreet, nulla eget suscipit eleifend, lacus lectus feugiat libero, non fermentum erat nisi at risus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pulvinar dignissim tellus, eu dignissim lorem vulputate quis. Morbi ut pulvinar augue.');
Validation.isValidUTF8(validBuffer).should.be.ok;
})
});
it('should return false for an erroneous string', function() {
var invalidBuffer = new Buffer([0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0xed, 0xa0, 0x80, 0x65, 0x64, 0x69, 0x74, 0x65, 0x64]);
Validation.isValidUTF8(invalidBuffer).should.not.be.ok;
})
});
it('should return true for valid cases from the autobahn test suite', function() {
Validation.isValidUTF8(new Buffer('\xf0\x90\x80\x80')).should.be.ok;
Validation.isValidUTF8(new Buffer([0xf0, 0x90, 0x80, 0x80])).should.be.ok;
})
});
it('should return false for erroneous autobahn strings', function() {
Validation.isValidUTF8(new Buffer([0xce, 0xba, 0xe1, 0xbd])).should.not.be.ok;
})
})
})
});
});
});

4 changes: 2 additions & 2 deletions test/WebSocket.integration.js
Expand Up @@ -38,5 +38,5 @@ describe('WebSocket', function() {
ws.terminate();
dataReceived = true;
});
})
})
});
});

0 comments on commit 09355ed

Please sign in to comment.