diff --git a/fleprocess/braketedData.go b/fleprocess/braketedData.go index 01c4d11..340e859 100644 --- a/fleprocess/braketedData.go +++ b/fleprocess/braketedData.go @@ -29,7 +29,7 @@ const ( QSL ) -func getBraketedData(inputLine string, braketType BraketType) (braketedData, cleanedLine string) { +func getBracketedData(inputLine string, braketType BraketType) (braketedData, cleanedLine string) { // Get substring between two strings. a := "" b := "" diff --git a/fleprocess/braketedData_test.go b/fleprocess/braketedData_test.go index a6d3afa..4841720 100644 --- a/fleprocess/braketedData_test.go +++ b/fleprocess/braketedData_test.go @@ -74,7 +74,7 @@ func Test_getBraketedData(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotBraketedData, gotCleanedLine := getBraketedData(tt.args.inputLine, tt.args.braketType) + gotBraketedData, gotCleanedLine := getBracketedData(tt.args.inputLine, tt.args.braketType) if gotBraketedData != tt.wantBraketedData { t.Errorf("getBraketedData() gotBraketedData = %v, want %v", gotBraketedData, tt.wantBraketedData) } diff --git a/fleprocess/load_file.go b/fleprocess/load_file.go index a0fd7f3..d174d1e 100644 --- a/fleprocess/load_file.go +++ b/fleprocess/load_file.go @@ -81,6 +81,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL headerMyCounty := "" headerQslMsg := "" headerNickname := "" + headerIsFirstLine := true //headerDate := "" lineCount := 0 @@ -213,11 +214,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL //My Sota if regexpHeaderMySota.MatchString(eachline) { - //Attempt to redefine value - if headerMySOTA != "" { - errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine MySOTA at line %d", lineCount)) - continue - } + oldHeaderMySOTA := headerMySOTA errorMsg := "" mySotaList := regexpHeaderMySota.Split(eachline, -1) if len(strings.TrimSpace(mySotaList[1])) > 0 { @@ -227,6 +224,11 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL errorLog = append(errorLog, fmt.Sprintf("Invalid \"My SOTA\" at line %d: %s (%s)", lineCount, mySotaList[1], errorMsg)) } } + if oldHeaderMySOTA != headerMySOTA { + // New SOTA reference defined + headerIsFirstLine = true + + } //If there is no data after the marker, we just skip the data. continue } @@ -333,6 +335,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL // Load the header values in the previousLogLine previousLogLine.MyCall = headerMyCall previousLogLine.Operator = headerOperator + previousLogLine.isFirstLine = headerIsFirstLine previousLogLine.MyWWFF = headerMyWWFF previousLogLine.MyPOTA = headerMyPOTA previousLogLine.MySOTA = headerMySOTA @@ -392,7 +395,9 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL } //store the current logline so that it can be used as a model when parsing the next line + // and reset the FirstLine flag previousLogLine = logline + headerIsFirstLine = false //We go back to the top to process the next loaded log line (Continue not necessary here) } @@ -445,14 +450,14 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL // displayLogSimple will print to stdout a simplified dump of a full log func displayLogSimple(fullLog []LogLine) { - firstLine := true + isFirstLogLine := true for _, filledLogLine := range fullLog { - if firstLine { + if (filledLogLine.isFirstLine || isFirstLogLine) { + fmt.Print("\n\n") fmt.Println(SprintHeaderValues(filledLogLine)) fmt.Print(SprintColumnTitles()) - firstLine = false + isFirstLogLine = false } fmt.Print(SprintLogInColumn(filledLogLine)) } - } diff --git a/fleprocess/load_file_test.go b/fleprocess/load_file_test.go index 9a284d0..d40cc9e 100644 --- a/fleprocess/load_file_test.go +++ b/fleprocess/load_file_test.go @@ -22,6 +22,8 @@ import ( "testing" ) +//TODO: Add tests for POTA + func TestLoadFile_happyCase(t *testing.T) { //Given @@ -592,7 +594,7 @@ func TestLoadFile_redefining_myCall_must_fail(t *testing.T) { os.Remove(temporaryDataFileName) } -func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { +func TestLoadFile_redefining_myWWFF(t *testing.T) { //Given dataArray := make([]string, 0) @@ -607,6 +609,7 @@ func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { dataArray = append(dataArray, "20/5/23") dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5") dataArray = append(dataArray, "myWWFF onff-0001") + dataArray = append(dataArray, "40m cw 0955 ik5zzz 9 5") temporaryDataFileName := createTestFile(dataArray) @@ -626,11 +629,16 @@ func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { t.Errorf("Not the expected MyWWFF value: %s (expecting %s)", loadedLogFile[0].MyWWFF, expectedValue) } + expectedValue = "ONFF-0001" + if loadedLogFile[1].MyWWFF != expectedValue { + t.Errorf("Not the expected MyWWFF value: %s (expecting %s)", loadedLogFile[0].MyWWFF, expectedValue) + } + //Clean Up os.Remove(temporaryDataFileName) } -func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { +func TestLoadFile_redefining_mySOTA(t *testing.T) { //Given dataArray := make([]string, 0) @@ -645,6 +653,7 @@ func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { dataArray = append(dataArray, "20/5/23") dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5") dataArray = append(dataArray, "mySota on/on-111") + dataArray = append(dataArray, "40m cw 0955 ik5zzz 9 5") temporaryDataFileName := createTestFile(dataArray) @@ -652,8 +661,52 @@ func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true) //Then - if isLoadedOK { - t.Error("Test file processing should return with an error") + if !isLoadedOK { + t.Error("Test file processing should not fail") + } + if len(loadedLogFile) == 0 { + t.Error("No data loaded") + } + + expectedValue := "ON/ON-001" + if loadedLogFile[0].MySOTA != expectedValue { + t.Errorf("Not the expected MySOTA value: %s (expecting %s)", loadedLogFile[0].MySOTA, expectedValue) + } + + expectedValue = "ON/ON-111" + if loadedLogFile[1].MySOTA != expectedValue { + t.Errorf("Not the expected MySOTA value: %s (expecting %s)", loadedLogFile[0].MySOTA, expectedValue) + } + + //Clean Up + os.Remove(temporaryDataFileName) +} + +// FIXME: See issue #101 +func TestLoadFile_redefining_mySOTA_no_data(t *testing.T) { + + //Given + dataArray := make([]string, 0) + dataArray = append(dataArray, "# Header") + dataArray = append(dataArray, "myCall on4kjm/p") + dataArray = append(dataArray, "operator on4kjm") + dataArray = append(dataArray, "nickname Portable") + dataArray = append(dataArray, "myWwff onff-0258") + dataArray = append(dataArray, "mySota on/on-001") + dataArray = append(dataArray, " ") + dataArray = append(dataArray, " #Log") + dataArray = append(dataArray, "20/5/23") + dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5") + dataArray = append(dataArray, "mySota on/on-111") + + temporaryDataFileName := createTestFile(dataArray) + + //When + loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true) + + //Then + if !isLoadedOK { + t.Error("Test file processing should not fail") } if len(loadedLogFile) == 0 { t.Error("No data loaded") diff --git a/fleprocess/parse_line.go b/fleprocess/parse_line.go index cd5d309..6480277 100644 --- a/fleprocess/parse_line.go +++ b/fleprocess/parse_line.go @@ -28,6 +28,7 @@ type LogLine struct { Date string MyCall string Operator string + isFirstLine bool MyWWFF string MyPOTA string MySOTA string @@ -100,12 +101,12 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg //TODO: what happens when we have <> or when there are multiple comments //TODO: Refactor this! it is ugly - comment, inputStr := getBraketedData(inputStr, COMMENT) + comment, inputStr := getBracketedData(inputStr, COMMENT) if comment != "" { logLine.Comment = comment } - QSLmsg, inputStr := getBraketedData(inputStr, QSL) + QSLmsg, inputStr := getBracketedData(inputStr, QSL) if QSLmsg != "" { logLine.QSLmsg = QSLmsg } @@ -127,7 +128,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg logLine.RSTrcvd = defaultReport } else { - errorMsg = errorMsg + "Double definitiion of RST" + errorMsg = errorMsg + "Double definition of RST" } continue } @@ -297,7 +298,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "wwff" keyword is used, skip it if regexpIsWwffKeyWord.MatchString(element) { - // this keyword is not requiered anymore with FLE 3 and doesn't add any value + // this keyword is not required anymore with FLE 3 and doesn't add any value continue } @@ -310,7 +311,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "pota" keyword is used, skip it if regexpIsPotaKeyWord.MatchString(element) { - // this keyword is not requiered anymore with FLE 3 and doesn't add any value + // this keyword is not required anymore with FLE 3 and doesn't add any value continue } @@ -323,7 +324,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // If the "sota" keyword is used, skip it if regexpIsSotaKeyWord.MatchString(element) { - // this keyword is not requiered anymore with FLE 3 and doesn't add any value + // this keyword is not required anymore with FLE 3 and doesn't add any value continue } diff --git a/test/data/multi-SOTA-summits.adi b/test/data/multi-SOTA-summits.adi new file mode 100644 index 0000000..8ea44a3 --- /dev/null +++ b/test/data/multi-SOTA-summits.adi @@ -0,0 +1,10 @@ +ADIF Export for Fast Log Entry by DF3CB +FLE +3.1.0 + +MW0PJE/P MW0ABC 20160424 1000 2m FM 59 59 GW/NW-001 +MW0PJE/P MW0ABD 20160424 1001 2m FM 59 59 GW/NW-001 +MW0PJE/P MM0ABE 20160424 1200 2m FM 59 59 GW/NW-002 +MW0PJE/P MM0ABF 20160424 1201 2m FM 59 59 GW/NW-002 +MW0PJE/P MI0ABG 20160424 1400 2m FM 59 59 GW/NW-003 +MW0PJE/P MI0ABH 20160424 1401 2m FM 59 59 GW/NW-003 diff --git a/test/data/multi-SOTA-summits.txt b/test/data/multi-SOTA-summits.txt new file mode 100644 index 0000000..f9ce29b --- /dev/null +++ b/test/data/multi-SOTA-summits.txt @@ -0,0 +1,22 @@ +#Header +mycall MW0PJE/P + + +#Log + +#First summit +mysota GW/NW-001 +date 2016-04-24 +2m FM +1000 mw0abc +01 mw0abd + +# New summit +mysota GW/NW-002 +1200 mm0abe +01 mm0abf + +# third summit +mysota GW/NW-003 +1400 mi0abg +01 mi0abh \ No newline at end of file