refactor: Update parsing of flight schedule data for improved accuracy and functionality

This commit is contained in:
windyboy
2024-07-30 10:56:05 +08:00
parent 766925f7f9
commit f827941a1b
2 changed files with 98 additions and 2 deletions
+3 -2
View File
@@ -13,11 +13,11 @@ const (
AirportCode = "airport"
Date = "date"
Task = "task"
IndexPattern = `(?P<idx>\(?L?\d+\)?\.?)`
IndexPattern = `(?P<idx>\(?L?[0-9]+\)?\.?)`
DatePattern = `\s?(?P<date>\d{2}\w{3})`
TaskPattern = `\s?(?P<task>[A-Z]\/[A-Z])`
WaypointPattern = `\s?(?P<arr_time>\d{4}(\(\d{2}\w{3}\))?)\/?(?P<airport>\w{3})\/?(?P<dep_time>\d{4}(\(\d{2}\w{3}\))?)`
FlightNumberPattern = `\s?(?P<number>[0-9A-Z][A-Z]\d{3,5})`
FlightNumberPattern = `\s?(?P<number>[0-9A-Z][0-9A-Z]\d{3,5})`
RegisterPattern = `\s?(?P<reg>B\d{4})`
)
@@ -53,6 +53,7 @@ func FindWaypoints(message string) map[string]string {
return result
}
func ParseLine(line string) *domain.FlightSchedule {
cleanLine := strings.TrimSpace(line)
words := strings.Split(cleanLine, " ")
+95
View File
@@ -7,6 +7,101 @@ import (
var _ = Describe("Schedule Parser", func() {
Describe("Index Parser", func() {
Context("parse : 83.", func() {
message := "83."
data := parse(message, IndexExpression)
It("should return a valid index", func() {
Expect(data).NotTo(BeNil())
Expect(data[Index]).To(Equal("83."))
})
})
Context("parse : (21)", func() {
message := "(21)"
data := parse(message, IndexExpression)
It("should return a valid index", func() {
Expect(data).NotTo(BeNil())
Expect(data[Index]).To(Equal("(21)"))
})
})
Context("parse : L59", func() {
message := "L59"
data := parse(message, IndexExpression)
It("should return a valid index", func() {
Expect(data).NotTo(BeNil())
Expect(data[Index]).To(Equal("L59"))
})
})
Context("parse : (205)", func() {
message := "(205)"
data := parse(message, IndexExpression)
It("should return a valid index", func() {
Expect(data).NotTo(BeNil())
Expect(data[Index]).To(Equal("(205)"))
})
})
Context("parse : L01", func() {
message := "L01"
data := parse(message, IndexExpression)
It("should return a valid index", func() {
Expect(data).NotTo(BeNil())
Expect(data[Index]).To(Equal("L01"))
})
})
Context("parse : 01)", func() {
message := "01)"
data := parse(message, IndexExpression)
It("should return a valid index", func() {
Expect(data).NotTo(BeNil())
Expect(data[Index]).To(Equal("01)"))
})
})
})
Describe("Flight Number Parser", func() {
Context("parse : FM9134", func() {
message := "FM9134"
data := parse(message, FlightNumberExpression)
It("should return a valid flight number", func() {
Expect(data).NotTo(BeNil())
Expect(data[FlightNumber]).To(Equal("FM9134"))
})
})
Context("parse : Y87969", func() {
message := "Y87969"
data := parse(message, FlightNumberExpression)
It("should return a valid flight number", func() {
Expect(data).NotTo(BeNil())
Expect(data[FlightNumber]).To(Equal("Y87969"))
})
})
Context("parse : CK261", func() {
message := "CK261"
data := parse(message, FlightNumberExpression)
It("should return a valid flight number", func() {
Expect(data).NotTo(BeNil())
Expect(data[FlightNumber]).To(Equal("CK261"))
})
})
Context("parse : 9C8812", func() {
message := "9C8812"
data := parse(message, FlightNumberExpression)
It("should return a valid flight number", func() {
Expect(data).NotTo(BeNil())
Expect(data[FlightNumber]).To(Equal("9C8812"))
})
})
})
Describe("FindWaypoints", func() {
It("should return the correct waypoints based on the message", func() {
message := "1845(11JUN)TSN/2100"