Files
tele-proc/parser/telegram_test.go
T

52 lines
1.4 KiB
Go
Raw Normal View History

2020-12-31 17:57:24 +08:00
package parser
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestBasicFlop(t *testing.T) {
ast := assert.New(t)
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.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])
ast.Equal(2526, tele.Sequence, "TMQ must be 2526")
ast.Equal(false, tele.Type == "PLN", "Not a plan")
ast.Equal("ARR", tele.Type, "Flop type is ARR")
}
func TestBasicPln(t *testing.T) {
ast := assert.New(t)
s := `ZCZC TMQ2886 142347
QU TSNZPCA
.
QU WUHZPCA WUHTZ8X TSNZPCA TSNTZCR FOCZPCA FOCTZMF XIYZPCA XIYKL8X
KWLZPCA KWLTF8X CANZPCA CANUOCZ CANKNCZ
.XMNUOMF 142346
PLN
15MAY
01) MF8138 B5162 ILS(8) TSN0010 0155WUH0245 0355FOC
02) MF8323 B5308 ILS(8) TSN0625 0810XIY0910 1050KWL
03) MF8324 B5308 ILS(8) KWL1135 1315XIY1405 1535TSN
04) MF8347 B5162 ILS(8) FOC0650 0815CAN
05) MF8348 B5162 ILS(8) CAN0920 1050FOC
SI:A/C CHG
=
NNNN`
tele, err := Parse(s)
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")
}