From a8f90031a266f1f4346ec454dc2650af1ab8ae0a Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Sun, 31 Dec 2023 14:41:30 +0100 Subject: [PATCH] WIP --- fleprocess/load_file.go | 22 +++++++++------ fleprocess/load_file_test.go | 47 ++++++++++++++++++++++++++++++-- fleprocess/parse_line.go | 1 + test/data/multi-SOTA-summits.txt | 7 ++++- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/fleprocess/load_file.go b/fleprocess/load_file.go index 2fd9bac..05d96b0 100644 --- a/fleprocess/load_file.go +++ b/fleprocess/load_file.go @@ -75,6 +75,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL headerMyGrid := "" headerQslMsg := "" headerNickname := "" + headerIsFirstLine := true //headerDate := "" lineCount := 0 @@ -207,11 +208,12 @@ 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 + // //FIXME: enhancement for issue #101 + // if headerMySOTA != "" { + // errorLog = append(errorLog, fmt.Sprintf("Warning: redefining MySOTA at line %d", lineCount)) + // continue + // } errorMsg := "" mySotaList := regexpHeaderMySota.Split(eachline, -1) if len(strings.TrimSpace(mySotaList[1])) > 0 { @@ -221,6 +223,10 @@ 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 } @@ -279,6 +285,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 @@ -336,6 +343,7 @@ 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 previousLogLine = logline + //FIXME: we need to reset the first line //We go back to the top to process the next loaded log line (Continue not necessary here) } @@ -388,12 +396,10 @@ 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 for _, filledLogLine := range fullLog { - if firstLine { + if filledLogLine.isFirstLine { fmt.Println(SprintHeaderValues(filledLogLine)) fmt.Print(SprintColumnTitles()) - firstLine = false } fmt.Print(SprintLogInColumn(filledLogLine)) } diff --git a/fleprocess/load_file_test.go b/fleprocess/load_file_test.go index 29e984e..bd094c5 100644 --- a/fleprocess/load_file_test.go +++ b/fleprocess/load_file_test.go @@ -455,7 +455,8 @@ func TestLoadFile_redefining_myWWFF_must_fail(t *testing.T) { os.Remove(temporaryDataFileName) } -func TestLoadFile_redefining_mySOTA_must_fail(t *testing.T) { +// FIXME: See issue #101 +func TestLoadFile_redefining_mySOTA(t *testing.T) { //Given dataArray := make([]string, 0) @@ -470,6 +471,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) @@ -477,8 +479,47 @@ 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) + } + + //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 c0e4181..0d16d9f 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 diff --git a/test/data/multi-SOTA-summits.txt b/test/data/multi-SOTA-summits.txt index 795c276..f9ce29b 100644 --- a/test/data/multi-SOTA-summits.txt +++ b/test/data/multi-SOTA-summits.txt @@ -1,7 +1,12 @@ #Header mycall MW0PJE/P -mysota GW/NW-001 + + #Log + +#First summit +mysota GW/NW-001 +date 2016-04-24 2m FM 1000 mw0abc 01 mw0abd