Skip to content

Commit f46b257

Browse files
committed
javacodegen: replace colons and other invalid chars in test identifiers
1 parent 41eb3a5 commit f46b257

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

schema_salad/java_codegen.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Java code generator for a given schema salad definition."""
22
import os
3+
import re
34
import shutil
45
import string
56
from io import StringIO
@@ -28,6 +29,8 @@
2829
# may even confuse things a bit so turning these off be default.
2930
USE_ONE_OR_LIST_OF_TYPES = False
3031

32+
BASIC_JAVA_IDENTIFIER_RE = re.compile(r"[^0-9a-zA-Z]+")
33+
3134

3235
def _ensure_directory_and_write(path: Path, contents: str) -> None:
3336
_safe_makedirs(path.parent)
@@ -857,6 +860,7 @@ def expand_resource_template_to(resource: str, path: Path) -> None:
857860
for example_name in os.listdir(self.examples):
858861
if example_name.startswith("valid"):
859862
basename = os.path.basename(example_name).rsplit(".", 1)[0]
863+
basename = re.sub(BASIC_JAVA_IDENTIFIER_RE, "_", basename)
860864
example_tests += """
861865
@org.junit.Test
862866
public void test{basename}ByString() throws Exception {{
@@ -882,7 +886,7 @@ def expand_resource_template_to(resource: str, path: Path) -> None:
882886
doc = (java.util.Map<String, Object>) YamlUtils.mapFromString(yaml);
883887
RootLoader.loadDocument(doc, url.toString());
884888
}}""".format(
885-
basename=basename.replace("-", "_").replace(".", "_"),
889+
basename=basename,
886890
example_name=example_name,
887891
)
888892

0 commit comments

Comments
 (0)