1717 * limitations under the License.
1818 */
1919
20- var alloc = require ( '../../lib/v1/internal/buf' ) . alloc ;
21- var CombinedBuffer = require ( '../../lib/v1/internal/buf' ) . CombinedBuffer ;
22- var utf8 = require ( '../../lib/v1/internal/utf8' ) . default ;
23- var Unpacker = require ( "../../lib/v1/internal/packstream.js" ) . Unpacker ;
20+ import { Unpacker } from '../../src/v1/internal/packstream-v1' ;
21+ import utf8 from '../../src/v1/internal/utf8' ;
22+ import { alloc , CombinedBuffer } from '../../src/v1/internal/buf' ;
2423
25- describe ( 'buffers' , function ( ) {
26- it ( 'should have helpful toString' , function ( ) {
24+ describe ( 'buffers' , ( ) => {
25+
26+ it ( 'should have helpful toString' , ( ) => {
2727 // Given
28- var b = alloc ( 4 ) ;
28+ const b = alloc ( 4 ) ;
2929 b . writeInt8 ( 1 ) ;
3030 b . writeInt8 ( 8 ) ;
3131 b . writeInt8 ( 15 ) ;
3232 b . writeInt8 ( 127 ) ;
3333
3434 // When
35- var str = b . toString ( ) ;
36- var hex = b . toHex ( ) ;
35+ const str = b . toString ( ) ;
36+ const hex = b . toHex ( ) ;
3737
3838 // Then
39- expect ( str ) . toContain ( " ( position=4 )\n 01 08 0f 7f" ) ;
40- expect ( hex ) . toBe ( " 01 08 0f 7f " ) ;
39+ expect ( str ) . toContain ( ' ( position=4 )\n 01 08 0f 7f' ) ;
40+ expect ( hex ) . toBe ( ' 01 08 0f 7f ' ) ;
4141 } ) ;
4242
43- it ( 'should read and write 8-bit unsigned integers' , function ( ) {
43+ it ( 'should read and write 8-bit unsigned integers' , ( ) => {
4444 // Given
45- var b = alloc ( 1 ) ;
45+ const b = alloc ( 1 ) ;
4646
47- for ( var i = 0 ; i < 7 ; i ++ ) {
48- var n = Math . pow ( 2 , i ) ;
47+ for ( let i = 0 ; i < 7 ; i ++ ) {
48+ const n = Math . pow ( 2 , i ) ;
4949
5050 // When
51- b . putUInt8 ( 0 , n ) ;
51+ b . putUInt8 ( 0 , n ) ;
5252
5353 // Then
54- expect ( b . getUInt8 ( 0 ) ) . toBe ( n ) ;
54+ expect ( b . getUInt8 ( 0 ) ) . toBe ( n ) ;
5555 }
5656 } ) ;
5757
58- it ( 'should read and write 16-bit unsigned integers' , function ( ) {
58+ it ( 'should read and write 16-bit unsigned integers' , ( ) => {
5959 // Given
60- var b = alloc ( 2 ) ;
60+ const b = alloc ( 2 ) ;
6161
62- for ( var i = 0 ; i < 15 ; i ++ ) {
63- var n = Math . pow ( 2 , i ) ;
62+ for ( let i = 0 ; i < 15 ; i ++ ) {
63+ const n = Math . pow ( 2 , i ) ;
6464
6565 // When
66- b . putUInt16 ( 0 , n ) ;
66+ b . putUInt16 ( 0 , n ) ;
6767
6868 // Then
69- expect ( b . getUInt16 ( 0 ) ) . toBe ( n ) ;
69+ expect ( b . getUInt16 ( 0 ) ) . toBe ( n ) ;
7070 }
7171 } ) ;
7272
73- it ( 'should read and write 32-bit unsigned integers' , function ( ) {
73+ it ( 'should read and write 32-bit unsigned integers' , ( ) => {
7474 // Given
75- var b = alloc ( 4 ) ;
75+ const b = alloc ( 4 ) ;
7676
77- for ( var i = 0 ; i < 30 ; i ++ ) {
78- var n = Math . pow ( 2 , i ) ;
77+ for ( let i = 0 ; i < 30 ; i ++ ) {
78+ const n = Math . pow ( 2 , i ) ;
7979
8080 // When
81- b . putUInt32 ( 0 , n ) ;
81+ b . putUInt32 ( 0 , n ) ;
8282
8383 // Then
84- expect ( b . getUInt32 ( 0 ) ) . toBe ( n ) ;
84+ expect ( b . getUInt32 ( 0 ) ) . toBe ( n ) ;
8585 }
8686 } ) ;
8787
88- it ( 'should read and write 8-bit signed integers' , function ( ) {
88+ it ( 'should read and write 8-bit signed integers' , ( ) => {
8989 // Given
90- var b = alloc ( 1 ) ;
90+ const b = alloc ( 1 ) ;
9191
92- for ( var i = 0 ; i < 6 ; i ++ ) {
93- var n = Math . pow ( 2 , i ) ;
92+ for ( let i = 0 ; i < 6 ; i ++ ) {
93+ const n = Math . pow ( 2 , i ) ;
9494
9595 // When
96- b . putInt8 ( 0 , n ) ;
96+ b . putInt8 ( 0 , n ) ;
9797
9898 // Then
99- expect ( b . getInt8 ( 0 ) ) . toBe ( n ) ;
99+ expect ( b . getInt8 ( 0 ) ) . toBe ( n ) ;
100100 }
101101 } ) ;
102102
103- it ( 'should read and write 16-bit signed integers' , function ( ) {
103+ it ( 'should read and write 16-bit signed integers' , ( ) => {
104104 // Given
105- var b = alloc ( 2 ) ;
105+ const b = alloc ( 2 ) ;
106106
107- for ( var i = 0 ; i < 14 ; i ++ ) {
108- var n = Math . pow ( 2 , i ) ;
107+ for ( let i = 0 ; i < 14 ; i ++ ) {
108+ const n = Math . pow ( 2 , i ) ;
109109
110110 // When
111- b . putInt16 ( 0 , n ) ;
111+ b . putInt16 ( 0 , n ) ;
112112
113113 // Then
114- expect ( b . getInt16 ( 0 ) ) . toBe ( n ) ;
114+ expect ( b . getInt16 ( 0 ) ) . toBe ( n ) ;
115115 }
116116 } ) ;
117117
118- it ( 'should read and write 32-bit signed integers' , function ( ) {
118+ it ( 'should read and write 32-bit signed integers' , ( ) => {
119119 // Given
120- var b = alloc ( 4 ) ;
120+ const b = alloc ( 4 ) ;
121121
122- for ( var i = 0 ; i < 30 ; i ++ ) {
123- var n = Math . pow ( 2 , i ) ;
122+ for ( let i = 0 ; i < 30 ; i ++ ) {
123+ const n = Math . pow ( 2 , i ) ;
124124
125125 // When
126- b . putInt32 ( 0 , n ) ;
126+ b . putInt32 ( 0 , n ) ;
127127
128128 // Then
129- expect ( b . getInt32 ( 0 ) ) . toBe ( n ) ;
129+ expect ( b . getInt32 ( 0 ) ) . toBe ( n ) ;
130130 }
131131 } ) ;
132132
133- it ( 'should encode list correctly' , function ( ) {
133+ it ( 'should encode list correctly' , ( ) => {
134134 // Given
135- var b = alloc ( 5 ) ;
135+ let b = alloc ( 5 ) ;
136136 b . writeUInt8 ( 0x90 | 0x2 ) ;
137137 b = writeString ( b , 'a' ) ;
138138 b = writeString ( b , 'b' ) ;
139139 // When
140- var hex = b . toHex ( ) ;
140+ const hex = b . toHex ( ) ;
141141 // Then
142- expect ( hex ) . toBe ( " 92 81 61 81 62 " ) ;
142+ expect ( hex ) . toBe ( ' 92 81 61 81 62 ' ) ;
143143 } ) ;
144144
145- it ( 'should decode list correctly' , function ( ) {
145+ it ( 'should decode list correctly' , ( ) => {
146146 // Given
147- var b = alloc ( 5 ) ;
147+ const b = alloc ( 5 ) ;
148148 b . writeUInt8 ( 0x92 ) ;
149149 b . writeUInt8 ( 0x81 ) ;
150150 b . writeUInt8 ( 0x61 ) ;
@@ -153,51 +153,52 @@ describe('buffers', function() {
153153 b . reset ( ) ;
154154
155155 // When
156- var data = new Unpacker ( ) . unpack ( b ) ;
156+ const data = new Unpacker ( ) . unpack ( b ) ;
157157
158158 // Then
159159 expect ( data [ 0 ] ) . toBe ( 'a' ) ;
160160 expect ( data [ 1 ] ) . toBe ( 'b' ) ;
161161 } ) ;
162162} ) ;
163163
164- describe ( 'CombinedBuffer' , function ( ) {
165- it ( 'should read int8' , function ( ) {
164+ describe ( 'CombinedBuffer' , ( ) => {
165+
166+ it ( 'should read int8' , ( ) => {
166167 // Given
167- var b1 = alloc ( 1 ) ;
168- var b2 = alloc ( 1 ) ;
168+ const b1 = alloc ( 1 ) ;
169+ const b2 = alloc ( 1 ) ;
169170 b1 . putInt8 ( 0 , 1 ) ;
170171 b2 . putInt8 ( 0 , 2 ) ;
171172
172- var b = new CombinedBuffer ( [ b1 , b2 ] ) ;
173-
173+ const b = new CombinedBuffer ( [ b1 , b2 ] ) ;
174+
174175 // When
175- var first = b . readInt8 ( ) ;
176- var second = b . readInt8 ( ) ;
176+ const first = b . readInt8 ( ) ;
177+ const second = b . readInt8 ( ) ;
177178
178179 // Then
179180 expect ( first ) . toBe ( 1 ) ;
180181 expect ( second ) . toBe ( 2 ) ;
181182 } ) ;
182183
183- it ( 'should read divided float64' , function ( ) {
184+ it ( 'should read divided float64' , ( ) => {
184185 // Given
185- var inner = alloc ( 8 ) ;
186+ const inner = alloc ( 8 ) ;
186187 inner . putFloat64 ( 0 , 0.1 ) ;
187188
188- var b = new CombinedBuffer ( [ inner . readSlice ( 4 ) , inner . readSlice ( 4 ) ] ) ;
189-
189+ const b = new CombinedBuffer ( [ inner . readSlice ( 4 ) , inner . readSlice ( 4 ) ] ) ;
190+
190191 // When
191- var read = b . readFloat64 ( ) ;
192+ const read = b . readFloat64 ( ) ;
192193
193194 // Then
194195 expect ( read ) . toBe ( 0.1 ) ;
195196 } ) ;
196197} ) ;
197198
198199function writeString ( b , str ) {
199- var bytes = utf8 . encode ( str ) ;
200- var size = bytes . length ;
200+ const bytes = utf8 . encode ( str ) ;
201+ const size = bytes . length ;
201202 b . writeUInt8 ( 0x80 | size ) ;
202203 b . writeBytes ( bytes ) ;
203204 return b ;
0 commit comments