Skip to content

Commit ebcf2f5

Browse files
committed
cue: change getInstance to getValue
Just getting rid of another instance of the use of Instance. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ia20f95e93a0c85d86d0421b4330649094b34d3b2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193916 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent bae8bbf commit ebcf2f5

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

cue/attribute_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestAttributes(t *testing.T) {
9595
}}
9696
for _, tc := range testCases {
9797
t.Run(tc.path, func(t *testing.T) {
98-
v := getInstance(t, config).Value().LookupPath(ParsePath(tc.path))
98+
v := getValue(t, config).LookupPath(ParsePath(tc.path))
9999
a := v.Attributes(tc.flags)
100100
got := fmt.Sprint(a)
101101
if got != tc.out {
@@ -136,7 +136,7 @@ func TestAttributeErr(t *testing.T) {
136136
}}
137137
for _, tc := range testCases {
138138
t.Run(tc.path+"-"+tc.attr, func(t *testing.T) {
139-
v := getInstance(t, config).Value().Lookup("a", tc.path)
139+
v := getValue(t, config).Lookup("a", tc.path)
140140
a := v.Attribute(tc.attr)
141141
err := a.Err()
142142
if !cmpError(err, tc.err) {
@@ -150,7 +150,7 @@ func TestAttributeName(t *testing.T) {
150150
const config = `
151151
a: 0 @foo(a,b,c=1) @bar()
152152
`
153-
v := getInstance(t, config).Value().Lookup("a")
153+
v := getValue(t, config).Lookup("a")
154154
a := v.Attribute("foo")
155155
if got, want := a.Name(), "foo"; got != want {
156156
t.Errorf("got %v; want %v", got, want)
@@ -207,7 +207,7 @@ func TestAttributeString(t *testing.T) {
207207
}}
208208
for _, tc := range testCases {
209209
t.Run(fmt.Sprintf("%s.%s:%d", tc.path, tc.attr, tc.pos), func(t *testing.T) {
210-
v := getInstance(t, config).Value().Lookup("a", tc.path)
210+
v := getValue(t, config).Lookup("a", tc.path)
211211
a := v.Attribute(tc.attr)
212212
got, err := a.String(tc.pos)
213213
if !cmpError(err, tc.err) {
@@ -267,7 +267,7 @@ func TestAttributeArg(t *testing.T) {
267267
}}
268268
for _, tc := range testCases {
269269
t.Run(fmt.Sprintf("%d", tc.pos), func(t *testing.T) {
270-
v := getInstance(t, config).Value().Lookup("a")
270+
v := getValue(t, config).Lookup("a")
271271
a := v.Attribute("foo")
272272
key, val := a.Arg(tc.pos)
273273
raw := a.RawArg(tc.pos)
@@ -324,7 +324,7 @@ func TestAttributeInt(t *testing.T) {
324324
}}
325325
for _, tc := range testCases {
326326
t.Run(fmt.Sprintf("%s.%s:%d", tc.path, tc.attr, tc.pos), func(t *testing.T) {
327-
v := getInstance(t, config).Value().Lookup("a", tc.path)
327+
v := getValue(t, config).Lookup("a", tc.path)
328328
a := v.Attribute(tc.attr)
329329
got, err := a.Int(tc.pos)
330330
if !cmpError(err, tc.err) {
@@ -381,7 +381,7 @@ func TestAttributeFlag(t *testing.T) {
381381
}}
382382
for _, tc := range testCases {
383383
t.Run(fmt.Sprintf("%s.%s:%d", tc.path, tc.attr, tc.pos), func(t *testing.T) {
384-
v := getInstance(t, config).Value().Lookup("a", tc.path)
384+
v := getValue(t, config).Lookup("a", tc.path)
385385
a := v.Attribute(tc.attr)
386386
got, err := a.Flag(tc.pos, tc.flag)
387387
if !cmpError(err, tc.err) {
@@ -456,7 +456,7 @@ func TestAttributeLookup(t *testing.T) {
456456
}}
457457
for _, tc := range testCases {
458458
t.Run(fmt.Sprintf("%s.%s:%d", tc.path, tc.attr, tc.pos), func(t *testing.T) {
459-
v := getInstance(t, config).Value().Lookup("a", tc.path)
459+
v := getValue(t, config).Lookup("a", tc.path)
460460
a := v.Attribute(tc.attr)
461461
got, _, err := a.Lookup(tc.pos, tc.key)
462462
if !cmpError(err, tc.err) {

cue/decode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestDecode(t *testing.T) {
240240
}}
241241
for _, tc := range testCases {
242242
t.Run(tc.value, func(t *testing.T) {
243-
err := getInstance(t, tc.value).Value().Decode(tc.dst)
243+
err := getValue(t, tc.value).Decode(tc.dst)
244244
checkFatal(t, err, tc.err, "init")
245245

246246
got := reflect.ValueOf(tc.dst).Elem().Interface()
@@ -260,13 +260,13 @@ func TestDecodeIntoCUEValue(t *testing.T) {
260260
var st struct {
261261
X Value `json:"x"`
262262
}
263-
err := getInstance(t, `x: string`).Value().Decode(&st)
263+
err := getValue(t, `x: string`).Decode(&st)
264264
qt.Assert(t, qt.IsNil(err))
265265
qt.Assert(t, qt.Equals(fmt.Sprint(st.X), "string"))
266266

267267
// Check we can decode into a top level value.
268268
var v Value
269-
err = getInstance(t, `int`).Value().Decode(&v)
269+
err = getValue(t, `int`).Decode(&v)
270270
qt.Assert(t, qt.IsNil(err))
271271
qt.Assert(t, qt.Equals(fmt.Sprint(v), "int"))
272272
}

cue/types_test.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"cuelang.org/go/internal/tdtest"
3737
)
3838

39-
func getInstance(t *testing.T, body string) *Instance {
39+
func getValue(t *testing.T, body string) Value {
4040
t.Helper()
4141

4242
var r Runtime // TODO: use Context and return Value
@@ -45,7 +45,7 @@ func getInstance(t *testing.T, body string) *Instance {
4545
if err != nil {
4646
t.Fatalf("unexpected parse error: %v", err)
4747
}
48-
return inst
48+
return inst.Value()
4949
}
5050

5151
func TestAPI(t *testing.T) {
@@ -340,7 +340,7 @@ func TestValueType(t *testing.T) {
340340
}}
341341
for _, tc := range testCases {
342342
t.Run(tc.value, func(t *testing.T) {
343-
inst := getInstance(t, tc.value)
343+
inst := getValue(t, tc.value)
344344
v := inst.Lookup("v")
345345
if got := v.Kind(); got != tc.kind {
346346
t.Errorf("Kind: got %x; want %x", int(got), int(tc.kind))
@@ -407,7 +407,7 @@ func TestInt(t *testing.T) {
407407
}}
408408
for _, tc := range testCases {
409409
t.Run(tc.value, func(t *testing.T) {
410-
n := getInstance(t, tc.value).Value()
410+
n := getValue(t, tc.value)
411411
base := 10
412412
if tc.base > 0 {
413413
base = tc.base
@@ -546,7 +546,7 @@ func TestFloat(t *testing.T) {
546546
}}
547547
for _, tc := range testCases {
548548
t.Run(tc.value, func(t *testing.T) {
549-
n := getInstance(t, tc.value).Value()
549+
n := getValue(t, tc.value)
550550
if n.Kind() != tc.kind {
551551
t.Fatal("Not a number")
552552
}
@@ -597,19 +597,19 @@ func TestString(t *testing.T) {
597597
}}
598598
for _, tc := range testCases {
599599
t.Run(tc.value, func(t *testing.T) {
600-
str, err := getInstance(t, tc.value).Value().String()
600+
str, err := getValue(t, tc.value).String()
601601
checkFatal(t, err, tc.err, "init")
602602
if str != tc.str {
603603
t.Errorf("String: got %q; want %q", str, tc.str)
604604
}
605605

606-
b, err := getInstance(t, tc.value).Value().Bytes()
606+
b, err := getValue(t, tc.value).Bytes()
607607
checkFatal(t, err, tc.err, "init")
608608
if got := string(b); got != tc.str {
609609
t.Errorf("Bytes: got %q; want %q", got, tc.str)
610610
}
611611

612-
r, err := getInstance(t, tc.value).Value().Reader()
612+
r, err := getValue(t, tc.value).Reader()
613613
checkFatal(t, err, tc.err, "init")
614614
b, _ = io.ReadAll(r)
615615
if got := string(b); got != tc.str {
@@ -634,7 +634,7 @@ func TestError(t *testing.T) {
634634
}}
635635
for _, tc := range testCases {
636636
t.Run(tc.value, func(t *testing.T) {
637-
err := getInstance(t, tc.value).Value().Err()
637+
err := getValue(t, tc.value).Err()
638638
checkErr(t, err, tc.err, "init")
639639
})
640640
}
@@ -658,7 +658,7 @@ func TestNull(t *testing.T) {
658658
}}
659659
for _, tc := range testCases {
660660
t.Run(tc.value, func(t *testing.T) {
661-
v := getInstance(t, tc.value).Lookup("v")
661+
v := getValue(t, tc.value).Lookup("v")
662662
err := v.Null()
663663
checkErr(t, err, tc.err, "init")
664664
wantBool := err == nil
@@ -692,7 +692,7 @@ func TestBool(t *testing.T) {
692692
}}
693693
for _, tc := range testCases {
694694
t.Run(tc.value, func(t *testing.T) {
695-
got, err := getInstance(t, tc.value).Value().Bool()
695+
got, err := getValue(t, tc.value).Bool()
696696
if checkErr(t, err, tc.err, "init") {
697697
if got != tc.bool {
698698
t.Errorf("got %v; want %v", got, tc.bool)
@@ -729,7 +729,7 @@ func TestList(t *testing.T) {
729729
}}
730730
for _, tc := range testCases {
731731
t.Run(tc.value, func(t *testing.T) {
732-
l, err := getInstance(t, tc.value).Value().List()
732+
l, err := getValue(t, tc.value).List()
733733
checkFatal(t, err, tc.err, "init")
734734

735735
buf := []byte{'['}
@@ -829,7 +829,7 @@ func TestFields(t *testing.T) {
829829
}}
830830
for _, tc := range testCases {
831831
t.Run(tc.value, func(t *testing.T) {
832-
obj := getInstance(t, tc.value).Value()
832+
obj := getValue(t, tc.value)
833833

834834
iter, err := obj.Fields(tc.opts...)
835835
checkFatal(t, err, tc.err, "init")
@@ -890,7 +890,7 @@ func TestAllFields(t *testing.T) {
890890
}}
891891
for _, tc := range testCases {
892892
t.Run(tc.value, func(t *testing.T) {
893-
obj := getInstance(t, tc.value).Value()
893+
obj := getValue(t, tc.value)
894894

895895
var iter *Iterator // Verify that the returned iterator is a pointer.
896896
iter, err := obj.Fields(All())
@@ -934,7 +934,7 @@ func TestFieldType(t *testing.T) {
934934
}}
935935
for _, tc := range testCases {
936936
t.Run(tc.value, func(t *testing.T) {
937-
obj := getInstance(t, tc.value).Value()
937+
obj := getValue(t, tc.value)
938938

939939
iter, err := obj.Fields(All())
940940
if err != nil {
@@ -1768,7 +1768,7 @@ func TestDefaults(t *testing.T) {
17681768
}}
17691769
for _, tc := range testCases {
17701770
t.Run(tc.value, func(t *testing.T) {
1771-
v := getInstance(t, "a: "+tc.value).Lookup("a")
1771+
v := getValue(t, "a: "+tc.value).Lookup("a")
17721772

17731773
v = v.Eval()
17741774
d, ok := v.Default()
@@ -1821,7 +1821,7 @@ func TestLen(t *testing.T) {
18211821
}}
18221822
for _, tc := range testCases {
18231823
t.Run(tc.input, func(t *testing.T) {
1824-
v := getInstance(t, "a: "+tc.input).Lookup("a")
1824+
v := getValue(t, "a: "+tc.input).Lookup("a")
18251825

18261826
length := v.Len()
18271827
if got := fmt.Sprint(length); got != tc.length {
@@ -1870,7 +1870,7 @@ func TestTemplate(t *testing.T) {
18701870
}}
18711871
for _, tc := range testCases {
18721872
t.Run("", func(t *testing.T) {
1873-
v := getInstance(t, tc.value).Value()
1873+
v := getValue(t, tc.value)
18741874
for _, p := range tc.path {
18751875
if p == "" {
18761876
v = v.Template()("label")
@@ -1928,7 +1928,7 @@ func TestElem(t *testing.T) {
19281928
}}
19291929
for _, tc := range testCases {
19301930
t.Run("", func(t *testing.T) {
1931-
v := getInstance(t, tc.value).Value()
1931+
v := getValue(t, tc.value)
19321932
v.v.Finalize(v.ctx()) // TODO: do in instance.
19331933
for _, p := range tc.path {
19341934
if p == "" {
@@ -2057,7 +2057,7 @@ func TestSubsume(t *testing.T) {
20572057
}}
20582058
for _, tc := range testCases {
20592059
t.Run(tc.value, func(t *testing.T) {
2060-
v := getInstance(t, tc.value)
2060+
v := getValue(t, tc.value)
20612061
a := v.Value().LookupPath(tc.pathA)
20622062
b := v.Value().LookupPath(tc.pathB)
20632063
got := a.Subsume(b, tc.options...) == nil
@@ -2120,7 +2120,7 @@ func TestSubsumes(t *testing.T) {
21202120
}}
21212121
for _, tc := range testCases {
21222122
t.Run(tc.value, func(t *testing.T) {
2123-
v := getInstance(t, tc.value)
2123+
v := getValue(t, tc.value)
21242124
a := v.Lookup(tc.pathA...)
21252125
b := v.Lookup(tc.pathB...)
21262126
got := a.Subsumes(b)
@@ -2191,7 +2191,7 @@ func TestUnify(t *testing.T) {
21912191
}}
21922192
// TODO(tdtest): use cuetest.Run when supported.
21932193
tdtest.Run(t, testCases, func(t *cuetest.T, tc *testCase) {
2194-
v := getInstance(t.T, tc.value).Value()
2194+
v := getValue(t.T, tc.value)
21952195
x := v.LookupPath(ParsePath(tc.pathA))
21962196
y := v.LookupPath(ParsePath(tc.pathB))
21972197
b, err := x.Unify(y).MarshalJSON()
@@ -2243,7 +2243,7 @@ func TestUnifyAccept(t *testing.T) {
22432243
}}
22442244
// TODO(tdtest): use cuetest.Run when supported.
22452245
tdtest.Run(t, testCases, func(t *cuetest.T, tc *testCase) {
2246-
v := getInstance(t.T, tc.value).Value()
2246+
v := getValue(t.T, tc.value)
22472247
x := v.LookupPath(ParsePath("#v"))
22482248
y := v.LookupPath(ParsePath("#w"))
22492249
a := v.LookupPath(ParsePath("#accept"))
@@ -2584,7 +2584,7 @@ func TestValueLookup(t *testing.T) {
25842584
}}
25852585
for _, tc := range testCases {
25862586
t.Run(tc.str, func(t *testing.T) {
2587-
v := getInstance(t, tc.config).Value().Lookup(tc.path...)
2587+
v := getValue(t, tc.config).Lookup(tc.path...)
25882588
if got := !v.Exists(); got != tc.notExists {
25892589
t.Errorf("exists: got %v; want %v", got, tc.notExists)
25902590
}
@@ -2929,7 +2929,7 @@ func TestMarshalJSON(t *testing.T) {
29292929
}}
29302930
for i, tc := range testCases {
29312931
t.Run(fmt.Sprintf("%d/%v", i, tc.value), func(t *testing.T) {
2932-
inst := getInstance(t, tc.value)
2932+
inst := getValue(t, tc.value)
29332933
b, err := inst.Value().MarshalJSON()
29342934
checkFatal(t, err, tc.err, "init")
29352935

@@ -3005,7 +3005,7 @@ func TestWalk(t *testing.T) {
30053005
}}
30063006
for i, tc := range testCases {
30073007
t.Run(fmt.Sprintf("%d/%v", i, tc.value), func(t *testing.T) {
3008-
inst := getInstance(t, tc.value)
3008+
inst := getValue(t, tc.value)
30093009
buf := []byte{}
30103010
stripComma := func() {
30113011
if n := len(buf) - 1; buf[n] == ',' {
@@ -3749,7 +3749,7 @@ func TestExpr(t *testing.T) {
37493749
}}
37503750
for _, tc := range testCases {
37513751
t.Run(tc.input, func(t *testing.T) {
3752-
v := getInstance(t, tc.input).Lookup("v")
3752+
v := getValue(t, tc.input).Lookup("v")
37533753
got := exprStr(v)
37543754
if got != tc.want {
37553755
t.Errorf("\n got %v;\nwant %v", got, tc.want)

0 commit comments

Comments
 (0)