summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2023-05-05 14:41:18 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2023-05-08 14:34:56 +0200
commitd51b4e507dc2768930dc75a1e7d9e53e0b618b94 (patch)
treec40208a09730e355131446c69600cde8f832c75c
parentcontent: Support array parameters (diff)
downloadrtems-central-d51b4e507dc2768930dc75a1e7d9e53e0b618b94.tar.bz2
content: Fix to_camel_case()
Make sure the result starts with a valid character.
-rw-r--r--rtemsspec/content.py5
-rw-r--r--rtemsspec/tests/test_content.py7
2 files changed, 9 insertions, 3 deletions
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 9045c890..2b3c33e1 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -1193,9 +1193,10 @@ _CAMEL_CASE_DISCARD = re.compile(r"[^ \t\n\r\f\va-zA-Z0-9]")
def to_camel_case(name: str) -> str:
""" Returns the name in CamelCase. """
- return name[0].upper() + _CAMEL_CASE_TO_UPPER.sub(
+ name = _CAMEL_CASE_TO_UPPER.sub(
lambda match: match.group(1).upper(),
- _CAMEL_CASE_DISCARD.sub(" ", name[1:].replace("+", "X")))
+ _CAMEL_CASE_DISCARD.sub(" ", name.replace("+", "X")))
+ return f"{name[0].upper()}{name[1:]}"
def get_integer_type(value: int) -> str:
diff --git a/rtemsspec/tests/test_content.py b/rtemsspec/tests/test_content.py
index 517bb070..f794c96b 100644
--- a/rtemsspec/tests/test_content.py
+++ b/rtemsspec/tests/test_content.py
@@ -28,7 +28,12 @@ import os
import pytest
from rtemsspec.content import Content, enabled_by_to_exp, \
- ExpressionMapper, PythonExpressionMapper
+ ExpressionMapper, PythonExpressionMapper, to_camel_case
+
+
+def test_to_camel_case():
+ assert to_camel_case("/x") == "X"
+ assert to_camel_case("/ab cd?ef+") == "AbCdEfX"
def test_tab():