1 # SPDX-FileCopyrightText: 2023 Philippe Proulx <eeppeliteloop@gmail.com>
2 # SPDX-License-Identifier: MIT
7 def test_init_labels():
8 labels
= {"yo": 0x88, "meow": 123} # type: normand.LabelsT
9 res
= normand
.parse("11 22 [yo:8] 33", init_labels
=labels
.copy())
10 assert res
.data
== bytearray([0x11, 0x22, 0x88, 0x33])
11 assert res
.labels
== labels
.copy()
15 variables
= {"zoom": 0x88, "bateau": -123.45} # type: normand.VariablesT
16 res
= normand
.parse("11 22 [zoom:8] 33", init_variables
=variables
.copy())
17 assert res
.data
== bytearray([0x11, 0x22, 0x88, 0x33])
18 assert res
.variables
== variables
.copy()
21 def test_init_offset():
22 res
= normand
.parse("11 22 [ICITTE:8] 33", init_offset
=0x23)
23 assert res
.data
== bytearray([0x11, 0x22, 0x25, 0x33])
24 assert res
.offset
== 0x27
27 def _test_init_bo(bo
: normand
.ByteOrder
):
31 if bo
== normand
.ByteOrder
.LE
:
32 h_byte
, l_byte
= l_byte
, h_byte
34 res
= normand
.parse("11 22 [-1993:16] 33", init_byte_order
=bo
)
35 assert res
.data
== bytearray([0x11, 0x22, h_byte
, l_byte
, 0x33])
36 assert res
.byte_order
== bo
39 def test_init_bo_be():
40 _test_init_bo(normand
.ByteOrder
.BE
)
43 def test_init_bo_le():
44 _test_init_bo(normand
.ByteOrder
.LE
)
47 def test_final_labels():
48 labels
= {"yo": 0x88, "meow": 123} # type: normand.LabelsT
50 "11 <june> 22 (77 <aug> 88) * 2 <kilo> 33", init_labels
=labels
.copy()
54 assert res
.labels
== labels
.copy()
57 def test_final_vars():
58 variables
= {"yo": 0x88, "meow": -123.45}
60 "11 {yo = 18.2} 22 (77 {zoom = ICITTE} 88) * 2 33",
61 init_variables
=variables
.copy(),
63 variables
["yo"] = 18.2
65 assert res
.variables
== variables
.copy()
68 def test_final_offset():
69 res
= normand
.parse("11 22 33 <32> 44 55")
70 assert res
.offset
== 34
73 def test_final_byte_order_none():
74 res
= normand
.parse("11 22 33 [-19:8] 44 55")
75 assert res
.byte_order
is None
78 def test_final_byte_order_be():
79 res
= normand
.parse("11 22 !le 33 [-19:8] 44 ( !be 88 ) * 3 55")
80 assert res
.byte_order
== normand
.ByteOrder
.BE
83 def test_final_byte_order_le():
84 res
= normand
.parse("11 22 !be 33 [-19:8] 44 ( !le 88 ) * 3 55")
85 assert res
.byte_order
== normand
.ByteOrder
.LE
89 res
= normand
.parse("# nothing to see here!\n")
90 assert len(res
.data
) == 0
91 assert len(res
.labels
) == 0
92 assert len(res
.variables
) == 0
93 assert res
.offset
== 0
This page took 0.031525 seconds and 4 git commands to generate.