github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/identity_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "testing" 8 ) 9 10 func TestParseIdentity(t *testing.T) { 11 for _, idents := range sampleIdentities { 12 checkIdentity(t, idents.input, idents.expected) 13 } 14 } 15 16 func checkIdentity(t *testing.T, input string, expected Identity) { 17 identity, err := ParseIdentity(input) 18 if err != nil { 19 t.Errorf("error parsing identity: %s", err) 20 } else { 21 if *identity != expected { 22 t.Errorf("identity differs from expected\n%s\n%s", identity, expected) 23 } 24 } 25 } 26 27 var sampleIdentities = []struct { 28 input string 29 expected Identity 30 }{ 31 {`Barb Akew <barb@example.com>`, 32 Identity{"Barb Akew", "", "barb@example.com"}}, 33 {`Barb Akew (bbq) <barb@example.com>`, 34 Identity{"Barb Akew", "bbq", "barb@example.com"}}, 35 {`"Barb Akew" (bbq) <barb@example.com>`, 36 Identity{"Barb Akew", "bbq", "barb@example.com"}}, 37 {`Barb Akew (b"b"q) <barb@example.com>`, 38 Identity{"Barb Akew", `b"b"q`, "barb@example.com"}}, 39 {`"Barb Akew (bbq)" <barb@example.com>`, 40 Identity{"Barb Akew", "bbq", "barb@example.com"}}, 41 {`x/Barb <barb@example.com>`, 42 Identity{"x/Barb", "", "barb@example.com"}}, 43 {`Barb Akew (co<mme>nt)`, 44 Identity{"Barb Akew", "co<mme>nt", ""}}, 45 {`Barb Akew (the "new" key)`, 46 Identity{"Barb Akew", `the "new" key`, ""}}, 47 {`Barb`, 48 Identity{"Barb", "", ""}}, 49 }