package fleprocess /* Copyright © 2020 Jean-Marc Meessen, ON4KJM Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import ( "reflect" "testing" ) func Test_adifElement(t *testing.T) { type args struct { elementName string elementValue string } tests := []struct { name string args args wantElement string }{ { "case 1", args{elementName: "station_callsign", elementValue: "ON4KJM/P"}, "ON4KJM/P ", }, { "case 2", args{elementName: "time_ON", elementValue: "1310"}, "1310 ", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if gotElement := adifElement(tt.args.elementName, tt.args.elementValue); gotElement != tt.wantElement { t.Errorf("adifElement() = %v, want %v", gotElement, tt.wantElement) } }) } } func Test_buildAdif(t *testing.T) { sampleFilledLog1 := []LogLine{ {MyCall: "ON4KJM/P", Call: "S57LC", Date: "2020-05-24", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM", Nickname: "ONFF-0259-1"}, {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM"}, } expectedOutput1 := []string{ "ADIF Export for Fast Log Entry by DF3CB", "FLE", "3.1.0", "", "ON4KJM/P S57LC 20200524 1310 20m CW 14.045 599 599 WWFF ONFF-0259 ON4KJM ONFF-0259-1 ", "ON4KJM/P ON4LY 20200524 1312 20m CW 559 599 WWFF ONFF-0259 ON4KJM ", } sampleFilledLog2 := []LogLine{ {MyCall: "ON4KJM/P", Call: "S57LC", Date: "2020-05-24", MyGrid: "JO40eu", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", GridLoc: "JO50", MyWWFF: "ONFF-0259", Operator: "ON4KJM", Nickname: "ONFF-0259-1"}, {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", MyGrid: "JO40eu", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM"}, } expectedOutput2 := []string{ "ADIF Export for Fast Log Entry by DF3CB", "FLE", "3.1.0", "", "ON4KJM/P S57LC 20200524 1310 20m CW 14.045 599 599 JO50 WWFF ONFF-0259 ON4KJM JO40eu ONFF-0259-1 ", "ON4KJM/P ON4LY 20200524 1312 20m CW 559 599 WWFF ONFF-0259 ON4KJM JO40eu ", } sampleFilledLog3 := []LogLine{ {MyCall: "ON4KJM/P", Call: "S57LC", Date: "2020-05-24", MyGrid: "JO40eu", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", GridLoc: "JO50", MyWWFF: "ONFF-0259", Operator: "ON4KJM", Nickname: "ONFF-0259-1"}, {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", MyGrid: "JO40eu", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyWWFF: "ONFF-0259", Operator: "ON4KJM", WWFF: "DLFF-0001"}, } expectedOutput3 := []string{ "ADIF Export for Fast Log Entry by DF3CB", "FLE", "3.1.0", "", "ON4KJM/P S57LC 20200524 1310 20m CW 14.045 599 599 JO50 WWFF ONFF-0259 ON4KJM JO40eu ONFF-0259-1 ", "ON4KJM/P ON4LY 20200524 1312 20m CW 559 599 WWFF ONFF-0259 WWFF DLFF-0001 ON4KJM JO40eu ", } type args struct { fullLog []LogLine isWWFF bool isSOTA bool } tests := []struct { name string args args wantAdifList []string }{ { "Happy case-WWFF", args{fullLog: sampleFilledLog1, isWWFF: true, isSOTA: false}, expectedOutput1, }, { "Happy case-Grid", args{fullLog: sampleFilledLog2, isWWFF: true, isSOTA: false}, expectedOutput2, }, { "Happy case-Park2Park", args{fullLog: sampleFilledLog3, isWWFF: true, isSOTA: false}, expectedOutput3, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if gotAdifList := buildAdif(tt.args.fullLog, tt.args.isWWFF, tt.args.isSOTA); !reflect.DeepEqual(gotAdifList, tt.wantAdifList) { t.Errorf("buildAdif() = %v, want %v", gotAdifList, tt.wantAdifList) } }) } } func Test_adifDate(t *testing.T) { type args struct { inputDate string } tests := []struct { name string args args wantOutputDate string }{ { "Happy case", args{inputDate: "2020-06-13"}, "20200613", }, //Panics as expected but I don't know how to test this. // { // "Bad format", // args{inputDate: "2020-13-06"}, // "20200613", // }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if gotOutputDate := adifDate(tt.args.inputDate); gotOutputDate != tt.wantOutputDate { t.Errorf("adifDate() = %v, want %v", gotOutputDate, tt.wantOutputDate) } }) } }