package lookup

import "testing"

// What goes in a log's Name field is the FIRST name. A log greets an operator;
// it does not address an envelope. "Robert Smith" filled the field with
// something no one would ever send on the air.
//
// The nickname wins ahead of it when asked for — but a published nickname is
// optional, so an empty one must fall through rather than blank the name. That
// is the whole difference between a fallback and a swap.
func TestQRZName(t *testing.T) {
	for _, tc := range []struct {
		name                  string
		prefer                bool
		nickname, fname, last string
		want                  string
	}{
		{"first name only, never the surname", false, "Bob", "Robert", "Smith", "Robert"},
		{"nickname when asked for", true, "Bob", "Robert", "Smith", "Bob"},
		{"no nickname published falls back to the FIRST name", true, "", "Robert", "Smith", "Robert"},
		{"a blank nickname is not a nickname", true, "   ", "Robert", "Smith", "Robert"},
		{"option off ignores the nickname", false, "Bob", "Robert", "Smith", "Robert"},
		{"surname is the last resort, not the default", true, "", "", "Smith", "Smith"},
		{"nothing published at all", false, "", "", "", ""},
		{"nickname alone", true, "Bob", "", "", "Bob"},
	} {
		if got := qrzName(tc.prefer, tc.nickname, tc.fname, tc.last); got != tc.want {
			t.Errorf("%s: qrzName(%v, %q, %q, %q) = %q, want %q",
				tc.name, tc.prefer, tc.nickname, tc.fname, tc.last, got, tc.want)
		}
	}
}
