Skip to content

Commit 2ef6896

Browse files
committed
Add tests for BitString and Tuple
1 parent 4d157e5 commit 2ef6896

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

test/bit_string_test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ErlangTypes from '../src/index.js';
2+
import chai from 'chai';
3+
const expect = chai.expect;
4+
5+
const BitString = ErlangTypes.BitString;
6+
7+
describe('BitString', function(){
8+
9+
describe('creation', function(){
10+
it('create properly', function(){
11+
let bs = new BitString(BitString.integer(1));
12+
expect(bs.value).to.eql([1]);
13+
14+
bs = new BitString(BitString.binary("foo"));
15+
expect(bs.value).to.eql([102, 111, 111]);
16+
17+
bs = new BitString(BitString.integer(0), BitString.binary("foo"));
18+
expect(bs.value).to.eql([0, 102, 111, 111]);
19+
20+
bs = new BitString(BitString.float(3.14));
21+
expect(bs.value).to.eql([64, 9, 30, 184, 81, 235, 133, 31]);
22+
23+
bs = new BitString(BitString.signed(BitString.integer(-100)));
24+
expect(bs.value).to.eql([156]);
25+
});
26+
});
27+
28+
describe('UTF conversions', function(){
29+
it('toUTF8Array', function(){
30+
let bs = BitString.toUTF8Array("fo≈");
31+
expect(bs).to.eql([102, 111, 226, 137, 136]);
32+
});
33+
34+
it('toUTF16Array', function(){
35+
let bs = BitString.toUTF16Array("fo≈");
36+
expect(bs).to.eql([0, 102, 0, 111, 34, 72]);
37+
});
38+
39+
it('toUTF32Array', function(){
40+
let bs = BitString.toUTF32Array("fo≈");
41+
expect(bs).to.eql([0, 0, 0, 102, 0, 0, 0, 111, 0, 0, 34, 72]);
42+
});
43+
});
44+
45+
describe('Float conversions', function(){
46+
it('float32ToBytes', function(){
47+
let bs = BitString.float32ToBytes(3.14);
48+
expect(bs).to.eql([64, 72, 245, 195]);
49+
});
50+
51+
it('float64ToBytes', function(){
52+
let bs = BitString.float64ToBytes(3.14);
53+
expect(bs).to.eql([64, 9, 30, 184, 81, 235, 133, 31]);
54+
});
55+
});
56+
});

test/tuple_test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import ErlangTypes from '../src/index.js';
2+
import chai from 'chai';
3+
const expect = chai.expect;
4+
5+
const Tuple = ErlangTypes.Tuple;
6+
7+
describe('Tuple', function(){
8+
9+
describe('toString', function(){
10+
it('empty', function(){
11+
expect(new Tuple().toString()).to.eql('{}');
12+
});
13+
14+
it('one element', function(){
15+
expect(new Tuple(1).toString()).to.eql('{1}');
16+
});
17+
18+
it('multiple elements', function(){
19+
expect(new Tuple(1, 2, 3).toString()).to.eql('{1, 2, 3}');
20+
});
21+
});
22+
23+
describe('count', function(){
24+
it('empty', function(){
25+
expect(new Tuple().count()).to.eql(0);
26+
});
27+
28+
it('one element', function(){
29+
expect(new Tuple(1).count()).to.eql(1);
30+
});
31+
32+
it('multiple elements', function(){
33+
expect(new Tuple(1, 2, 3).count()).to.eql(3);
34+
});
35+
});
36+
37+
describe('get', function(){
38+
it('empty', function(){
39+
expect(new Tuple().get(0)).to.eql(undefined);
40+
});
41+
42+
it('one element', function(){
43+
expect(new Tuple(1).get(0)).to.eql(1);
44+
});
45+
46+
it('multiple elements', function(){
47+
expect(new Tuple(1, 2, 3).get(1)).to.eql(2);
48+
});
49+
});
50+
51+
});

0 commit comments

Comments
 (0)