diff --git a/idf_build_apps/manifest/soc_header.py b/idf_build_apps/manifest/soc_header.py index e739fc4..34ea051 100644 --- a/idf_build_apps/manifest/soc_header.py +++ b/idf_build_apps/manifest/soc_header.py @@ -42,7 +42,7 @@ # Define value, either a hex, int or a string _hex_value = Combine(Literal('0x') + Word(hexnums) + Optional(_literal_suffix).suppress())('hex_value') _str_value = QuotedString('"')('str_value') -_int_value = Word(nums)('int_value') + ~Char('.') + Optional(_literal_suffix)('literal_suffix') +_int_value = Combine(Optional('-') + Word(nums))('int_value') + ~Char('.') + Optional(_literal_suffix)('literal_suffix') # Remove optional parenthesis around values _value = Optional('(').suppress() + MatchFirst([_hex_value, _str_value, _int_value])('value') + Optional(')').suppress() diff --git a/tests/test_soc_caps.py b/tests/test_soc_caps.py new file mode 100644 index 0000000..be1ab25 --- /dev/null +++ b/tests/test_soc_caps.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +from idf_build_apps.manifest.soc_header import parse_define + + +@pytest.mark.parametrize( + 's, res', + [ + ('#define SOC_FOO (4)', '4'), + ('#define SOC_FOO (-4)', '-4'), + ('#define SOC_FOO 4', '4'), + ('#define SOC_FOO -4', '-4'), + ], +) +def test_parse_define_int(s, res): + parse_result = parse_define(s) + assert parse_result['name'] == 'SOC_FOO' + assert parse_result['int_value'] == res