feat: add id validators
This commit is contained in:
parent
92a358a079
commit
f7fbf40721
4 changed files with 190 additions and 24 deletions
|
|
@ -1,9 +1,8 @@
|
|||
use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use rstest::rstest;
|
||||
use rustypipe::validate;
|
||||
use time::macros::date;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
|
|
@ -2121,6 +2120,7 @@ async fn music_genres() {
|
|||
assert!(!pop.is_mood);
|
||||
|
||||
genres.iter().for_each(|g| {
|
||||
assert!(validate::genre_id(&g.id));
|
||||
assert_gte(g.color, 0xff000000, "color");
|
||||
});
|
||||
}
|
||||
|
|
@ -2270,32 +2270,17 @@ async fn assert_next_items<T: FromYtItem, Q: AsRef<RustyPipeQuery>>(
|
|||
}
|
||||
|
||||
fn assert_video_id(id: &str) {
|
||||
static VIDEO_ID_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[A-Za-z0-9_-]{11}$").unwrap());
|
||||
|
||||
assert!(VIDEO_ID_REGEX.is_match(id), "invalid video id: `{}`", id);
|
||||
assert!(validate::video_id(id), "invalid video id: `{}`", id)
|
||||
}
|
||||
|
||||
fn assert_channel_id(id: &str) {
|
||||
static CHANNEL_ID_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^UC[A-Za-z0-9_-]{22}$").unwrap());
|
||||
|
||||
assert!(
|
||||
CHANNEL_ID_REGEX.is_match(id),
|
||||
"invalid channel id: `{}`",
|
||||
id
|
||||
);
|
||||
assert!(validate::channel_id(id), "invalid channel id: `{}`", id);
|
||||
}
|
||||
|
||||
fn assert_album_id(id: &str) {
|
||||
static ALBUM_ID_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^MPREb_[A-Za-z0-9_-]{11}$").unwrap());
|
||||
|
||||
assert!(ALBUM_ID_REGEX.is_match(id), "invalid album id: `{}`", id);
|
||||
assert!(validate::album_id(id), "invalid album id: `{}`", id);
|
||||
}
|
||||
|
||||
fn assert_playlist_id(id: &str) {
|
||||
static PLAYLIST_ID_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^(?:PL|RD|OLAK)[A-Za-z0-9_-]{30,}$").unwrap());
|
||||
|
||||
assert!(PLAYLIST_ID_REGEX.is_match(id), "invalid album id: `{}`", id);
|
||||
assert!(validate::playlist_id(id), "invalid playlist id: `{}`", id);
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue