Jelajahi Sumber

Added aditional tests for NewNodeFromJSON

Steve Thielemann 1 tahun lalu
induk
melakukan
0429a48e60
1 mengubah file dengan 37 tambahan dan 0 penghapusan
  1. 37 0
      node_test.go

+ 37 - 0
node_test.go

@@ -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)
+	}
+}