mirror of
https://github.com/on4kjm/FLEcli.git
synced 2025-01-31 14:51:04 +01:00
some additional tests to callsign validation
This commit is contained in:
parent
bb70d9b98d
commit
42274b1429
2 changed files with 53 additions and 27 deletions
|
@ -42,20 +42,28 @@ func ValidateCall(sign string) (call, errorMsg string) {
|
|||
if validCallRegexp.MatchString(sp[0]) {
|
||||
//Callisign with suffix (unchecked)
|
||||
return sign, ""
|
||||
} else {
|
||||
//Callsign with prefix
|
||||
//validate the part that should contain the call (sp[1])
|
||||
if !validCallRegexp.MatchString(sp[1]) {
|
||||
return wrongSign, "Invalid call"
|
||||
}
|
||||
//validate the prefix
|
||||
if !validPrefixRegexp.MatchString(sp[0]) {
|
||||
return wrongSign, "Invalid prefix"
|
||||
}
|
||||
return sign, ""
|
||||
}
|
||||
//else we are dealing with a prefixed Callsign
|
||||
//validate the part that should contain the call (sp[1])
|
||||
if !validCallRegexp.MatchString(sp[1]) {
|
||||
return wrongSign, "Invalid call"
|
||||
}
|
||||
//validate the prefix
|
||||
if !validPrefixRegexp.MatchString(sp[0]) {
|
||||
return wrongSign, "Invalid prefix"
|
||||
}
|
||||
return sign, ""
|
||||
case 3:
|
||||
return sign, "??????"
|
||||
//validate the part that should contain the call (sp[1])
|
||||
if !validCallRegexp.MatchString(sp[1]) {
|
||||
return wrongSign, "Invalid call"
|
||||
}
|
||||
//validate the prefix
|
||||
if !validPrefixRegexp.MatchString(sp[0]) {
|
||||
return wrongSign, "Invalid prefix"
|
||||
}
|
||||
//We don't check the suffix
|
||||
return sign, ""
|
||||
}
|
||||
return sign, "?????"
|
||||
return wrongSign, "Too many '/'"
|
||||
}
|
|
@ -15,45 +15,63 @@ func TestValidateCall(t *testing.T) {
|
|||
{
|
||||
"Good call (simple)",
|
||||
args{ sign: "on4kjm", },
|
||||
"ON4KJM",
|
||||
"",
|
||||
"ON4KJM", "",
|
||||
},
|
||||
{
|
||||
"Good call (suffix)",
|
||||
args{ sign: "on4kjm/p", },
|
||||
"ON4KJM/P",
|
||||
"",
|
||||
"ON4KJM/P", "",
|
||||
},
|
||||
{
|
||||
"Good call (prefix only)",
|
||||
args{ sign: "DL/on4KJm", },
|
||||
"DL/ON4KJM",
|
||||
"",
|
||||
"DL/ON4KJM", "",
|
||||
},
|
||||
{
|
||||
"Good call (prefix and suffix)",
|
||||
args{ sign: "DL/on4KJm/p", },
|
||||
"DL/ON4KJM/P",
|
||||
"",
|
||||
"DL/ON4KJM/P", "",
|
||||
},
|
||||
{
|
||||
"Good call (Numerical prefix)",
|
||||
args{ sign: "4x/on4KJm/p", },
|
||||
"4X/ON4KJM/P", "",
|
||||
},
|
||||
{
|
||||
"Good call (prefix and long suffix)",
|
||||
args{ sign: "DL/on4KJm/qrpp ", },
|
||||
"DL/ON4KJM/QRPP", "",
|
||||
},
|
||||
//Error cases
|
||||
{
|
||||
"Pure junk passed",
|
||||
args{ sign: "aaaaaa", },
|
||||
"*AAAAAA",
|
||||
"Invalid call",
|
||||
"*AAAAAA", "Invalid call",
|
||||
},
|
||||
{
|
||||
"empty string",
|
||||
args{ sign: "", },
|
||||
"*",
|
||||
"Invalid call",
|
||||
"*", "Invalid call",
|
||||
},
|
||||
{
|
||||
"string with spaces",
|
||||
args{ sign: " ", },
|
||||
"*",
|
||||
"Invalid call",
|
||||
"*", "Invalid call",
|
||||
},
|
||||
{
|
||||
"invalid prefix",
|
||||
args{ sign: "xyz/on4kjm", },
|
||||
"*XYZ/ON4KJM", "Invalid prefix",
|
||||
},
|
||||
{
|
||||
"Too many /",
|
||||
args{ sign: "F/on4kjm/p/x", },
|
||||
"*F/ON4KJM/P/X", "Too many '/'",
|
||||
},
|
||||
{
|
||||
"signe /",
|
||||
args{ sign: "/", },
|
||||
"*/", "Invalid call",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in a new issue