From 0c45dcfbc1ce5ea1486f1104b3719f64544a7155 Mon Sep 17 00:00:00 2001 From: Jean-Marc MEESSEN Date: Sun, 21 Jun 2020 10:38:14 +0200 Subject: [PATCH] Adding line parsing tests --- cmd/parse_line.go | 2 +- cmd/parse_line_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/cmd/parse_line.go b/cmd/parse_line.go index ee974b1..3eafd32 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -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" diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index b56fc66..515094c 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -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 +// 2m fm +// 1227 gw4gte +// 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 ", + 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) + } + }) + } +} \ No newline at end of file