add basic parse method
This commit is contained in:
+55
-5
@@ -5,15 +5,15 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBasicFlop(t *testing.T) {
|
||||
func TestBasicFlop(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
s :=`ZCZC TMQ2526 141605
|
||||
s := `ZCZC TMQ2526 141605
|
||||
FF ZBTJZPZX
|
||||
141604 ZBACZQZX
|
||||
(ARR-JAE7433/A0132-RKSI-ZBTJ1604)
|
||||
NNNN`
|
||||
tele, err := Parse(s)
|
||||
ast.Nil(err, "Should be no error")
|
||||
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])
|
||||
@@ -42,11 +42,61 @@ SI:A/C CHG
|
||||
=
|
||||
NNNN`
|
||||
tele, err := Parse(s)
|
||||
ast.Nil(err, "Should be no error")
|
||||
ast.Nil(err, "Should be no error")
|
||||
ast.Equal(tele.Complete, true, "Should be complete telegram")
|
||||
ast.Equal(15, len(tele.Fields), "get 15 lines")
|
||||
ast.Equal("ZCZC TMQ2886 142347", tele.Fields[0])
|
||||
ast.Equal(2886, tele.Sequence, "TMQ must be 2886")
|
||||
ast.Equal(true, tele.Type == "PLN", "This is a plan")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetValues(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := "ZBTJ1604"
|
||||
values := getFields(DestinationRegex, text)
|
||||
|
||||
ast.Equal(2, len(values))
|
||||
ast.Equal("ZBTJ", values["dest"])
|
||||
ast.Equal("1604", values["time"])
|
||||
}
|
||||
|
||||
func TestParseDestAndTime(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := `ZBTJ1604`
|
||||
dest, destTime := getAirportAndTime(text)
|
||||
ast.Equal("ZBTJ", dest)
|
||||
ast.Equal(16, destTime.Hour())
|
||||
ast.Equal(4, destTime.Minute())
|
||||
|
||||
text = `ZBTJ`
|
||||
dest, _ = getAirportAndTime(text)
|
||||
ast.Equal("ZBTJ", dest)
|
||||
|
||||
}
|
||||
|
||||
func TestGetFlopValues(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := `(ARR-JAE7433/A0132-RKSI-ZBTJ1604-ZBTJ)`
|
||||
values := getFlopValues(text)
|
||||
ast.Equal(5, len(values))
|
||||
ast.Equal("ARR", values[0])
|
||||
ast.Equal("JAE7433/A0132", values[1])
|
||||
ast.Equal("RKSI", values[2])
|
||||
ast.Equal("ZBTJ1604", values[3])
|
||||
ast.Equal("ZBTJ", values[4])
|
||||
|
||||
}
|
||||
|
||||
func TestGetFlight(t *testing.T) {
|
||||
ast := assert.New(t)
|
||||
text := `JAE7433/A0132`
|
||||
fn, rn := parseFlight(text)
|
||||
ast.Equal("JAE7433", fn)
|
||||
ast.Equal("A0132", rn)
|
||||
|
||||
text = "JAE1234"
|
||||
fn, rn = parseFlight(text)
|
||||
ast.Equal("JAE1234", fn)
|
||||
ast.Equal("", rn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user