|
| 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 | +}); |
0 commit comments