Skip to content

Commit 11c3b04

Browse files
authored
Merge pull request #4 from bombsimon/master
Ensure serial is not 000
2 parents 4df1ac7 + 35aad18 commit 11c3b04

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ impl Personnummer {
137137
self.date.month(),
138138
self.date.day()
139139
);
140+
140141
let to_control = format!("{:06}{:03}", ymd, self.serial);
141142

142-
luhn(to_control) == self.control
143+
self.serial > 0 && luhn(to_control) == self.control
143144
}
144145

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

212213
#[test]
213214
fn test_valid_date_invalid_digits() {
214-
let cases = vec!["19900101-1111", "20160229-1111", "6403273814"];
215+
let cases = vec![
216+
"19900101-1111",
217+
"20160229-1111",
218+
"6403273814",
219+
"20150916-0006",
220+
];
215221

216222
for tc in cases {
217223
assert!(!Personnummer::new(tc).valid());

0 commit comments

Comments
 (0)