diff --git a/src/lib.rs b/src/lib.rs index 0280a32..b748179 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1242,4 +1242,32 @@ Martin}}"#; Err(TypeError::new(74..74, TypeErrorKind::MissingNumber).into()) ); } + + #[test] + #[allow(clippy::single_range_in_vec_init)] + fn test_page_ranges() { + let raw = r#"@article{test, + pages = {1---2}, + } + @article{test1, + pages = {2--3}, + } + @article{test2, + pages = {1}, + }"#; + + let bibliography = Bibliography::parse(raw).unwrap(); + assert_eq!( + bibliography.get("test").unwrap().pages(), + Ok(PermissiveType::Typed(vec![1..2])) + ); + assert_eq!( + bibliography.get("test1").unwrap().pages(), + Ok(PermissiveType::Typed(vec![2..3])) + ); + assert_eq!( + bibliography.get("test2").unwrap().pages(), + Ok(PermissiveType::Typed(vec![1..1])) + ); + } } diff --git a/src/types/mod.rs b/src/types/mod.rs index d728663..88383f3 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -232,7 +232,10 @@ impl Type for Vec> { let mut s = Scanner::new(&range_candidate); let start = component(&mut s, span.start)?; s.eat_whitespace(); - if !s.eat_if('-') { + + // The double and triple hyphen is converted into en dashes and em + // dashes earlier. + if !s.eat_if(['-', '–', '—']) { res.push(start..start); continue; }