Prevent second definition of some header fields

pull/53/head
Jean-Marc MEESSEN 4 years ago committed by GitHub
parent 51bea8d698
commit ca4a992b8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -121,6 +121,11 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
//My Call
if regexpHeaderMyCall.MatchString(eachline) {
//Attempt to redefine value
if headerMyCall != "" {
errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine MyCall at line %d", lineCount))
continue
}
errorMsg := ""
myCallList := regexpHeaderMyCall.Split(eachline, -1)
if len(strings.TrimSpace(myCallList[1])) > 0 {
@ -136,6 +141,11 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
//Operator
if regexpHeaderOperator.MatchString(eachline) {
//Attempt to redefine value
if headerOperator != "" {
errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine Operator at line %d", lineCount))
continue
}
errorMsg := ""
myOperatorList := regexpHeaderOperator.Split(eachline, -1)
if len(strings.TrimSpace(myOperatorList[1])) > 0 {
@ -151,6 +161,11 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
// My WWFF
if regexpHeaderMyWwff.MatchString(eachline) {
//Attempt to redefine value
if headerMyWWFF != "" {
errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine MyWWFF at line %d", lineCount))
continue
}
errorMsg := ""
myWwffList := regexpHeaderMyWwff.Split(eachline, -1)
if len(strings.TrimSpace(myWwffList[1])) > 0 {
@ -166,6 +181,11 @@ 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
}
errorMsg := ""
mySotaList := regexpHeaderMySota.Split(eachline, -1)
if len(strings.TrimSpace(mySotaList[1])) > 0 {
@ -181,6 +201,11 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
//My Grid
if regexpHeaderMyGrid.MatchString(eachline) {
//Attempt to redefine value
if headerMyGrid != "" {
errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine MyGrid at line %d", lineCount))
continue
}
errorMsg := ""
myGridList := regexpHeaderMyGrid.Split(eachline, -1)
if len(strings.TrimSpace(myGridList[1])) > 0 {
@ -207,6 +232,11 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
//Nickname
if regexpHeaderNickname.MatchString(eachline) {
//Attempt to redefine value
if headerNickname != "" {
errorLog = append(errorLog, fmt.Sprintf("Attempt to redefine eQSL Nickname at line %d", lineCount))
continue
}
myNicknameList := regexpHeaderNickname.Split(eachline, -1)
if len(strings.TrimSpace(myNicknameList[1])) > 0 {
headerNickname = strings.TrimSpace(myNicknameList[1])
@ -216,43 +246,6 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL
continue
}
// // Date with keyword
// if regexpHeaderDateMarker.MatchString(eachline) {
// errorMsg := ""
// myDateList := regexpHeaderDateMarker.Split(eachline, -1)
// if len(myDateList[1]) > 0 {
// normalizedDate := ""
// normalizedDate, errorMsg = NormalizeDate(myDateList[1])
// if len(errorMsg) != 0 {
// errorLog = append(errorLog, fmt.Sprintf("Invalid Date at line %d: %s (%s)", lineCount, eachline, errorMsg))
// } else {
// headerDate, errorMsg = ValidateDate(normalizedDate)
// if len(errorMsg) != 0 {
// errorLog = append(errorLog, fmt.Sprintf("Invalid Date at line %d: %s (%s)", lineCount, myDateList[1], errorMsg))
// }
// }
// }
// //If there is no data after the marker, we just skip the data.
// continue
// }
// //Date, apparently alone on a line?
// if regexpDatePattern.MatchString(eachline) {
// //We probably have a date, let's normalize it
// errorMsg := ""
// normalizedDate := ""
// normalizedDate, errorMsg = NormalizeDate(eachline)
// if len(errorMsg) != 0 {
// errorLog = append(errorLog, fmt.Sprintf("Invalid Date at line %d: %s (%s)", lineCount, eachline, errorMsg))
// } else {
// headerDate, errorMsg = ValidateDate(normalizedDate)
// if len(errorMsg) != 0 {
// errorLog = append(errorLog, fmt.Sprintf("Invalid Date at line %d: %s (%s)", lineCount, eachline, errorMsg))
// }
// }
// continue
// }
// ****
// ** Process the data block
// ****

@ -381,6 +381,248 @@ func TestLoadFile_happyCase_day(t *testing.T) {
os.Remove(temporaryDataFileName)
}
func TestLoadFile_redefining_myCall_must_fail(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, " ")
dataArray = append(dataArray, " #Log")
dataArray = append(dataArray, "20/5/23")
dataArray = append(dataArray, "40m cw 0950 ik5zve/5 9 5")
dataArray = append(dataArray, "myCall on4do")
temporaryDataFileName := createTestFile(dataArray)
//When
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
//Then
if isLoadedOK {
t.Error("Test file processing should return with an error")
}
if len(loadedLogFile) == 0 {
t.Error("No data loaded")
}
expectedValue := "ON4KJM/P"
if loadedLogFile[0].MyCall != expectedValue {
t.Errorf("Not the expected MyCall value: %s (expecting %s)", loadedLogFile[0].MyCall, expectedValue)
}
//Clean Up
os.Remove(temporaryDataFileName)
}
func TestLoadFile_redefining_myWWFF_must_fail(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, "myWWFF onff-0001")
temporaryDataFileName := createTestFile(dataArray)
//When
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
//Then
if isLoadedOK {
t.Error("Test file processing should return with an error")
}
if len(loadedLogFile) == 0 {
t.Error("No data loaded")
}
expectedValue := "ONFF-0258"
if loadedLogFile[0].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) {
//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 return with an error")
}
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)
}
func TestLoadFile_redefining_myGRID_must_fail(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, "myGrid YO50")
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, "myGrid ZZ99")
temporaryDataFileName := createTestFile(dataArray)
//When
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
//Then
if isLoadedOK {
t.Error("Test file processing should return with an error")
}
if len(loadedLogFile) == 0 {
t.Error("No data loaded")
}
expectedValue := "YO50"
if loadedLogFile[0].MyGrid != expectedValue {
t.Errorf("Not the expected MyGRID value: %s (expecting %s)", loadedLogFile[0].MyGrid, expectedValue)
}
//Clean Up
os.Remove(temporaryDataFileName)
}
func TestLoadFile_redefining_operator_must_fail(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, "operator blahh")
temporaryDataFileName := createTestFile(dataArray)
//When
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
//Then
if isLoadedOK {
t.Error("Test file processing should return with an error")
}
if len(loadedLogFile) == 0 {
t.Error("No data loaded")
}
expectedValue := "ON4KJM"
if loadedLogFile[0].Operator != expectedValue {
t.Errorf("Not the expected operator value: %s (expecting %s)", loadedLogFile[0].Operator, expectedValue)
}
//Clean Up
os.Remove(temporaryDataFileName)
}
func TestLoadFile_redefining_nickname_must_fail(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, "nickname blaaahh")
temporaryDataFileName := createTestFile(dataArray)
//When
loadedLogFile, isLoadedOK := LoadFile(temporaryDataFileName, true)
//Then
if isLoadedOK {
t.Error("Test file processing should return with an error")
}
if len(loadedLogFile) == 0 {
t.Error("No data loaded")
}
expectedValue := "Portable"
if loadedLogFile[0].Nickname != expectedValue {
t.Errorf("Not the expected Nickname value: %s (expecting %s)", loadedLogFile[0].Nickname, expectedValue)
}
//Clean Up
os.Remove(temporaryDataFileName)
}
func TestLoadFile_bad_date(t *testing.T) {
//Given

Loading…
Cancel
Save