Skip to content

Commit b401576

Browse files
committed
Moved packstream test to ES6
1 parent 2723fe5 commit b401576

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

test/internal/packstream.test.js

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,68 +16,67 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
20-
var alloc = require('../../lib/v1/internal/buf').alloc,
21-
packstream = require("../../lib/v1/internal/packstream"),
22-
Integer = require("../../lib/v1/integer").default,
23-
Packer = packstream.Packer,
24-
Unpacker = packstream.Unpacker,
25-
Structure = packstream.Structure;
2619

27-
describe('packstream', function() {
20+
import {alloc} from '../../src/v1/internal/buf';
21+
import {Packer, Structure, Unpacker} from '../../src/v1/internal/packstream';
22+
import {int} from '../../src/v1';
2823

24+
describe('packstream', () => {
2925

30-
it('should pack integers', function() {
31-
var n, i;
26+
it('should pack integers', () => {
27+
let n, i;
3228
// test small numbers
33-
for(n = -999; n <= 999; n += 1) {
34-
i = Integer.fromNumber(n);
35-
expect( packAndUnpack( i ).toString() ).toBe( i.toString() );
29+
for (n = -999; n <= 999; n += 1) {
30+
i = int(n);
31+
expect(packAndUnpack(i).toString()).toBe(i.toString());
3632
}
3733
// positive numbers
38-
for(n = 16; n <= 16 ; n += 1) {
39-
i = Integer.fromNumber(Math.pow(2, n));
40-
expect( packAndUnpack( i ).toString() ).toBe( i.toString() );
34+
for (n = 16; n <= 16; n += 1) {
35+
i = int(Math.pow(2, n));
36+
expect(packAndUnpack(i).toString()).toBe(i.toString());
4137
}
4238
// negative numbers
43-
for(n = 0; n <= 63 ; n += 1) {
44-
i = Integer.fromNumber(-Math.pow(2, n));
45-
expect( packAndUnpack( i ).toString() ).toBe( i.toString() );
39+
for (n = 0; n <= 63; n += 1) {
40+
i = int(-Math.pow(2, n));
41+
expect(packAndUnpack(i).toString()).toBe(i.toString());
4642
}
4743
});
48-
it('should pack strings', function() {
49-
expect( packAndUnpack( "" ) ).toBe( "" );
50-
expect( packAndUnpack( "abcdefg123567" ) ).toBe( "abcdefg123567" );
51-
var str = Array(65536 + 1).join('a'); // 2 ^ 16 + 1
52-
expect( packAndUnpack(str, str.length + 8)).toBe(str);
44+
45+
it('should pack strings', () => {
46+
expect(packAndUnpack('')).toBe('');
47+
expect(packAndUnpack('abcdefg123567')).toBe('abcdefg123567');
48+
const str = Array(65536 + 1).join('a'); // 2 ^ 16 + 1
49+
expect(packAndUnpack(str, str.length + 8)).toBe(str);
5350
});
54-
it('should pack structures', function() {
55-
expect( packAndUnpack( new Structure(1, ["Hello, world!!!"] ) ).fields[0] )
56-
.toBe( "Hello, world!!!" );
51+
52+
it('should pack structures', () => {
53+
expect(packAndUnpack(new Structure(1, ['Hello, world!!!'])).fields[0])
54+
.toBe('Hello, world!!!');
5755
});
58-
it('should pack lists', function() {
59-
var list = ['a', 'b'];
60-
var roundtripped = packAndUnpack( list );
61-
expect( roundtripped[0] ).toBe( list[0] );
62-
expect( roundtripped[1] ).toBe( list[1] );
56+
57+
it('should pack lists', () => {
58+
const list = ['a', 'b'];
59+
const unpacked = packAndUnpack(list);
60+
expect(unpacked[0]).toBe(list[0]);
61+
expect(unpacked[1]).toBe(list[1]);
6362
});
6463

65-
it('should pack long lists', function() {
66-
var listLength = 256;
67-
var list = [];
68-
for(var i = 0; i < listLength; i++) {
69-
list.push(null)
64+
it('should pack long lists', () => {
65+
const listLength = 256;
66+
const list = [];
67+
for (let i = 0; i < listLength; i++) {
68+
list.push(null);
7069
}
71-
var roundtripped = packAndUnpack( list, 1400 );
72-
expect( roundtripped[0] ).toBe( list[0] );
73-
expect( roundtripped[1] ).toBe( list[1] );
70+
const unpacked = packAndUnpack(list, 1400);
71+
expect(unpacked[0]).toBe(list[0]);
72+
expect(unpacked[1]).toBe(list[1]);
7473
});
7574
});
7675

77-
function packAndUnpack( val, bufferSize ) {
76+
function packAndUnpack(val, bufferSize) {
7877
bufferSize = bufferSize || 128;
79-
var buffer = alloc(bufferSize);
80-
new Packer( buffer ).packable( val )();
78+
const buffer = alloc(bufferSize);
79+
new Packer(buffer).packable(val)();
8180
buffer.reset();
82-
return new Unpacker().unpack( buffer );
81+
return new Unpacker().unpack(buffer);
8382
}

0 commit comments

Comments
 (0)