Skip to content

Commit d6ec5cf

Browse files
committed
cue: use more realistic arguments for TestDecode
It passed a pointer to an interfaces for each of the tests, which is somewhat useful, but not ideal. Change-Id: I8679d3893050b796d520c3b10328fe2202b1d887 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2713 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 9c96be3 commit d6ec5cf

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

cue/types_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ func TestDecode(t *testing.T) {
994994
err: "from source",
995995
}, {
996996
value: `"str"`,
997-
dst: "",
997+
dst: new(string),
998998
want: "str",
999999
}, {
10001000
value: `"str"`,
@@ -1003,45 +1003,46 @@ func TestDecode(t *testing.T) {
10031003
}, {
10041004
value: `{}`,
10051005
dst: &fields{},
1006-
want: &fields{},
1006+
want: fields{},
10071007
}, {
10081008
value: `{a:1,b:2,c:3}`,
10091009
dst: &fields{},
1010-
want: &fields{A: 1, B: 2, C: 3},
1010+
want: fields{A: 1, B: 2, C: 3},
10111011
}, {
10121012
value: `{"\(k)": v for k, v in y if v > 1}
10131013
y: {a:1,b:2,c:3}`,
10141014
dst: &fields{},
1015-
want: &fields{B: 2, C: 3},
1015+
want: fields{B: 2, C: 3},
10161016
}, {
10171017
value: `{a:1,b:2,c:int}`,
10181018
dst: new(fields),
10191019
err: "cannot convert incomplete value",
10201020
}, {
10211021
value: `[]`,
10221022
dst: intList(),
1023-
want: intList(),
1023+
want: *intList(),
10241024
}, {
10251025
value: `[1,2,3]`,
10261026
dst: intList(),
1027-
want: intList(1, 2, 3),
1027+
want: *intList(1, 2, 3),
10281028
}, {
10291029
value: `[x for x in y if x > 1]
10301030
y: [1,2,3]`,
10311031
dst: intList(),
1032-
want: intList(2, 3),
1032+
want: *intList(2, 3),
10331033
}, {
10341034
value: `[int]`,
10351035
err: "cannot convert incomplete value",
10361036
}}
10371037
for _, tc := range testCases {
10381038
t.Run(tc.value, func(t *testing.T) {
1039-
err := getInstance(t, tc.value).Value().Decode(&tc.dst)
1039+
err := getInstance(t, tc.value).Value().Decode(tc.dst)
10401040
checkFatal(t, err, tc.err, "init")
10411041

1042-
if !cmp.Equal(tc.dst, tc.want) {
1043-
t.Error(cmp.Diff(tc.dst, tc.want))
1044-
t.Errorf("\n%#v\n%#v", tc.dst, tc.want)
1042+
got := reflect.ValueOf(tc.dst).Elem().Interface()
1043+
if !cmp.Equal(got, tc.want) {
1044+
t.Error(cmp.Diff(got, tc.want))
1045+
t.Errorf("\n%#v\n%#v", got, tc.want)
10451046
}
10461047
})
10471048
}

0 commit comments

Comments
 (0)