-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeta_encoder_test.go
54 lines (47 loc) · 1.3 KB
/
meta_encoder_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
package lang
import (
"testing"
"github.com/freeconf/yang"
"github.com/freeconf/yang/fc"
"github.com/freeconf/yang/parser"
"github.com/freeconf/yang/source"
)
func TestBasicMetaEncoder(t *testing.T) {
ypath := source.Dir("./test/testdata/yang")
m := parser.RequireModule(ypath, "testme")
x := NewMetaEncoder().Encode(m)
fc.AssertEqual(t, "testme", x.Ident)
fc.AssertEqual(t, len(m.DataDefinitions()), len(x.Definitions))
fc.AssertEqual(t, "x", x.Definitions[0].GetLeaf().Ident)
fc.AssertEqual(t, "z", x.Definitions[1].GetContainer().Ident)
}
var testFiles = []string{
"car",
"echo",
"meta",
"testme",
"advanced",
}
func TestMetaEncoder(t *testing.T) {
ypath := source.Dir("./test/testdata/yang")
for _, f := range testFiles {
t.Log(f)
m := parser.RequireModule(ypath, f)
NewMetaEncoder().Encode(m)
}
}
func TestRecurse(t *testing.T) {
ypath := source.Dir("./test/testdata/yang")
m := parser.RequireModule(ypath, "recurse")
e := NewMetaEncoder()
x := e.Encode(m)
z := x.Definitions[0].GetContainer()
fc.AssertEqual(t, "z", z.Ident)
fc.AssertEqual(t, "a", z.Definitions[0].GetLeaf().Ident)
zPtr := z.Definitions[1].GetPtr()
fc.AssertEqual(t, "z", zPtr.Path)
}
func TestMassiveRecurse(t *testing.T) {
m := parser.RequireModule(yang.InternalYPath, "fc-yang")
NewMetaEncoder().Encode(m)
}