|
@@ -277,3 +277,40 @@ func TestJSON2NodeA1(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestNewNode2(t *testing.T) {
|
|
|
+ n, err := node.NewNodeFromJSON([]byte(`{"test": [1, 2, 3]}`))
|
|
|
+ if err != nil {
|
|
|
+ t.Fail()
|
|
|
+ t.Logf("Unexpected Error: %v", err)
|
|
|
+ }
|
|
|
+ if n.Name() != "test" {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Node Name expected \"test\", got \"%s\"", n.Name())
|
|
|
+ }
|
|
|
+ if n.Len() != 3 {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Node Length expected 3, got %d", n.Len())
|
|
|
+ }
|
|
|
+ n, err = node.NewNodeFromJSON([]byte(`{"test": [1, 2, 3}`))
|
|
|
+ if err == nil {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ t.Logf("Error expected!")
|
|
|
+ }
|
|
|
+ if n != nil {
|
|
|
+ if !t.Failed() {
|
|
|
+ t.Fail()
|
|
|
+ }
|
|
|
+ pay, err := n.MarshalJSON()
|
|
|
+ if err != nil {
|
|
|
+ t.Errorf("Node.MarshalJSON: %v", err)
|
|
|
+ }
|
|
|
+ t.Logf("Node should be nil! %s", pay)
|
|
|
+ }
|
|
|
+}
|