Skip to content

Commit

Permalink
Add test for Hawaii license
Browse files Browse the repository at this point in the history
  • Loading branch information
c0shea committed Mar 11, 2018
1 parent 7498a78 commit d5c2f48
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
51 changes: 51 additions & 0 deletions IdParser.Test/DriversLicenseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2320,5 +2320,56 @@ public void TestILLicense()
Assert.AreEqual("60611", idCard.Address.PostalCodeDisplay);
Assert.AreEqual("Illinois", idCard.IssuerIdentificationNumber.GetDescription());
}

[TestMethod]
public void TestHILicense()
{
var expected = new DriversLicense
{
Name = new Name
{
First = "MICHAEL",
Middle = "JAY",
Last = "MOTORIST"
},

Address = new Address
{
StreetLine1 = "456 MOANA ST 2",
StreetLine2 = "O",
City = "HONOLULU",
JurisdictionCode = "HI",
PostalCode = "96826",
Country = Country.Usa
},

DateOfBirth = new DateTime(1988, 03, 12),
Sex = Sex.Male,
EyeColor = EyeColor.Blue,
HairColor = HairColor.Blond,
Height = Height.FromImperial(72),

IdNumber = "H01387330",
AamvaVersionNumber = Version.Aamva2009,

IssueDate = new DateTime(2016, 05, 13),
ExpirationDate = new DateTime(2024, 03, 12),

Jurisdiction = new DriversLicenseJurisdiction
{
VehicleClass = "3",
RestrictionCodes = "B"
}
};

var file = File.ReadAllText("HI License.txt");
var idCard = Barcode.Parse(file, Validation.None);

AssertIdCard(expected, idCard);
AssertLicense(expected, idCard);

Assert.AreEqual("96826", idCard.Address.PostalCodeDisplay);
Assert.AreEqual("Hawaii", idCard.IssuerIdentificationNumber.GetDescription());
}
}
}
30 changes: 30 additions & 0 deletions IdParser.Test/HI License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@

ANSI 636047040002DL00410258ZH02990021DLDCA3
DCBB
DCDNONE
DBA03122024
DCSMOTORIST
DACMICHAEL
DADJAY
DBD05132016
DBB03121988
DBC1
DAYBLU
DAU72 IN
DAG456 MOANA ST 2
DAIHONOLULU
DAJHI
DAK96826 0
DAQH01387330
DCF2016051411385491547K1O
DCGUSA
DDEU
DDFU
DDGU
DAHO
DAZBLN
DCJ20160518-053221-9-2048
ZHZHAO
ZHB
ZHCHIDL-C
3 changes: 3 additions & 0 deletions IdParser.Test/IdParser.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<Content Include="DE License.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="HI License.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="IA License.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
13 changes: 11 additions & 2 deletions IdParser/Parsers/Id/PostalCodeParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System;
using System.Text.RegularExpressions;
using IdParser.Attributes;

namespace IdParser.Parsers.Id
Expand All @@ -14,11 +15,19 @@ public PostalCodeParser(IdParser.IdentificationCard idCard, Version version, Cou

public override void ParseAndSet(string input)
{
if (input == null)
if (StringHasNoValue(input))
{
return;
}

// Some jurisdictions, like Hawaii, have spaces after the ZIP code followed by a number like 0.
// Chop off the excess junk otherwise we'd wind up with a 6-digit ZIP code.
var indexOfSpaces = input.IndexOf(" ", StringComparison.OrdinalIgnoreCase);
if (indexOfSpaces >= 0)
{
input = input.Substring(0, indexOfSpaces);
}

IdCard.Address.PostalCode = new Regex(NonAlphaNumericPattern).Replace(input, "")
.Replace("0000", "");
}
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ will be parsed correctly. The app works with both OPOS and HID keyboard emulatio
recommended level for scanners using OPOS. However, if HID keyboard emulation is used, especially when
scanning using a web browser, the expected data can become malformed. You can try using the `None`
validation level, however this is not guaranteed to work in all cases. Data elements may be skipped
and exceptions may still be thrown.
and exceptions may still be thrown.

## Find IDs Not in Tests Regex

```regex
DAJ(?!(AL|AR|AZ|CA|CO|CT|DE|FL|GA|IA|IL|IN|KS|KY|LA|MA|MD|ME|MI|MO|MT|NC|NH|NJ|NM|NY|OH|ON|OR|PA|PR|RI|SC|TN|TX|UT|VA|VT|WA|WI|QC|OK))[A-Z]+
```

0 comments on commit d5c2f48

Please sign in to comment.