Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ensure serial is not 000 #4

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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