pub mod general;
pub mod editor;
pub mod difficulty;
pub mod metadata;
pub mod events;
pub mod timing_points;
pub mod colors;
pub mod hit_objects;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Section {
General,
Editor,
Metadata,
Difficulty,
Events,
TimingPoints,
Colors,
HitObjects,
Variables,
CatchTheBeat,
Mania,
}
impl Section {
pub fn try_from_line(line: &str) -> Option<Self> {
let section = line.strip_prefix('[')?.strip_suffix(']')?;
let section = match section {
"General" => Self::General,
"Editor" => Self::Editor,
"Metadata" => Self::Metadata,
"Difficulty" => Self::Difficulty,
"Events" => Self::Events,
"TimingPoints" => Self::TimingPoints,
"Colours" => Self::Colors,
"HitObjects" => Self::HitObjects,
"Variables" => Self::Variables,
"CatchTheBeat" => Self::CatchTheBeat,
"Mania" => Self::Mania,
_ => return None,
};
Some(section)
}
}
thiserror! {
#[error("unknown key")]
#[derive(Debug)]
pub struct UnknownKeyError;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn finds_valid_sections() {
assert_eq!(Section::try_from_line("[General]"), Some(Section::General));
assert_eq!(
Section::try_from_line("[Difficulty]"),
Some(Section::Difficulty)
);
assert_eq!(
Section::try_from_line("[HitObjects]"),
Some(Section::HitObjects)
);
}
#[test]
fn requires_brackets() {
assert_eq!(Section::try_from_line("General"), None);
assert_eq!(Section::try_from_line("[General"), None);
assert_eq!(Section::try_from_line("General]"), None);
}
#[test]
fn denies_invalid_sections() {
assert_eq!(Section::try_from_line("abc"), None);
assert_eq!(Section::try_from_line("HitObject"), None);
}
}