forked from geops/gtfsparser
-
Notifications
You must be signed in to change notification settings - Fork 7
/
feed_test.go
98 lines (75 loc) · 2.36 KB
/
feed_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2016 Patrick Brosi
// Authors: [email protected]
//
// Use of this source code is governed by a GPL v2
// license that can be found in the LICENSE file
package gtfsparser
import (
// "github.com/patrickbr/gtfsparser/gtfs"
"testing"
)
func TestFeedParsing(t *testing.T) {
feedCorA := NewFeed()
feedCorA.SetParseOpts(ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: false})
e := feedCorA.Parse("./testfeeds/correct/a")
if e != nil {
t.Error(e)
return
}
feedFailA := NewFeed()
feedFailA.SetParseOpts(ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: false})
e = feedFailA.Parse("./testfeeds/fail/a")
if e == nil {
t.Error("Parse successful, but input feed was incorrect!")
return
}
feedFailA = NewFeed()
feedFailA.SetParseOpts(ParseOptions{UseDefValueOnError: true, DropErroneous: false, DryRun: false})
e = feedFailA.Parse("./testfeeds/fail/a")
if e == nil {
t.Error("Parse successful, but input feed was incorrect - and unfixable via def value!")
return
}
feedFailA = NewFeed()
feedFailA.SetParseOpts(ParseOptions{UseDefValueOnError: false, DropErroneous: true, DryRun: false})
e = feedFailA.Parse("./testfeeds/fail/a")
if e != nil {
t.Error(e)
return
}
shp, _ := feedFailA.Shapes["C_shp"]
for i, p := range shp.Points {
if i > 0 && p.HasDistanceTraveled() && shp.Points[i-1].HasDistanceTraveled() && p.Dist_traveled <= shp.Points[i-1].Dist_traveled {
t.Error(p.Dist_traveled, shp.Points[i-1].Dist_traveled)
return
}
}
if len(shp.Points) != 7 {
t.Error(len(shp.Points))
}
feedCorB := NewFeed()
feedCorB.SetParseOpts(ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: false})
e = feedCorB.Parse("./testfeeds/correct/b")
if e != nil {
t.Error(e)
return
}
feedCorAddFlds := NewFeed()
feedCorAddFlds.SetParseOpts(ParseOptions{UseDefValueOnError: false, DropErroneous: false, DryRun: false, KeepAddFlds: true})
e = feedCorAddFlds.Parse("./testfeeds/correct/addflds")
if e != nil {
t.Error(e)
return
}
if len(feedCorAddFlds.Agencies) != 1 {
t.Error("expected on agency")
return
}
a := feedCorAddFlds.Agencies["DTA"]
if feedCorAddFlds.AgenciesAddFlds["testfield"][a.Id] != "testvalue" {
t.Error("Wrong value for <testfield>")
}
if feedCorAddFlds.ShapesAddFlds["testfield_shp"]["B_shp"][5] != "b" {
t.Error("Wrong value for <testfield>")
}
}