arr and dep with composite regex
This commit is contained in:
+60
-28
@@ -5,12 +5,50 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArr(t *testing.T) {
|
||||
func TestAirportAndTimeRegex(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := "ZBTJ0554"
|
||||
|
||||
fields := getFields(DepRegex, text)
|
||||
ast.Equal(1, len(fields), "Should get 1 filed")
|
||||
ast.Equal("ZBTJ0554", fields[KeyDeparture])
|
||||
|
||||
fields = getFields(DestinationRegex, text)
|
||||
|
||||
ast.Equal(2, len(fields))
|
||||
ast.Equal("ZBTJ", fields["dest"])
|
||||
ast.Equal("0554", fields["time"])
|
||||
|
||||
}
|
||||
|
||||
func TestPlaneRegex(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := "JAE7433/A0132"
|
||||
fields := getFields(PlaneRegex, text)
|
||||
ast.Equal(1, len(fields), "Should get plane value")
|
||||
ast.Equal("JAE7433/A0132", fields[KeyPlane])
|
||||
|
||||
}
|
||||
|
||||
func TestDofRegex(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := "DOF/120820"
|
||||
fields := getFields(DofRegex, text)
|
||||
ast.Equal(1, len(fields), "Should get dof value")
|
||||
ast.Equal("DOF/120820", fields[KeyDof])
|
||||
|
||||
d := parseDof(text)
|
||||
ast.Equal(2012, d.Year())
|
||||
ast.Equal(8, int(d.Month()))
|
||||
ast.Equal(20, d.Day())
|
||||
}
|
||||
|
||||
func TestArrDep(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
s := `ZCZC TMQ2526 141605
|
||||
FF ZBTJZPZX
|
||||
141604 ZBACZQZX
|
||||
(ARR-JAE7433/A0132-RKSI-ZBTJ1604-DOF/120820)
|
||||
(ARR-JAE7433/A0132-RKSI-ZBTJ1604)
|
||||
NNNN`
|
||||
tele, err := Parse(s)
|
||||
ast.Nil(err, "Should be no error")
|
||||
@@ -26,6 +64,26 @@ NNNN`
|
||||
ast.Equal("ZBTJ", tele.Destination, "destination airport is ZBTJ")
|
||||
ast.Equal(16, tele.DestinationTime.Hour())
|
||||
ast.Equal(4, tele.DestinationTime.Minute())
|
||||
|
||||
s = `ZCZC TMQ2526 141605
|
||||
FF ZBTJZPZX
|
||||
141604 ZBACZQZX
|
||||
(DEP-JAE7433/A0132-RKSI1604-ZBTJ-DOF/120820)
|
||||
NNNN`
|
||||
tele, err = Parse(s)
|
||||
ast.Nil(err, "Should be no error")
|
||||
ast.Equal(tele.Complete, true, "Should be complete telegram")
|
||||
ast.Equal(4, len(tele.Fields), "get 4 lines")
|
||||
ast.Equal("ZCZC TMQ2526 141605", tele.Fields[0])
|
||||
ast.Equal(2526, tele.Sequence, "TMQ must be 2526")
|
||||
ast.Equal(false, tele.Type == "PLN", "Not a plan")
|
||||
ast.Equal("DEP", tele.Type, "Flop type is DEP")
|
||||
ast.Equal("JAE7433", tele.FlightNumber, "flight number is JAE7433")
|
||||
ast.Equal("A0132", tele.RegisterNumber, "register number is A0132")
|
||||
ast.Equal("RKSI", tele.Departure, "departure airport is RKSI")
|
||||
ast.Equal("ZBTJ", tele.Destination, "destination airport is ZBTJ")
|
||||
ast.Equal(16, tele.DepartureTime.Hour())
|
||||
ast.Equal(4, tele.DepartureTime.Minute())
|
||||
ast.Equal(2012, tele.DateOfFlight.Year())
|
||||
ast.Equal(8, int(tele.DateOfFlight.Month()))
|
||||
ast.Equal(20, tele.DateOfFlight.Day())
|
||||
@@ -41,32 +99,6 @@ NNNN`
|
||||
|
||||
}
|
||||
|
||||
func TestDep(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := `ZCZC TMQ2626 142159
|
||||
FF ZBTJZXZX
|
||||
142158 ZBTJZPZX
|
||||
(DEP-JAE7433/A3036-ZBTJ1816-EDDF-DOF/120820)
|
||||
NNNN`
|
||||
tele, err := Parse(text)
|
||||
ast.Nil(err, "Should be no error")
|
||||
ast.Equal(4, len(tele.Fields), "get 4 lines")
|
||||
ast.Equal("ZCZC TMQ2626 142159", tele.Fields[0])
|
||||
ast.Equal(2626, tele.Sequence, "TMQ must be 2626")
|
||||
ast.Equal(false, tele.Type == "PLN", "Not a plan")
|
||||
ast.Equal("DEP", tele.Type, "Flop type is DEP")
|
||||
ast.Equal("JAE7433", tele.FlightNumber, "flight number is JAE7433")
|
||||
ast.Equal("A3036", tele.RegisterNumber, "register number is A3036")
|
||||
ast.Equal("ZBTJ", tele.Departure, "departure airport is ZBTJ")
|
||||
ast.Equal(18, tele.DepartureTime.Hour())
|
||||
ast.Equal(16, tele.DepartureTime.Minute())
|
||||
ast.Equal("EDDF", tele.Destination, "destination airport is EDDF")
|
||||
|
||||
ast.Equal(2012, tele.DateOfFlight.Year())
|
||||
ast.Equal(8, int(tele.DateOfFlight.Month()))
|
||||
ast.Equal(20, tele.DateOfFlight.Day())
|
||||
}
|
||||
|
||||
func TestFpl(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := `ZCZC TMQ2628 151601
|
||||
|
||||
Reference in New Issue
Block a user