Debian Codegraph @

issue_188_test.go

raw
1 package sprig
2
3 import (
4 "testing"
5 )
6
7 func TestIssue188(t *testing.T) {
8 tests := map[string]string{
9
10 // This first test shows two merges and the merge is NOT A DEEP COPY MERGE.
11 // The first merge puts $one on to $target. When the second merge of $two
12 // on to $target the nested dict brought over from $one is changed on
13 // $one as well as $target.
14 `{{- $target := dict -}}
15 {{- $one := dict "foo" (dict "bar" "baz") "qux" true -}}
16 {{- $two := dict "foo" (dict "bar" "baz2") "qux" false -}}
17 {{- mergeOverwrite $target $one | toString | trunc 0 }}{{ $__ := mergeOverwrite $target $two }}{{ $one }}`: "map[foo:map[bar:baz2] qux:true]",
18
19 // This test uses deepCopy on $one to create a deep copy and then merge
20 // that. In this case the merge of $two on to $target does not affect
21 // $one because a deep copy was used for that merge.
22 `{{- $target := dict -}}
23 {{- $one := dict "foo" (dict "bar" "baz") "qux" true -}}
24 {{- $two := dict "foo" (dict "bar" "baz2") "qux" false -}}
25 {{- deepCopy $one | mergeOverwrite $target | toString | trunc 0 }}{{ $__ := mergeOverwrite $target $two }}{{ $one }}`: "map[foo:map[bar:baz] qux:true]",
26 }
27
28 for tpl, expect := range tests {
29 if err := runt(tpl, expect); err != nil {
30 t.Error(err)
31 }
32 }
33 }