Skip to content

Commit 993348b

Browse files
authored
Handle test/mod names that start with a digit (#325)
1 parent e3806a0 commit 993348b

File tree

1 file changed

+16
-3
lines changed
  • partiql-conformance-test-generator/src

1 file changed

+16
-3
lines changed

partiql-conformance-test-generator/src/util.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@ pub trait Escaper {
1111
fn escape_module_name(&self) -> String;
1212
}
1313

14+
fn escape_str(s: &str) -> String {
15+
match s.chars().next() {
16+
None => "_".to_string(),
17+
Some(c) => {
18+
if c.is_numeric() {
19+
format!("_{}", s.to_snake_case())
20+
} else {
21+
s.to_snake_case()
22+
}
23+
}
24+
}
25+
}
26+
1427
impl Escaper for &str {
1528
fn escape_path(&self) -> String {
16-
self.to_snake_case()
29+
escape_str(self)
1730
}
1831

1932
fn escape_test_name(&self) -> String {
20-
format!("r#{}", self.to_snake_case())
33+
format!("r#{}", escape_str(self))
2134
}
2235
fn escape_module_name(&self) -> String {
23-
format!("r#{}", self.to_snake_case())
36+
format!("r#{}", escape_str(self))
2437
}
2538
}
2639

0 commit comments

Comments
 (0)