feat(lookup): optional QRZ nickname as the logged name
QRZ publishes <nickname> — the name an operator goes BY on the air — and OpsLog was composing fname + name instead. "Bob" is what belongs in a log; "Robert J Smith" is what belongs on a licence. QRZ only, and deliberately so: HamQTH's <nick> already fills the Name field that way, so the same switch there would toggle a behaviour it has no way to turn off. A published nickname is optional, so an empty one falls through to the registered name. That is the whole point of it being a fallback rather than a swap, and it is what the test pins — a blank nickname must never blank the name.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package lookup
|
||||
|
||||
import "testing"
|
||||
|
||||
// The nickname is the name an operator goes BY on the air, and that is what
|
||||
// belongs in a log — "Bob", not "Robert J Smith". HamQTH's <nick> is already
|
||||
// used that way; this brings QRZ into line for operators who ask for it.
|
||||
//
|
||||
// The one thing it must never do is blank the name. A published nickname is
|
||||
// optional, so an empty one has to fall through to the registered name rather
|
||||
// than win by being "preferred".
|
||||
func TestQRZNamePrefersNicknameButFallsBack(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
prefer bool
|
||||
nickname, fname, name string
|
||||
want string
|
||||
}{
|
||||
{true, "Bob", "Robert", "Smith", "Bob"},
|
||||
{true, "", "Robert", "Smith", "Robert Smith"}, // no nickname published
|
||||
{true, " ", "Robert", "Smith", "Robert Smith"}, // blank is not a nickname
|
||||
{false, "Bob", "Robert", "Smith", "Robert Smith"}, // option off
|
||||
{true, "Bob", "", "", "Bob"},
|
||||
{false, "", "Robert", "", "Robert"},
|
||||
{true, "", "", "Smith", "Smith"},
|
||||
} {
|
||||
if got := qrzName(tc.prefer, tc.nickname, tc.fname, tc.name); got != tc.want {
|
||||
t.Errorf("qrzName(%v, %q, %q, %q) = %q, want %q",
|
||||
tc.prefer, tc.nickname, tc.fname, tc.name, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user