Adding line parsing tests

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 571371faf5
commit 0c45dcfbc1

@ -231,7 +231,7 @@ func SprintLogRecord(logLine LogLine) (output string){
output = output + "ModeType " + logLine.ModeType + "\n"
output = output + "Band " + logLine.Band + "\n"
output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandUpperLimit) + "\n"
output = output + "Frequency " + logLine.Frequency + "\n"
output = output + "Time " + logLine.Time + "\n"
output = output + "Call " + logLine.Call + "\n"

@ -110,3 +110,45 @@ func TestParseLine(t *testing.T) {
})
}
}
func TestHappyParseLine(t *testing.T) {
type args struct {
inputStr string
previousLine LogLine
}
tests := []struct {
name string
args args
wantLogLine LogLine
wantErrorMsg string
}{
// 4 g3noh <PSE QSL Direct>
// 2m fm
// 1227 gw4gte <Dave>
// 8 gw0tlk/m gwff-0021
{
"test1",
args{ inputStr: "1202 g4elz",
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"}, "",
},
{
"test2",
args{ inputStr: "4 g3noh <PSE QSL Direct>",
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"}, "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotLogLine, gotErrorMsg := ParseLine(tt.args.inputStr, tt.args.previousLine)
if !reflect.DeepEqual(gotLogLine, tt.wantLogLine) {
t.Errorf("ParseLine() gotLogLine = %v, want %v", gotLogLine, tt.wantLogLine)
}
if gotErrorMsg != tt.wantErrorMsg {
t.Errorf("ParseLine() gotErrorMsg = %v, want %v", gotErrorMsg, tt.wantErrorMsg)
}
})
}
}
Loading…
Cancel
Save