Skip to content
Open
2 changes: 1 addition & 1 deletion fleprocess/braketedData.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down
2 changes: 1 addition & 1 deletion fleprocess/braketedData_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
23 changes: 14 additions & 9 deletions fleprocess/load_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
headerMyCounty := ""
headerQslMsg := ""
headerNickname := ""
headerIsFirstLine := true
//headerDate := ""
lineCount := 0

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
}

}
61 changes: 57 additions & 4 deletions fleprocess/load_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"testing"
)

//TODO: Add tests for POTA

func TestLoadFile_happyCase(t *testing.T) {

//Given
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -645,15 +653,60 @@ 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)

//When
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")
Expand Down
13 changes: 7 additions & 6 deletions fleprocess/parse_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LogLine struct {
Date string
MyCall string
Operator string
isFirstLine bool
MyWWFF string
MyPOTA string
MySOTA string
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions test/data/multi-SOTA-summits.adi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ADIF Export for Fast Log Entry by DF3CB
<PROGRAMID:3>FLE
<ADIF_VER:5>3.1.0
<EOH>
<STATION_CALLSIGN:8>MW0PJE/P <CALL:6>MW0ABC <QSO_DATE:8>20160424 <TIME_ON:4>1000 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SOTA_REF:9>GW/NW-001 <EOR>
<STATION_CALLSIGN:8>MW0PJE/P <CALL:6>MW0ABD <QSO_DATE:8>20160424 <TIME_ON:4>1001 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SOTA_REF:9>GW/NW-001 <EOR>
<STATION_CALLSIGN:8>MW0PJE/P <CALL:6>MM0ABE <QSO_DATE:8>20160424 <TIME_ON:4>1200 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SOTA_REF:9>GW/NW-002 <EOR>
<STATION_CALLSIGN:8>MW0PJE/P <CALL:6>MM0ABF <QSO_DATE:8>20160424 <TIME_ON:4>1201 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SOTA_REF:9>GW/NW-002 <EOR>
<STATION_CALLSIGN:8>MW0PJE/P <CALL:6>MI0ABG <QSO_DATE:8>20160424 <TIME_ON:4>1400 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SOTA_REF:9>GW/NW-003 <EOR>
<STATION_CALLSIGN:8>MW0PJE/P <CALL:6>MI0ABH <QSO_DATE:8>20160424 <TIME_ON:4>1401 <BAND:2>2m <MODE:2>FM <RST_SENT:2>59 <RST_RCVD:2>59 <MY_SOTA_REF:9>GW/NW-003 <EOR>
22 changes: 22 additions & 0 deletions test/data/multi-SOTA-summits.txt
Original file line number Diff line number Diff line change
@@ -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