Skip to content

Commit

Permalink
fix(common): fix parsing of TrackIdentifier (#48)
Browse files Browse the repository at this point in the history
also add a test
  • Loading branch information
snylonue authored Aug 4, 2024
1 parent 1faeb2c commit 431496d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions anni-common/src/models.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::{Borrow, Cow};
use std::fmt::Display;
use std::num::NonZeroU8;
use std::str::{FromStr, Split};
use std::str::FromStr;

use thiserror::Error;

Expand Down Expand Up @@ -67,7 +67,7 @@ impl FromStr for TrackIdentifier {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut split = s.splitn(2, '/');
let mut split = s.splitn(3, '/');

let album_id = split.next().ok_or(ParseError::InvalidFormat)?;
let disc_id = split
Expand Down
17 changes: 17 additions & 0 deletions anni-common/tests/identifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::num::NonZeroU8;

use anni_common::models::{ParseError, TrackIdentifier};

#[test]
fn parse() -> Result<(), ParseError> {
let identifier = "65cf12dc-9717-4503-9901-848e8cd3ebff/1/8".parse::<TrackIdentifier>()?;

assert_eq!(
identifier.inner.album_id,
"65cf12dc-9717-4503-9901-848e8cd3ebff"
);
assert_eq!(identifier.inner.disc_id, NonZeroU8::new(1).unwrap());
assert_eq!(identifier.inner.track_id, NonZeroU8::new(8).unwrap());

Ok(())
}

0 comments on commit 431496d

Please sign in to comment.