11import lightbug.protocol show *
2- import log
32
43main :
54 addAndget-data
@@ -11,61 +10,61 @@ from-bytes:
1110 // no data fileds
1211 d := Data .from-bytes #[ 0x00 , 0x00 ]
1312 if d .data-field-count != 0 :
14- log . error "❌ Failed getting data-field-count of empty data, got: " + d .data-field-count .stringify
13+ print "❌ Failed getting data-field-count of empty data, got: " + d .data-field-count .stringify
1514 else:
16- log . info "✅ Passed getting data-field-count of empty data"
15+ print "✅ Passed getting data-field-count of empty data"
1716
1817 // a single uint8 of type 1 value 2
1918 d = Data .from-bytes #[ 0x01 , 0x00 , 0x01 , 0x01 , 0x02 ]
2019 if d .data-field-count != 1 :
21- log . error "❌ Failed getting data-field-count of single data field, got: " + d .data-field-count .stringify
20+ print "❌ Failed getting data-field-count of single data field, got: " + d .data-field-count .stringify
2221 else:
23- log . info "✅ Passed getting data-field-count of single data field"
22+ print "✅ Passed getting data-field-count of single data field"
2423
2524 // uint8 of type 1 value 2, and 2 bytes of type 5, value 8 8
2625 d = Data .from-bytes #[ 0x02 , 0x00 , 0x01 , 0x05 , 0x01 , 0x02 , 0x02 , 0x08 , 0x08 ]
2726 if d .data-field-count != 2 :
28- log . error "❌ Failed getting data-field-count of 2 data fields, got: " + d .data-field-count .stringify
27+ print "❌ Failed getting data-field-count of 2 data fields, got: " + d .data-field-count .stringify
2928 else:
30- log . info "✅ Passed getting data-field-count of 2 data fields"
29+ print "✅ Passed getting data-field-count of 2 data fields"
3130
3231from-list :
3332 // no data fileds
3433 d := Data .from-list [ 0x00 , 0x00 ]
3534 if d .data-field-count != 0 :
36- log . error "❌ LIST Failed getting data-field-count of empty data, got: " + d .data-field-count .stringify
35+ print "❌ LIST Failed getting data-field-count of empty data, got: " + d .data-field-count .stringify
3736 else:
38- log . info "✅ LIST Passed getting data-field-count of empty data"
37+ print "✅ LIST Passed getting data-field-count of empty data"
3938
4039 // a single uint8 of type 1 value 2
4140 d = Data .from-list [ 0x01 , 0x00 , 0x01 , 0x01 , 0x02 ]
4241 if d .data-field-count != 1 :
43- log . error "❌ LIST Failed getting data-field-count of single data field, got: " + d .data-field-count .stringify
42+ print "❌ LIST Failed getting data-field-count of single data field, got: " + d .data-field-count .stringify
4443 else:
45- log . info "✅ LIST Passed getting data-field-count of single data field"
44+ print "✅ LIST Passed getting data-field-count of single data field"
4645
4746 // uint8 of type 1 value 2, and 2 bytes of type 5, value 8 8
4847 d = Data .from-list [ 0x02 , 0x00 , 0x01 , 0x05 , 0x01 , 0x02 , 0x02 , 0x08 , 0x08 ]
4948 if d .data-field-count != 2 :
50- log . error "❌ LIST Failed getting data-field-count of 2 data fields, got: " + d .data-field-count .stringify
49+ print "❌ LIST Failed getting data-field-count of 2 data fields, got: " + d .data-field-count .stringify
5150 else:
52- log . info "✅ LIST Passed getting data-field-count of 2 data fields"
51+ print "✅ LIST Passed getting data-field-count of 2 data fields"
5352
5453toBytes :
5554 d := Data
5655 d .add-data-uint8 1 6
5756 b := d .bytes-for-protocol
5857 if b != #[ 0x01 , 0x00 , 0x01 , 0x01 , 0x06 ] :
59- log . error "❌ Failed toBytes single uint8, got: $ b "
58+ print "❌ Failed toBytes single uint8, got: $ b "
6059 else:
61- log . info "✅ Passed toBytes single uint8"
60+ print "✅ Passed toBytes single uint8"
6261
6362 d .add-data 5 #[ 8 , 8 ]
6463 b = d .bytes-for-protocol
6564 if b != #[ 0x02 , 0x00 , 0x01 , 0x05 , 0x01 , 0x06 , 0x02 , 0x08 , 0x08 ] :
66- log . error "❌ Failed toBytes 2 data fields, got: $ b "
65+ print "❌ Failed toBytes 2 data fields, got: $ b "
6766 else:
68- log . info "✅ Passed toBytes 2 data fields"
67+ print "✅ Passed toBytes 2 data fields"
6968
7069addAndget-data :
7170 d := Data
@@ -76,25 +75,25 @@ addAndget-data:
7675 // Test uint32
7776 d .add-data-uint32 1 290
7877 if ( d .get-data 1 ) != #[ 0x22 , 0x01 , 0x00 , 0x00 ] :
79- log . error "❌ Failed uint32 byte representation"
78+ print "❌ Failed uint32 byte representation"
8079 else:
81- log . info "✅ Passed uint32 byte representation"
80+ print "✅ Passed uint32 byte representation"
8281
8382 // Test int32
8483 d .add-data-int32 2 290
8584 if ( d .get-data 2 ) != #[ 0x22 , 0x01 , 0x00 , 0x00 ] :
86- log . error "❌ Failed int32 byte representation"
85+ print "❌ Failed int32 byte representation"
8786 else:
88- log . info "✅ Passed int32 byte representation"
87+ print "✅ Passed int32 byte representation"
8988
9089 // Test float
9190 d .add-data-float32 3 3.1415927
9291 got := d .get-data 3
9392 expect := #[ 0xdb , 0x0f , 0x49 , 0x40 ]
9493 if got != expect :
95- log . error "❌ Failed float byte representation. Expected: $ expect , got: $ got "
94+ print "❌ Failed float byte representation. Expected: $ expect , got: $ got "
9695 else:
97- log . info "✅ Passed float byte representation"
96+ print "✅ Passed float byte representation"
9897
9998 ////////////////
10099 // Round trips
@@ -103,49 +102,49 @@ addAndget-data:
103102 // Test uint32 roundtrip
104103 d .add-data-uint32 4 290
105104 if ( d .get-data-uint32 4 ) != 290 :
106- log . error "❌ Failed uint32 roundtrip"
105+ print "❌ Failed uint32 roundtrip"
107106 else:
108- log . info "✅ Passed uint32 roundtrip"
107+ print "✅ Passed uint32 roundtrip"
109108
110109 // Test int32 roundtrip
111110 d .add-data-int32 5 -290
112111 if ( d .get-data-int32 5 ) != -290 :
113- log . error "❌ Failed int32 roundtrip"
112+ print "❌ Failed int32 roundtrip"
114113 else:
115- log . info "✅ Passed int32 roundtrip"
114+ print "✅ Passed int32 roundtrip"
116115
117116 // Float roundtrip
118117 expected := 3.1400001049041748047
119118 d .add-data-float32 6 expected
120119 gotFloat := d .get-data-float32 6
121120 if gotFloat != expected :
122- log . error "❌ Failed float roundtrip. Expected: $ expected , got: $ gotFloat "
121+ print "❌ Failed float roundtrip. Expected: $ expected , got: $ gotFloat "
123122 else:
124- log . info "✅ Passed float roundtrip"
123+ print "✅ Passed float roundtrip"
125124
126125 // list uint16 roundtrip
127126 expectedList := [ 1 , 2 , 3 ]
128127 d .add-data-list-uint16 7 expectedList
129128 gotList := d .get-data-list-uint16 7
130129 if gotList != expectedList :
131- log . error "❌ Failed list uint16 roundtrip. Expected: $ expectedList , got: $ gotList "
130+ print "❌ Failed list uint16 roundtrip. Expected: $ expectedList , got: $ gotList "
132131 else:
133- log . info "✅ Passed list uint16 roundtrip"
132+ print "✅ Passed list uint16 roundtrip"
134133
135134 // list uint32 roundtrip
136135 expectedListUint32 := [ 100000 , 200000 , 300000 ]
137136 d .add-data-list-uint32 8 expectedListUint32
138137 gotListUint32 := d .get-data-list-uint32 8
139138 if gotListUint32 != expectedListUint32 :
140- log . error "❌ Failed list uint32 roundtrip. Expected: $ expectedListUint32 , got: $ gotListUint32 "
139+ print "❌ Failed list uint32 roundtrip. Expected: $ expectedListUint32 , got: $ gotListUint32 "
141140 else:
142- log . info "✅ Passed list uint32 roundtrip"
141+ print "✅ Passed list uint32 roundtrip"
143142
144143 // list int32 pairs roundtrip
145144 expectedListInt32Pairs := [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ]
146145 d .add-data-list-int32-pairs 9 expectedListInt32Pairs
147146 gotListInt32Pairs := d .get-data-list-int32-pairs 9
148147 if gotListInt32Pairs != expectedListInt32Pairs :
149- log . error "❌ Failed list int32 pairs roundtrip. Expected: $ expectedListInt32Pairs , got: $ gotListInt32Pairs "
148+ print "❌ Failed list int32 pairs roundtrip. Expected: $ expectedListInt32Pairs , got: $ gotListInt32Pairs "
150149 else:
151- log . info "✅ Passed list int32 pairs roundtrip"
150+ print "✅ Passed list int32 pairs roundtrip"
0 commit comments