ADIF defines CNTY as "STATE,COUNTY" — "GA,BARROW". OpsLog wrote the bare county name, which a receiving logger cannot resolve: county names repeat across states, and there is a Washington County in thirty of them. The award engine here was never affected, since it reads the columns rather than the ADIF; the damage was to every file we hand to someone else. One writer covers everything — writeRecord — so this fixes file exports and the LoTW, Club Log, HRDLog and QRZ uploads together. MY_CNTY gets the same treatment. The county alone is still written when no state is known: a bare name is worth more than nothing, and inventing a prefix would be worse than either. A value that already carries a comma passes through untouched, so re-exporting an imported record cannot double the prefix. Import is the mirror: "GA,BARROW" fills both columns, and a file carrying the bare county — as OpsLog's own older exports do — still imports unchanged. The state parsed out of CNTY only fills a blank STATE, never overrides it: STATE is the dedicated field and the more specific statement.
47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
package adif
|
|
|
|
import "testing"
|
|
|
|
// ADIF defines CNTY as "STATE,COUNTY" — "GA,BARROW". OpsLog exported the bare
|
|
// county, which a receiving logger cannot resolve: county names repeat across
|
|
// states, and there is a Washington County in thirty of them.
|
|
func TestADIFCountyFormat(t *testing.T) {
|
|
for _, tc := range []struct{ state, county, want string }{
|
|
{"GA", "BARROW", "GA,BARROW"},
|
|
{"ga", "Barrow", "GA,Barrow"}, // the state is a code, upper-cased; the name is not touched
|
|
{"", "BARROW", "BARROW"}, // no state known: a bare name beats nothing
|
|
{"GA", "", ""}, // no county: nothing to write
|
|
{"GA", "GA,BARROW", "GA,BARROW"}, // already formatted — never double the prefix
|
|
{" GA ", " BARROW ", "GA,BARROW"},
|
|
} {
|
|
if got := adifCounty(tc.state, tc.county); got != tc.want {
|
|
t.Errorf("adifCounty(%q, %q) = %q, want %q", tc.state, tc.county, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// And the mirror: a file from a logger that follows the standard must fill both
|
|
// columns, while a file carrying the bare county still imports unchanged.
|
|
func TestSplitADIFCounty(t *testing.T) {
|
|
for _, tc := range []struct{ in, county, state string }{
|
|
{"GA,BARROW", "BARROW", "GA"},
|
|
{"ga, Barrow", "Barrow", "GA"},
|
|
{"BARROW", "BARROW", ""}, // the old OpsLog form, and many other loggers
|
|
{"", "", ""},
|
|
{" ", "", ""},
|
|
} {
|
|
c, s := splitADIFCounty(tc.in)
|
|
if c != tc.county || s != tc.state {
|
|
t.Errorf("splitADIFCounty(%q) = (%q, %q), want (%q, %q)", tc.in, c, s, tc.county, tc.state)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Round trip: what OpsLog writes, OpsLog reads back to the same two values.
|
|
func TestCountyRoundTrip(t *testing.T) {
|
|
c, s := splitADIFCounty(adifCounty("GA", "BARROW"))
|
|
if c != "BARROW" || s != "GA" {
|
|
t.Errorf("round trip gave (%q, %q), want (BARROW, GA)", c, s)
|
|
}
|
|
}
|