@ -5,7 +5,6 @@ import (
"testing"
"testing"
)
)
func TestParseLine ( t * testing . T ) {
func TestParseLine ( t * testing . T ) {
type args struct {
type args struct {
inputStr string
inputStr string
@ -18,94 +17,94 @@ func TestParseLine(t *testing.T) {
wantErrorMsg string
wantErrorMsg string
} {
} {
{
{
"Parse band and mode only" ,
"Parse band and mode only" ,
args { inputStr : "40M cw" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "40M cw" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 , Mode : "CW" , ModeType : "CW" , RSTsent : "599" , RSTrcvd : "599" } , "" ,
LogLine { Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 , Mode : "CW" , ModeType : "CW" , RSTsent : "599" , RSTrcvd : "599" } , "" ,
} ,
} ,
{
{
"Parse for time" ,
"Parse for time" ,
args { inputStr : "1314 g3noh" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "1314 g3noh" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { Time : "1314" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "1314" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse partial time - 1" ,
"Parse partial time - 1" ,
args { inputStr : "4 g3noh" , previousLine : LogLine { Time : "" , Mode : "SSB" , }} ,
args { inputStr : "4 g3noh" , previousLine : LogLine { Time : "" , Mode : "SSB" }} ,
LogLine { Time : "4" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" , //TODO: should fail
LogLine { Time : "4" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" , //TODO: should fail
} ,
} ,
{
{
"Parse partial time - 2" ,
"Parse partial time - 2" ,
args { inputStr : "15 g3noh" , previousLine : LogLine { Time : "1200" , Mode : "SSB" , }} ,
args { inputStr : "15 g3noh" , previousLine : LogLine { Time : "1200" , Mode : "SSB" }} ,
LogLine { Time : "1215" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "1215" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse partial time - 3" ,
"Parse partial time - 3" ,
args { inputStr : "4 g3noh" , previousLine : LogLine { Time : "1200" , Mode : "SSB" , }} ,
args { inputStr : "4 g3noh" , previousLine : LogLine { Time : "1200" , Mode : "SSB" }} ,
LogLine { Time : "1204" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "1204" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse for comment" ,
"Parse for comment" ,
args { inputStr : "4 g3noh <PSE QSL Direct>" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "4 g3noh <PSE QSL Direct>" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { Time : "4" , Comment : "PSE QSL Direct" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "4" , Comment : "PSE QSL Direct" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse for QSL" ,
"Parse for QSL" ,
args { inputStr : "g3noh [Custom QSL message]" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "g3noh [Custom QSL message]" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { QSLmsg : "Custom QSL message" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { QSLmsg : "Custom QSL message" , Call : "G3NOH" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Wrong mode" ,
"Wrong mode" ,
args { inputStr : "cww" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "cww" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "Unable to parse cww " ,
LogLine { Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "Unable to parse cww " ,
} ,
} ,
{
{
"Parse OM name" ,
"Parse OM name" ,
args { inputStr : "@Jean" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "@Jean" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { OMname : "Jean" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { OMname : "Jean" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse Grid locator" ,
"Parse Grid locator" ,
args { inputStr : "#grid" , previousLine : LogLine { Mode : "SSB" , }} ,
args { inputStr : "#grid" , previousLine : LogLine { Mode : "SSB" }} ,
LogLine { GridLoc : "grid" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { GridLoc : "grid" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse frequency" ,
"Parse frequency" ,
args { inputStr : "14.153 on4kjm" , previousLine : LogLine { Mode : "SSB" , Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 } } ,
args { inputStr : "14.153 on4kjm" , previousLine : LogLine { Mode : "SSB" , Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 } } ,
LogLine { Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 , Frequency : "14.153" , Call : "ON4KJM" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 , Frequency : "14.153" , Call : "ON4KJM" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"Parse frequency out of limit" ,
"Parse frequency out of limit" ,
args { inputStr : "14.453 on4kjm" , previousLine : LogLine { Mode : "SSB" , Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 } } ,
args { inputStr : "14.453 on4kjm" , previousLine : LogLine { Mode : "SSB" , Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 } } ,
LogLine { Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 , Call : "ON4KJM" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , " Frequency 14.453 is invalid for 20m band" ,
LogLine { Band : "20m" , BandLowerLimit : 14.0 , BandUpperLimit : 14.35 , Call : "ON4KJM" , Mode : "SSB" , RSTsent : "59" , RSTrcvd : "59" } , " Frequency 14.453 is invalid for 20m band" ,
} ,
} ,
{
{
"parse partial RST (sent) - CW" ,
"parse partial RST (sent) - CW" ,
args { inputStr : "1230 on4kjm 5" , previousLine : LogLine { Mode : "CW" , ModeType : "CW" } } ,
args { inputStr : "1230 on4kjm 5" , previousLine : LogLine { Mode : "CW" , ModeType : "CW" } } ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "559" , RSTrcvd : "599" , Mode : "CW" , ModeType : "CW" } , "" ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "559" , RSTrcvd : "599" , Mode : "CW" , ModeType : "CW" } , "" ,
} ,
} ,
{
{
"parse partial RST (received) - CW" ,
"parse partial RST (received) - CW" ,
args { inputStr : "1230 on4kjm 5 44" , previousLine : LogLine { Mode : "CW" , ModeType : "CW" } } ,
args { inputStr : "1230 on4kjm 5 44" , previousLine : LogLine { Mode : "CW" , ModeType : "CW" } } ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "559" , RSTrcvd : "449" , Mode : "CW" , ModeType : "CW" } , "" ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "559" , RSTrcvd : "449" , Mode : "CW" , ModeType : "CW" } , "" ,
} ,
} ,
{
{
"parse full RST (received) - CW" ,
"parse full RST (received) - CW" ,
args { inputStr : "1230 on4kjm 5 448" , previousLine : LogLine { Mode : "CW" , ModeType : "CW" } } ,
args { inputStr : "1230 on4kjm 5 448" , previousLine : LogLine { Mode : "CW" , ModeType : "CW" } } ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "559" , RSTrcvd : "448" , Mode : "CW" , ModeType : "CW" } , "" ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "559" , RSTrcvd : "448" , Mode : "CW" , ModeType : "CW" } , "" ,
} ,
} ,
{
{
"parse partial report (sent) - FM" ,
"parse partial report (sent) - FM" ,
args { inputStr : "1230 on4kjm 5" , previousLine : LogLine { Mode : "FM" , ModeType : "PHONE" } } ,
args { inputStr : "1230 on4kjm 5" , previousLine : LogLine { Mode : "FM" , ModeType : "PHONE" } } ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "55" , RSTrcvd : "59" , Mode : "FM" , ModeType : "PHONE" } , "" ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "55" , RSTrcvd : "59" , Mode : "FM" , ModeType : "PHONE" } , "" ,
} ,
} ,
{
{
"parse partial report (received) - FM" ,
"parse partial report (received) - FM" ,
args { inputStr : "1230 on4kjm 5 44" , previousLine : LogLine { Mode : "FM" , ModeType : "PHONE" } } ,
args { inputStr : "1230 on4kjm 5 44" , previousLine : LogLine { Mode : "FM" , ModeType : "PHONE" } } ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "55" , RSTrcvd : "44" , Mode : "FM" , ModeType : "PHONE" } , "" ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "55" , RSTrcvd : "44" , Mode : "FM" , ModeType : "PHONE" } , "" ,
} ,
} ,
{
{
"Incompatible report" ,
"Incompatible report" ,
args { inputStr : "1230 on4kjm 5 599" , previousLine : LogLine { Mode : "FM" , ModeType : "PHONE" } } ,
args { inputStr : "1230 on4kjm 5 599" , previousLine : LogLine { Mode : "FM" , ModeType : "PHONE" } } ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "55" , RSTrcvd : "*599" , Mode : "FM" , ModeType : "PHONE" } , "Invalid report (599) for PHONE mode " ,
LogLine { Call : "ON4KJM" , Time : "1230" , RSTsent : "55" , RSTrcvd : "*599" , Mode : "FM" , ModeType : "PHONE" } , "Invalid report (599) for PHONE mode " ,
} ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
@ -133,34 +132,34 @@ func TestHappyParseLine(t *testing.T) {
wantErrorMsg string
wantErrorMsg string
} {
} {
{
{
"test1" ,
"test1" ,
args { inputStr : "1202 g4elz" ,
args { inputStr : "1202 g4elz" ,
previousLine : LogLine { Mode : "CW" , ModeType : "CW" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 } } ,
previousLine : LogLine { Mode : "CW" , ModeType : "CW" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 } } ,
LogLine { Time : "1202" , Call : "G4ELZ" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 , Mode : "CW" , ModeType : "CW" , RSTsent : "599" , RSTrcvd : "599" } , "" ,
LogLine { Time : "1202" , Call : "G4ELZ" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 , Mode : "CW" , ModeType : "CW" , RSTsent : "599" , RSTrcvd : "599" } , "" ,
} ,
} ,
{
{
"test2" ,
"test2" ,
args { inputStr : "4 g3noh <PSE QSL Direct>" ,
args { inputStr : "4 g3noh <PSE QSL Direct>" ,
previousLine : LogLine { Time : "1202" , Mode : "CW" , ModeType : "CW" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 } } ,
previousLine : LogLine { Time : "1202" , Mode : "CW" , ModeType : "CW" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 } } ,
LogLine { Time : "1204" , Call : "G3NOH" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 , Mode : "CW" , ModeType : "CW" , Comment : "PSE QSL Direct" , RSTsent : "599" , RSTrcvd : "599" } , "" ,
LogLine { Time : "1204" , Call : "G3NOH" , Band : "40m" , BandLowerLimit : 7 , BandUpperLimit : 7.3 , Mode : "CW" , ModeType : "CW" , Comment : "PSE QSL Direct" , RSTsent : "599" , RSTrcvd : "599" } , "" ,
} ,
} ,
{
{
"test3" ,
"test3" ,
args { inputStr : "1227 gw4gte <Dave>" ,
args { inputStr : "1227 gw4gte <Dave>" ,
previousLine : LogLine { Time : "1202" , Mode : "FM" , ModeType : "PHONE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 } } ,
previousLine : LogLine { Time : "1202" , Mode : "FM" , ModeType : "PHONE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 } } ,
LogLine { Time : "1227" , Call : "GW4GTE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 , Mode : "FM" , ModeType : "PHONE" , Comment : "Dave" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "1227" , Call : "GW4GTE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 , Mode : "FM" , ModeType : "PHONE" , Comment : "Dave" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"test4" ,
"test4" ,
args { inputStr : "8 gw0tlk/m gwff-0021" ,
args { inputStr : "8 gw0tlk/m gwff-0021" ,
previousLine : LogLine { Time : "1227" , Mode : "FM" , ModeType : "PHONE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 } } ,
previousLine : LogLine { Time : "1227" , Mode : "FM" , ModeType : "PHONE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 } } ,
LogLine { Time : "1228" , Call : "GW0TLK/M" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 , Mode : "FM" , ModeType : "PHONE" , WWFF : "GWFF-0021" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "1228" , Call : "GW0TLK/M" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 , Mode : "FM" , ModeType : "PHONE" , WWFF : "GWFF-0021" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
{
{
"test5" ,
"test5" ,
args { inputStr : "7 dl0dan/p dlff-0002 dl/al-044" ,
args { inputStr : "7 dl0dan/p dlff-0002 dl/al-044" ,
previousLine : LogLine { Time : "1220" , Mode : "FM" , ModeType : "PHONE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 } } ,
previousLine : LogLine { Time : "1220" , Mode : "FM" , ModeType : "PHONE" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 } } ,
LogLine { Time : "1227" , Call : "DL0DAN/P" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 , Mode : "FM" , ModeType : "PHONE" , WWFF : "DLFF-0002" , SOTA : "DL/AL-044" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
LogLine { Time : "1227" , Call : "DL0DAN/P" , Band : "2m" , BandLowerLimit : 144 , BandUpperLimit : 148 , Mode : "FM" , ModeType : "PHONE" , WWFF : "DLFF-0002" , SOTA : "DL/AL-044" , RSTsent : "59" , RSTrcvd : "59" } , "" ,
} ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
@ -174,4 +173,4 @@ func TestHappyParseLine(t *testing.T) {
}
}
} )
} )
}
}
}
}