Skip to content

Commit

Permalink
Merge pull request #1 from scrive/IC-73-finnish-pn-extra-separators
Browse files Browse the repository at this point in the history
[IC-73] Update Finish personal number validator
  • Loading branch information
kutyel authored Feb 25, 2025
2 parents cc05592 + 54d0849 commit 1e5ee6f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/PersonalNumber/Finnish.elm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ checksumChars =
"0123456789ABCDEFHJKLMNPRSTUVWXY"


{-| Separators used in personal identity codes:
- for those born in or after 2000, letters A, B, C, D, E, F.
- for those born in the 1900s, the current hyphen (-) or the letters Y, X, W, V, U.
- for those born in the 19th century, a plus sign (+).
-}
separatorChars : String
separatorChars =
"-+ABCDEFYXWVU"


personalNumberParser : Parser PersonalNumber
personalNumberParser =
(getChompedString <|
Expand All @@ -75,7 +87,7 @@ personalNumberParser =
|. digit
|. digit
|. digit
|. chompIf (\c -> c == '-' || c == '+' || c == 'A')
|. chompIf (String.fromChar >> flip String.contains separatorChars)
|. digit
|. digit
|. digit
Expand Down
15 changes: 15 additions & 0 deletions tests/FinnishTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ suite =
PersonalNumber.fromString "010200A9618"
|> Result.map PersonalNumber.display
|> Expect.equal (Ok "010200A9618")
, test "should accept a PNR with a different century marker for those born in or after 2000" <|
\_ ->
PersonalNumber.fromString "010200F9618"
|> Result.map PersonalNumber.display
|> Expect.equal (Ok "010200F9618")
, test "should accept a PNR with a different century marker for those born in the 1900s" <|
\_ ->
PersonalNumber.fromString "010200X9618"
|> Result.map PersonalNumber.display
|> Expect.equal (Ok "010200X9618")
, test "should accept a PNR with a different century marker for those born in the 19th century" <|
\_ ->
PersonalNumber.fromString "010200+9618"
|> Result.map PersonalNumber.display
|> Expect.equal (Ok "010200+9618")
, test "should not accept a PNR with an invalid checksum" <|
\_ -> Expect.err (PersonalNumber.fromString "131052308X")
, test "should not accept an empty value" <|
Expand Down

0 comments on commit 1e5ee6f

Please sign in to comment.