Skip to content

Commit 7c92525

Browse files
committed
Adds support for special case : with test
Signed-off-by: Aminu Oluwaseun Joshua <[email protected]>
1 parent d31c6bd commit 7c92525

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

crates/manifest/src/schema/v2.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,21 @@ mod tests {
796796
}
797797
}
798798

799+
#[test]
800+
fn test_valid_kebab_ids() {
801+
for valid in [
802+
"default",
803+
"mixed-case-words",
804+
"letters1-then2-numbers345",
805+
"gpt-oss:20b",
806+
"gpt-4",
807+
] {
808+
if let Err(err) = KebabId::try_from(valid.to_string()) {
809+
panic!("{valid:?} should be value: {err:?}");
810+
}
811+
}
812+
}
813+
799814
#[test]
800815
fn test_invalid_snake_ids() {
801816
for invalid in [

crates/manifest/tests/ui/invalid/bad_kebab_component_ref.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ TOML parse error at line 7, column 13
22
|
33
7 | component = "1-2-3"
44
| ^^^^^^^
5-
'-'-separated words must start with an ASCII letter; got '1'
5+
'-'-separated words must start with an ASCII letter or digit; got '1'
66

crates/manifest/tests/ui/invalid/bad_variable_name.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ TOML parse error at line 7, column 1
22
|
33
7 | "bad+name" = { required = true }
44
| ^^^^^^^^^^
5-
'_'-separated words may only contain alphanumeric ASCII; got '+'
5+
'_'-separated words may only contain alphanumeric ASCII (plus ':' inside words); got '+'

crates/serde/src/id.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ impl<const DELIM: char, const LOWER: bool> TryFrom<String> for Id<DELIM, LOWER>
4444
));
4545
}
4646
}
47-
for word in id.split(DELIM) {
47+
for (i, word) in id.split(DELIM).enumerate() {
4848
if word.is_empty() {
4949
return Err(format!("{DELIM:?}-separated words must not be empty"));
5050
}
5151
let mut chars = word.chars();
5252
let first = chars.next().unwrap();
53-
if !first.is_ascii_alphabetic() {
53+
if !(first.is_ascii_alphabetic() || (i > 0 && first.is_ascii_digit())) {
5454
return Err(format!(
55-
"{DELIM:?}-separated words must start with an ASCII letter; got {first:?}"
55+
"{DELIM:?}-separated words must start with an ASCII letter or digit; got {first:?}"
5656
));
5757
}
5858
let word_is_uppercase = first.is_ascii_uppercase();
5959
for ch in chars {
60-
if ch.is_ascii_digit() {
60+
if ch.is_ascii_digit() || ch == ':' {
6161
} else if !ch.is_ascii_alphanumeric() {
6262
return Err(format!(
63-
"{DELIM:?}-separated words may only contain alphanumeric ASCII; got {ch:?}"
63+
"{DELIM:?}-separated words may only contain alphanumeric ASCII (plus ':' inside words); got {ch:?}"
6464
));
6565
} else if ch.is_ascii_uppercase() != word_is_uppercase {
6666
return Err(format!("{DELIM:?}-separated words must be all lowercase or all UPPERCASE; got {word:?}"));

0 commit comments

Comments
 (0)