RNode copier

This commit is contained in:
jregan
2020-08-21 17:58:26 -07:00
parent 9b4d4c9d46
commit 24beeb429d
4 changed files with 106 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
package yaml
import (
"reflect"
"strings"
"testing"
@@ -206,6 +207,33 @@ func TestIsMissingOrNull(t *testing.T) {
}
}
func TestCopy(t *testing.T) {
rn := RNode{
fieldPath: []string{"fp1", "fp2"},
value: &Node{
Kind: 200,
},
Match: []string{"m1", "m2"},
}
rnC := rn.Copy()
if !reflect.DeepEqual(&rn, rnC) {
t.Fatalf("copy %v is not deep equal to %v", rnC, rn)
}
tmp := rn.value.Kind
rn.value.Kind = 666
if reflect.DeepEqual(rn, rnC) {
t.Fatalf("changing component should break equality")
}
rn.value.Kind = tmp
if !reflect.DeepEqual(&rn, rnC) {
t.Fatalf("should be back to normal")
}
rn.fieldPath[0] = "Different"
if reflect.DeepEqual(rn, rnC) {
t.Fatalf("changing fieldpath should break equality")
}
}
func TestFieldRNodes(t *testing.T) {
testCases := []struct {
testName string