Skip to content

Commit

Permalink
fix: negative value for soc caps integer
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev committed Dec 20, 2024
1 parent e2ee173 commit 494be97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion idf_build_apps/manifest/soc_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions tests/test_soc_caps.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 494be97

Please sign in to comment.