refactor: Add support for parsing JD Airlines flight schedule data

This commit is contained in:
windyboy
2024-07-31 17:27:14 +08:00
parent 2729e33f59
commit 4bd2adda51
2 changed files with 20 additions and 7 deletions
+5
View File
@@ -15,6 +15,7 @@ type LineParser struct {
}
const (
CANCELLED = "CNL"
AirportCode = "airport"
Date = "date"
Task = "task"
@@ -173,6 +174,10 @@ func ParseWithDef(line string, parserDef *LineParser) *domain.ScheduleLine {
var flightSchedule = &domain.ScheduleLine{
Reference: line,
}
if strings.Contains(line, CANCELLED) {
flightSchedule.Comments = "Cancelled"
return flightSchedule
}
// var result map[string]string
if parserDef == nil {
log.Warnf("No definition found: %s", line)
+15 -7
View File
@@ -132,25 +132,33 @@ var _ = Describe("Schedule Parser", func() {
})
var _ = Describe("FindDef", func() {
var _ = Describe("Parser Definition", func() {
Context("find def for MF", func() {
It("should return a valid def", func() {
Context("MF", func() {
It("valid def", func() {
def := FindDef("MF")
Expect(def).NotTo(BeNil())
Expect(def.Airlines).To(ContainElement("MF"))
})
})
Context("find def for FM", func() {
It("should return a valid def", func() {
Context("FM", func() {
It("valid def", func() {
def := FindDef("FM")
Expect(def).NotTo(BeNil())
Expect(def.Airlines).To(ContainElement("FM"))
})
})
Context("find def for CK", func() {
It("should return a valid def", func() {
Context("8X", func() {
It("valid def", func() {
def := FindDef("8X")
Expect(def).NotTo(BeNil())
Expect(def.Airlines).To(ContainElement("8X"))
})
})
Context("CK", func() {
It("nil", func() {
def := FindDef("CK")
Expect(def).To(BeNil())
})