refactor: Update parseWaypoints function to return error in schedule_parser_test.go

This commit is contained in:
windyboy
2024-08-06 22:28:46 +08:00
parent afafd51bad
commit bbaea62788
5 changed files with 293 additions and 117 deletions
+3 -42
View File
@@ -24,49 +24,10 @@ type LineParser struct {
Fields map[int]string
}
// Constants for specific values.
const (
CANCELLED = "CNL"
AirportCode = "airport"
Date = "date"
Task = "task"
// Index = "idx"
)
// Regular expression patterns.
const (
AllDigitsPattern = `^(?P<dep_time>\d+)$`
IndexPattern = `^(?P<idx>\(?L?[0-9]+\)?:?\.?)$`
DatePattern = `^(?P<date>\d{2}\w{3})$`
TaskPattern = `(?P<task>[A-Z]\/[A-Z])$`
WaypointPattern = `^(SI:)?(?P<arr_time>\d{4}(\(\d{2}[A-Z]{3}\))?)?\/?(?P<airport>[A-Z]{3})\/?(?P<dep_time>\d{4}(\(\d{2}[A-Z]{3}\))?)?$`
FlightNumberPattern = `^(?P<number>[0-9A-Z][0-9A-Z]\d{3,5}(\/\d+)*)$`
RegisterPattern = `^(?P<reg>B\d{4})$`
ArrPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>[A-Z0-9]+)(\/?(?P<ssr>[A-Z0-9]+))?-(?P<dep>[A-Z]{4})-(?P<arr>[A-Z]{4})(?P<arr_time>\d{4})\)$`
DepPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>[A-Z0-9]+)(\/(?P<ssr>[A-Z0-9]+))?-(?P<dep>[A-Z]{4})(?P<dep_time>\d{4})-(?P<arr>[A-Z]{4})\)$`
FplPatternString = `\((?P<category>[A-Z]{3})-(?P<number>[A-Z]+\d+)-(?P<indicator>[A-Z]{2})\n-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\n?-(?P<surve>.*)\n?-(?P<dep>[A-Z]{4})(?P<dep_time>\d{4})\n?-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s+(?P<route>(.|\n)+)\n-(?P<dest>[A-Z]{4})(?P<estt>\d{4})\s?(?P<alter>(\s[A-Z]{4})+)\n?-([A-Z]{3}\/(?:[A-Z]{4}\d{4}\s?)+)?(?P<other>(?m)[A-Z]{3}\/(.|\n)*)\)$`
CnlPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>\w+\d+)-?(?P<dep>[A-Z]{4})?-?(?<arr>[A-Z]{4})\)$`
DlaPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>\w+\d+)-?(?P<dep>[A-Z]{4})(?P<dep_time>\d{4})?-?(?<arr>[A-Z]{4})(?<arr_time>\d{4})?\)$`
)
var (
// Pre-compiled regular expressions.
AllDigitsExpression = regexp.MustCompile(AllDigitsPattern)
IndexExpression = regexp.MustCompile(IndexPattern)
TaskExpression = regexp.MustCompile(TaskPattern)
DateExpression = regexp.MustCompile(DatePattern)
WaypointExpression = regexp.MustCompile(WaypointPattern)
FlightNumberExpression = regexp.MustCompile(FlightNumberPattern)
RegisterExpression = regexp.MustCompile(RegisterPattern)
ArrPatternExpression = regexp.MustCompile(ArrPatternString)
DepPatternExpression = regexp.MustCompile(DepPatternString)
FplPatternExpression = regexp.MustCompile(FplPatternString)
CnlPatternExpression = regexp.MustCompile(CnlPatternString)
DlaPatternExpression = regexp.MustCompile(DlaPatternString)
BodyTypePattern = regexp.MustCompile(`^\(([A-Z]{3})(.*\n?)+\)$`)
bodyPatterns = map[string]BodyConfig{}
parserMap = map[string]*regexp.Regexp{}
parserDef = &[]LineParser{}
bodyPatterns = map[string]BodyConfig{}
parserMap = map[string]*regexp.Regexp{}
parserDef = &[]LineParser{}
)
func init() {