|
@@ -314,3 +314,67 @@ func TestNewNode2(t *testing.T) {
|
|
|
t.Logf("Node should be nil! %s", pay)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestNewNode3(t *testing.T) {
|
|
|
+ n, err := node.NewNodeFromFile("test.json")
|
|
|
+ if err != nil {
|
|
|
+ t.Fail()
|
|
|
+ t.Logf("Node.NewNodeFromFile(\"test.json\"): %v", err)
|
|
|
+ }
|
|
|
+ if n == nil {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Node expected, got nil.")
|
|
|
+ }
|
|
|
+ if n.Name() != "test" {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Node name should be \"test\", got \"%s\"", n.Name())
|
|
|
+ }
|
|
|
+ if n.Len() != 4 {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Node should have 4 children, got %d", n.Len())
|
|
|
+ }
|
|
|
+ k1 := n.KidByName("kid1")
|
|
|
+ if k1 == nil || k1.Name() != "kid1" {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ if k1 != nil {
|
|
|
+ t.Logf("Kid1] KidByName, Expected 'kid1', got '%s'", k1.Name())
|
|
|
+ } else {
|
|
|
+ t.Logf("Kid1] KidByName, Expected 'kid1', got nil!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if k1 != nil {
|
|
|
+ if k1.Data().(float64) != 1.0 {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Kid1] Expected 1, got %#v", k1.Data())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ k3 := n.KidByName("kid3")
|
|
|
+ if k3 == nil || k3.Name() != "kid3" {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ if k1 != nil {
|
|
|
+ t.Logf("Kid3] KidByName, Expected 'kid3', got '%s'", k1.Name())
|
|
|
+ } else {
|
|
|
+ t.Logf("Kid3] KidByName, Expected 'kid3', got nil!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if k3 != nil {
|
|
|
+ if k3.Len() != 2 {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Kid3] Expected 2 children, got %d", k3.Len())
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|