Skip to content

Commit

Permalink
Merge pull request #4 from bombsimon/master
Browse files Browse the repository at this point in the history
Ensure serial is not 000
  • Loading branch information
bombsimon authored Jun 16, 2020
2 parents 4df1ac7 + 35aad18 commit 11c3b04
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ impl Personnummer {
self.date.month(),
self.date.day()
);

let to_control = format!("{:06}{:03}", ymd, self.serial);

luhn(to_control) == self.control
self.serial > 0 && luhn(to_control) == self.control
}

/// Return the age of the person holding the personal identity number. The dates used for the
Expand Down Expand Up @@ -211,7 +212,12 @@ mod tests {

#[test]
fn test_valid_date_invalid_digits() {
let cases = vec!["19900101-1111", "20160229-1111", "6403273814"];
let cases = vec![
"19900101-1111",
"20160229-1111",
"6403273814",
"20150916-0006",
];

for tc in cases {
assert!(!Personnummer::new(tc).valid());
Expand Down

0 comments on commit 11c3b04

Please # to comment.