Skip to content

Commit b0f91c7

Browse files
committed
Add more tests for invalid crate name
Signed-off-by: hi-rustin <[email protected]>
1 parent ab56423 commit b0f91c7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/models/krate.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ mod tests {
609609

610610
#[test]
611611
fn validate_crate_name() {
612-
use super::InvalidCrateName;
612+
use super::{InvalidCrateName, MAX_NAME_LENGTH};
613613

614614
assert_ok!(Crate::validate_crate_name("foo"));
615615
assert_err_eq!(
@@ -627,6 +627,7 @@ mod tests {
627627
Crate::validate_crate_name("foo+plus"),
628628
InvalidCrateName::Char('+', "foo+plus".into())
629629
);
630+
// Crate names cannot start with an underscore on crates.io.
630631
assert_err_eq!(
631632
Crate::validate_crate_name("_foo"),
632633
InvalidCrateName::Start('_', "_foo".into())
@@ -635,6 +636,14 @@ mod tests {
635636
Crate::validate_crate_name("-foo"),
636637
InvalidCrateName::Start('-', "-foo".into())
637638
);
639+
assert_err_eq!(
640+
Crate::validate_crate_name("123"),
641+
InvalidCrateName::StartWithDigit("123".into())
642+
);
643+
assert_err_eq!(
644+
Crate::validate_crate_name("o".repeat(MAX_NAME_LENGTH + 1).as_str()),
645+
InvalidCrateName::TooLong("o".repeat(MAX_NAME_LENGTH + 1).as_str().into())
646+
);
638647
}
639648

640649
#[test]

0 commit comments

Comments
 (0)