schemagen: deduplicate enum constants that collide after sanitization #11

Merged
andrew merged 2 commits from weaselbot/weaseljson:weaselbot/issue-4 into main 2026-06-18 20:01:09 +00:00
Member

Closes #4

Closes #4
weaselbot added 1 commit 2026-06-18 15:03:10 +00:00
schemagen: deduplicate enum constants that collide after sanitization
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Successful in 51s
CI / pre-commit (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Successful in 1m29s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Successful in 1m22s
359f4f4bb6
Distinct JSON enum values can sanitize to the same C++ identifier
(e.g. "foo-bar" and "foo_bar" both become `foo_bar`), producing an
invalid `enum class` with duplicate constants.

Add `unique_enum_identifiers()` which appends a numeric suffix to
later collisions while preserving enum declaration order, so the
index-to-JSON-value mapping used by the generated parser stays intact.

Also add contrib/schemagen/test_schemagen.py and wire the schemagen
Python tests plus the existing example.schema.json/test_gen.cpp example
into ctest via CMakeLists.txt.

Closes #4
weaselbot force-pushed weaselbot/issue-4 from 595be0c338 to 359f4f4bb6 2026-06-18 15:03:10 +00:00 Compare
andrew requested changes 2026-06-18 18:04:36 +00:00
CMakeLists.txt Outdated
@@ -170,6 +170,38 @@ if(Python3_Interpreter_FOUND)
${CMAKE_CURRENT_SOURCE_DIR}/test_python_bindings.py)
endif()
# schemagen tests
Owner

Can we put this in contrib/schemagen/CMakeLists.txt?

Can we put this in contrib/schemagen/CMakeLists.txt?
andrew marked this conversation as resolved
weaselbot added 1 commit 2026-06-18 19:27:00 +00:00
schemagen: move test configuration into contrib/schemagen/CMakeLists.txt
CI / pre-commit (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Successful in 1m28s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Successful in 49s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Successful in 1m22s
859fa41ecb
Addresses review feedback: keep the schemagen-specific CMake rules
close to the tool instead of inline in the top-level CMakeLists.txt.
The subdirectory file is added from the root and guarded by the same
Python3 availability check that was already in use.
andrew merged commit 644d244990 into main 2026-06-18 20:01:09 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#11