add dep test
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
Name: "boom",
|
||||
Name: "boom",
|
||||
Usage: "make an explosive entrance",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Println("boom! I say!")
|
||||
|
||||
+4
-2
@@ -10,17 +10,19 @@ const (
|
||||
DestinationRegex = `(?P<dest>[A-Z]+)(?P<time>\d{0,4})?`
|
||||
DOFRegex = `(?P<dof>\w+)/(?P<time>\d{6})`
|
||||
TypeArrival = "ARR"
|
||||
TypeDeparture = "DEP"
|
||||
)
|
||||
|
||||
func parseArr(telegram *Telegram, data string) {
|
||||
func parseArrOrDep(telegram *Telegram, data string) {
|
||||
values := getFlopValues(data)
|
||||
l := len(values)
|
||||
if l < 4 {
|
||||
telegram.ParseErrors = append(telegram.ParseErrors, errors.New("arrival data less than 4 "))
|
||||
return
|
||||
}
|
||||
|
||||
telegram.FlightNumber, telegram.RegisterNumber = parseFlight(values[1])
|
||||
telegram.Departure = values[2]
|
||||
telegram.Departure, telegram.DepartureTime = getAirportAndTime(values[2])
|
||||
telegram.Destination, telegram.DestinationTime = getAirportAndTime(values[3])
|
||||
if l == 5 {
|
||||
parseDof(telegram, values[4])
|
||||
|
||||
@@ -40,3 +40,29 @@ 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())
|
||||
}
|
||||
|
||||
+2
-2
@@ -46,8 +46,8 @@ func Parse(text string) (*Telegram, error) {
|
||||
r := regexp.MustCompile(FlopRegex)
|
||||
data := r.FindString(telegram.Text)
|
||||
switch telegram.Type {
|
||||
case TypeArrival:
|
||||
parseArr(telegram, data)
|
||||
case TypeArrival, TypeDeparture:
|
||||
parseArrOrDep(telegram, data)
|
||||
}
|
||||
}
|
||||
return telegram, nil
|
||||
|
||||
Reference in New Issue
Block a user