package qso import "testing" // The predicate behind "Worked before". Exact when folding is off; with it on, // a station's portable forms are one operator — and the fold has to work from // either end, because you may type the base call or the portable one. func TestCallMatch(t *testing.T) { if pred, args := callMatch("RK3DWA", false); pred != "callsign = ?" || len(args) != 1 || args[0] != "RK3DWA" { t.Errorf("exact: got %q %v", pred, args) } // Typing the base call: match it and everything suffixed off it. pred, args := callMatch("RK3DWA", true) if pred != "(callsign = ? OR callsign LIKE ?)" { t.Errorf("variants predicate = %q", pred) } if len(args) != 2 || args[0] != "RK3DWA" || args[1] != "RK3DWA/%" { t.Errorf("variants args = %v, want [RK3DWA RK3DWA/%%]", args) } // Typing a portable form must reach the plain call too — the suffix is // stripped from the INPUT, not just matched in the column. _, args = callMatch("RK3DWA/3", true) if len(args) != 2 || args[0] != "RK3DWA" || args[1] != "RK3DWA/%" { t.Errorf("portable input args = %v, want [RK3DWA RK3DWA/%%]", args) } // A leading slash is not a suffix marker — dropping to "" there would match // the entire logbook. if _, args := callMatch("/RK3DWA", true); args[0] != "/RK3DWA" { t.Errorf("leading slash: args[0] = %v, want the call unchanged", args[0]) } }