Skip to content

Commit

Permalink
Make middle name return nil when not present
Browse files Browse the repository at this point in the history
  • Loading branch information
danilobecke committed Jun 24, 2021
1 parent ee4f318 commit 8f01366
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/LicenseParser/FieldParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ public class FieldParser: FieldParsing {
- Returns: An optional value parsed out of the raw data
*/
public func parseMiddleName() -> String? {
return parseString(key: "middleName")
let middleName = parseString(key: "middleName")
return middleName?.caseInsensitiveCompare("NONE") == .orderedSame ? nil : middleName
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Tests/LicenseParserTests/DriverLicenseNameSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@ class DriverLicenseNameSpec: QuickSpec{
expect(result.suffix).to(equal(.second))
}
}

describe("when the middle name is not present") {
it("should return nil") {
let sut = Parser(data: "DADNONE")
let result = sut.parse()

expect(result.middleName).to(beNil())
}
}
}
}

0 comments on commit 8f01366

Please sign in to comment.