Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/resource/class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,25 @@ def convert_camel_case_to_snake_case(string_: str) -> str:
if following_capital_chars:
formatted_str += f"_{char.lower()}"
last_capital_char = True
continue

remaining_str = "".join(string_[idx:])
# The 2 letters in the string; uppercase char followed by lowercase char.
# Example: `clusterIPs`, handle `Ps` at this point
if idx + 1 == str_len_for_idx_check:
formatted_str += remaining_str.lower()
break

# The last word in the string; uppercase followed by multiple lowercase chars
# Example: `dataVolumeTTLSeconds`, handle `Seconds` at this point
elif remaining_str.istitle():
formatted_str += f"_{remaining_str.lower()}"
break

else:
formatted_str += char.lower()
last_capital_char = True

else:
formatted_str += char.lower()
last_capital_char = True
Expand Down
15 changes: 13 additions & 2 deletions scripts/resource/tests/test_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ def test_parse_explain(tmpdir_factory, kind, debug_file, result_file):
),
pytest.param("XMLHttpRequest", "xml_http_request", id="combined_uppercase_word_is_first"),
pytest.param(
"additionalCORSAllowedOS", "additional_cors_allowed_os", id="combined_uppercase_word_in_the_middle"
"additionalCORSAllowedOS",
"additional_cors_allowed_os",
id="combined_uppercase_word_in_the_middle",
),
pytest.param("hostIPC", "host_ipc", id="combined_uppercase_word_is_last"),
pytest.param("clusterIPs", "cluster_ips", id="combined_uppercase_word_is_last_ends_with_lowercase"),
pytest.param(
"clusterIPs",
"cluster_ips",
id="combined_uppercase_word_is_last_ends_with_one_lowercase_char",
),
pytest.param(
"dataVolumeTTLSeconds",
"data_volume_ttl_seconds",
id="combined_uppercase_word_followed_by_uppercase_word_is_last_ends_with_lowercase",
),
],
)
def test_convert_camel_case_to_snake_case(camel_case_str, expected):
Expand Down