github.com/blend/go-sdk@v1.20220411.3/names/parser_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package names 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 func TestNames(t *testing.T) { 17 assert := assert.New(t) 18 19 names := map[string]Name{} 20 names["John Doe"] = Name{"", "John", "", "Doe", ""} 21 names["Mr Anthony R Von Fange III"] = Name{"Mr.", "Anthony", "R", "Von Fange", "III"} 22 names["Sara Ann Fraser"] = Name{"", "Sara Ann", "", "Fraser", ""} 23 names["Adam"] = Name{"", "Adam", "", "", ""} 24 names["Jonathan Smith"] = Name{"", "Jonathan", "", "Smith", ""} 25 names["Anthony R Von Fange III"] = Name{"", "Anthony", "R", "Von Fange", "III"} 26 names["Anthony Von Fange III"] = Name{"", "Anthony", "", "Von Fange", "III"} 27 names["Mr John Doe"] = Name{"Mr.", "John", "", "Doe", ""} 28 names["Justin White Phd"] = Name{"", "Justin", "", "White", "PhD"} 29 names["Mark P Williams"] = Name{"", "Mark", "P", "Williams", ""} 30 // Preserves the case of compound last name words 31 names["Aaron bin Omar"] = Name{"", "Aaron", "", "bin Omar", ""} 32 names["AARON BIN OMAR"] = Name{"", "Aaron", "", "Bin Omar", ""} 33 names["Aaron ibn Omar"] = Name{"", "Aaron", "", "ibn Omar", ""} 34 // Title case all caps 35 names["MICHAEL J SPOLARICH JR"] = Name{"", "Michael", "J", "Spolarich", "Jr"} 36 // Title case lowers 37 names["michael j spolarich jr"] = Name{"", "Michael", "J", "Spolarich", "Jr"} 38 // Preserve camel if provided 39 names["LaTosha McMichaels"] = Name{"", "LaTosha", "", "McMichaels", ""} 40 // Can't camel if we get consistent case 41 names["LATOSHA MCMICHAELS"] = Name{"", "Latosha", "", "Mcmichaels", ""} 42 names[""] = Name{"", "", "", "", ""} 43 names["Dr"] = Name{"Dr.", "", "", "", ""} 44 45 for rawName, expectedResult := range names { 46 result := Parse(rawName) 47 assert.Equal(expectedResult, result) 48 } 49 }