@@ -36,11 +36,50 @@ pub fn bit_size_erlang_only_test() {
36
36
}
37
37
38
38
pub fn byte_size_test ( ) {
39
- bit_array . byte_size ( bit_array . from_string ( "hello" ) )
39
+ bit_array . byte_size ( << >> )
40
+ |> should . equal ( 0 )
41
+
42
+ bit_array . byte_size ( << 0 , 1 , 2 , 3 , 4 >> )
40
43
|> should . equal ( 5 )
44
+ }
41
45
42
- bit_array . byte_size ( bit_array . from_string ( "" ) )
43
- |> should . equal ( 0 )
46
+ // This test is target specific since it's using non byte-aligned BitArrays
47
+ // and those are not supported on the JavaScript target.
48
+ @ target ( erlang )
49
+ pub fn byte_size_erlang_only_test ( ) {
50
+ bit_array . byte_size ( << 1 , 2 , 3 : 6 >> )
51
+ |> should . equal ( 3 )
52
+ }
53
+
54
+ pub fn pad_to_bytes_test ( ) {
55
+ << >>
56
+ |> bit_array . pad_to_bytes
57
+ |> should . equal ( << >> )
58
+
59
+ << 0xAB >>
60
+ |> bit_array . pad_to_bytes
61
+ |> should . equal ( << 0xAB >> )
62
+
63
+ << 0xAB , 0x12 >>
64
+ |> bit_array . pad_to_bytes
65
+ |> should . equal ( << 0xAB , 0x12 >> )
66
+ }
67
+
68
+ // This test is target specific since it's using non byte-aligned BitArrays
69
+ // and those are not supported on the JavaScript target.
70
+ @ target ( erlang )
71
+ pub fn pad_to_bytes_erlang_only_test ( ) {
72
+ << 1 : 1 >>
73
+ |> bit_array . pad_to_bytes
74
+ |> should . equal ( << 0x80 >> )
75
+
76
+ << - 1 : 7 >>
77
+ |> bit_array . pad_to_bytes
78
+ |> should . equal ( << 0xFE >> )
79
+
80
+ << 0xAB , 0x12 , 3 : 3 >>
81
+ |> bit_array . pad_to_bytes
82
+ |> should . equal ( << 0xAB , 0x12 , 0x60 >> )
44
83
}
45
84
46
85
pub fn not_equal_test ( ) {
@@ -85,9 +124,25 @@ pub fn concat_test() {
85
124
// and those are not supported on the JavaScript target.
86
125
@ target ( erlang )
87
126
pub fn concat_erlang_only_test ( ) {
127
+ [ << - 1 : 32 >> , << 0 : 1 >> , << 0 : 0 >> ]
128
+ |> bit_array . concat
129
+ |> should . equal ( << 255 , 255 , 255 , 255 , 0 : 1 >> )
130
+
131
+ [ << - 20 : 6 , 2 >> , << 3 : 4 >> , << 7 : 3 >> , << - 1 : 64 >> ]
132
+ |> bit_array . concat
133
+ |> should . equal ( << 176 , 8 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 31 : size( 5 ) >> )
134
+
88
135
[ << 1 , 2 : 4 >> , << 3 >> ]
89
136
|> bit_array . concat
90
137
|> should . equal ( << 1 , 2 : 4 , 3 >> )
138
+
139
+ [ << - 1 : 32 >> , << 0 : 1 >> , << 0 : 0 >> ]
140
+ |> bit_array . concat
141
+ |> should . equal ( << 255 , 255 , 255 , 255 , 0 : 1 >> )
142
+
143
+ [ << - 20 : 6 , 2 >> , << 3 : 4 >> , << 7 : 3 >> , << - 1 : 64 >> ]
144
+ |> bit_array . concat
145
+ |> should . equal ( << 176 , 8 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 31 : size( 5 ) >> )
91
146
}
92
147
93
148
pub fn slice_test ( ) {
@@ -133,6 +188,19 @@ pub fn slice_test() {
133
188
|> should . equal ( Ok ( << "b" : utf8 >> ) )
134
189
}
135
190
191
+ // This test is target specific since it's using non byte-aligned BitArrays
192
+ // and those are not supported on the JavaScript target.
193
+ @ target ( erlang )
194
+ pub fn slice_erlang_onyl_test ( ) {
195
+ << 0 , 1 , 2 : 7 >>
196
+ |> bit_array . slice ( 0 , 3 )
197
+ |> should . equal ( Error ( Nil ) )
198
+
199
+ << 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 >>
200
+ |> bit_array . slice ( 8 , 12 )
201
+ |> should . equal ( Error ( Nil ) )
202
+ }
203
+
136
204
pub fn to_string_test ( ) {
137
205
<< >>
138
206
|> bit_array . to_string
@@ -155,6 +223,15 @@ pub fn to_string_test() {
155
223
|> should . equal ( Error ( Nil ) )
156
224
}
157
225
226
+ // This test is target specific since it's using non byte-aligned BitArrays
227
+ // and those are not supported on the JavaScript target.
228
+ @ target ( erlang )
229
+ pub fn to_string_erlang_only_test ( ) {
230
+ << "ø" : utf8 , 50 : 4 >>
231
+ |> bit_array . to_string
232
+ |> should . equal ( Error ( Nil ) )
233
+ }
234
+
158
235
pub fn is_utf8_test ( ) {
159
236
<< >>
160
237
|> bit_array . is_utf8
@@ -207,6 +284,23 @@ pub fn base64_encode_test() {
207
284
) )
208
285
}
209
286
287
+ // This test is target specific since it's using non byte-aligned BitArrays
288
+ // and those are not supported on the JavaScript target.
289
+ @ target ( erlang )
290
+ pub fn base64_erlang_only_encode_test ( ) {
291
+ << - 1 : 7 >>
292
+ |> bit_array . base64_encode ( True )
293
+ |> should . equal ( "/g==" )
294
+
295
+ << 0xFA , 5 : 3 >>
296
+ |> bit_array . base64_encode ( True )
297
+ |> should . equal ( "+qA=" )
298
+
299
+ << 0xFA , 0xBC , 0x6D , 1 : 1 >>
300
+ |> bit_array . base64_encode ( True )
301
+ |> should . equal ( "+rxtgA==" )
302
+ }
303
+
210
304
pub fn base64_decode_test ( ) {
211
305
"/3/+/A=="
212
306
|> bit_array . base64_decode ( )
@@ -305,6 +399,27 @@ pub fn base16_test() {
305
399
|> should . equal ( "A1B2C3D4E5F67891" )
306
400
}
307
401
402
+ // This test is target specific since it's using non byte-aligned BitArrays
403
+ // and those are not supported on the JavaScript target.
404
+ @ target ( erlang )
405
+ pub fn base16_encode_erlang_only_test ( ) {
406
+ << - 1 : 7 >>
407
+ |> bit_array . base16_encode ( )
408
+ |> should . equal ( "FE" )
409
+
410
+ << 0xFA , 5 : 3 >>
411
+ |> bit_array . base16_encode ( )
412
+ |> should . equal ( "FAA0" )
413
+
414
+ << 0xFA , 5 : 4 >>
415
+ |> bit_array . base16_encode ( )
416
+ |> should . equal ( "FA50" )
417
+
418
+ << 0xFA , 0xBC , 0x6D , 1 : 1 >>
419
+ |> bit_array . base16_encode ( )
420
+ |> should . equal ( "FABC6D80" )
421
+ }
422
+
308
423
pub fn base16_decode_test ( ) {
309
424
bit_array . base16_decode ( "" )
310
425
|> should . equal ( Ok ( << >> ) )
@@ -353,7 +468,7 @@ pub fn inspect_test() {
353
468
// This test is target specific since it's using non byte-aligned BitArrays
354
469
// and those are not supported on the JavaScript target.
355
470
@ target ( erlang )
356
- pub fn inspect_partial_bytes_test ( ) {
471
+ pub fn inspect_erlang_only_test ( ) {
357
472
bit_array . inspect ( << 4 : 5 >> )
358
473
|> should . equal ( "<<4:size(5)>>" )
359
474
@@ -365,7 +480,7 @@ pub fn inspect_partial_bytes_test() {
365
480
}
366
481
367
482
@ target ( erlang )
368
- pub fn compare_different_sizes_test ( ) {
483
+ pub fn compare_test ( ) {
369
484
bit_array . compare ( << 4 : 5 >> , << 4 : 5 >> )
370
485
|> should . equal ( order . Eq )
371
486
@@ -458,4 +573,10 @@ pub fn starts_with_erlang_only_test() {
458
573
459
574
bit_array . starts_with ( << 0 : 127 >> , << 1 : 127 >> )
460
575
|> should . be_false
576
+
577
+ bit_array . starts_with ( << 0xFF , 0x81 >> , << 0xFF , 1 : 1 >> )
578
+ |> should . be_true
579
+
580
+ bit_array . starts_with ( << 0xFF , 0x81 >> , << 0xFF , 0 : 1 >> )
581
+ |> should . be_false
461
582
}
0 commit comments