@@ -36,7 +36,7 @@ import (
36
36
"cuelang.org/go/internal/tdtest"
37
37
)
38
38
39
- func getInstance (t * testing.T , body string ) * Instance {
39
+ func getValue (t * testing.T , body string ) Value {
40
40
t .Helper ()
41
41
42
42
var r Runtime // TODO: use Context and return Value
@@ -45,7 +45,7 @@ func getInstance(t *testing.T, body string) *Instance {
45
45
if err != nil {
46
46
t .Fatalf ("unexpected parse error: %v" , err )
47
47
}
48
- return inst
48
+ return inst . Value ()
49
49
}
50
50
51
51
func TestAPI (t * testing.T ) {
@@ -340,7 +340,7 @@ func TestValueType(t *testing.T) {
340
340
}}
341
341
for _ , tc := range testCases {
342
342
t .Run (tc .value , func (t * testing.T ) {
343
- inst := getInstance (t , tc .value )
343
+ inst := getValue (t , tc .value )
344
344
v := inst .Lookup ("v" )
345
345
if got := v .Kind (); got != tc .kind {
346
346
t .Errorf ("Kind: got %x; want %x" , int (got ), int (tc .kind ))
@@ -407,7 +407,7 @@ func TestInt(t *testing.T) {
407
407
}}
408
408
for _ , tc := range testCases {
409
409
t .Run (tc .value , func (t * testing.T ) {
410
- n := getInstance (t , tc .value ). Value ( )
410
+ n := getValue (t , tc .value )
411
411
base := 10
412
412
if tc .base > 0 {
413
413
base = tc .base
@@ -546,7 +546,7 @@ func TestFloat(t *testing.T) {
546
546
}}
547
547
for _ , tc := range testCases {
548
548
t .Run (tc .value , func (t * testing.T ) {
549
- n := getInstance (t , tc .value ). Value ( )
549
+ n := getValue (t , tc .value )
550
550
if n .Kind () != tc .kind {
551
551
t .Fatal ("Not a number" )
552
552
}
@@ -597,19 +597,19 @@ func TestString(t *testing.T) {
597
597
}}
598
598
for _ , tc := range testCases {
599
599
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 ()
601
601
checkFatal (t , err , tc .err , "init" )
602
602
if str != tc .str {
603
603
t .Errorf ("String: got %q; want %q" , str , tc .str )
604
604
}
605
605
606
- b , err := getInstance (t , tc .value ). Value ( ).Bytes ()
606
+ b , err := getValue (t , tc .value ).Bytes ()
607
607
checkFatal (t , err , tc .err , "init" )
608
608
if got := string (b ); got != tc .str {
609
609
t .Errorf ("Bytes: got %q; want %q" , got , tc .str )
610
610
}
611
611
612
- r , err := getInstance (t , tc .value ). Value ( ).Reader ()
612
+ r , err := getValue (t , tc .value ).Reader ()
613
613
checkFatal (t , err , tc .err , "init" )
614
614
b , _ = io .ReadAll (r )
615
615
if got := string (b ); got != tc .str {
@@ -634,7 +634,7 @@ func TestError(t *testing.T) {
634
634
}}
635
635
for _ , tc := range testCases {
636
636
t .Run (tc .value , func (t * testing.T ) {
637
- err := getInstance (t , tc .value ). Value ( ).Err ()
637
+ err := getValue (t , tc .value ).Err ()
638
638
checkErr (t , err , tc .err , "init" )
639
639
})
640
640
}
@@ -658,7 +658,7 @@ func TestNull(t *testing.T) {
658
658
}}
659
659
for _ , tc := range testCases {
660
660
t .Run (tc .value , func (t * testing.T ) {
661
- v := getInstance (t , tc .value ).Lookup ("v" )
661
+ v := getValue (t , tc .value ).Lookup ("v" )
662
662
err := v .Null ()
663
663
checkErr (t , err , tc .err , "init" )
664
664
wantBool := err == nil
@@ -692,7 +692,7 @@ func TestBool(t *testing.T) {
692
692
}}
693
693
for _ , tc := range testCases {
694
694
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 ()
696
696
if checkErr (t , err , tc .err , "init" ) {
697
697
if got != tc .bool {
698
698
t .Errorf ("got %v; want %v" , got , tc .bool )
@@ -729,7 +729,7 @@ func TestList(t *testing.T) {
729
729
}}
730
730
for _ , tc := range testCases {
731
731
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 ()
733
733
checkFatal (t , err , tc .err , "init" )
734
734
735
735
buf := []byte {'[' }
@@ -829,7 +829,7 @@ func TestFields(t *testing.T) {
829
829
}}
830
830
for _ , tc := range testCases {
831
831
t .Run (tc .value , func (t * testing.T ) {
832
- obj := getInstance (t , tc .value ). Value ( )
832
+ obj := getValue (t , tc .value )
833
833
834
834
iter , err := obj .Fields (tc .opts ... )
835
835
checkFatal (t , err , tc .err , "init" )
@@ -890,7 +890,7 @@ func TestAllFields(t *testing.T) {
890
890
}}
891
891
for _ , tc := range testCases {
892
892
t .Run (tc .value , func (t * testing.T ) {
893
- obj := getInstance (t , tc .value ). Value ( )
893
+ obj := getValue (t , tc .value )
894
894
895
895
var iter * Iterator // Verify that the returned iterator is a pointer.
896
896
iter , err := obj .Fields (All ())
@@ -934,7 +934,7 @@ func TestFieldType(t *testing.T) {
934
934
}}
935
935
for _ , tc := range testCases {
936
936
t .Run (tc .value , func (t * testing.T ) {
937
- obj := getInstance (t , tc .value ). Value ( )
937
+ obj := getValue (t , tc .value )
938
938
939
939
iter , err := obj .Fields (All ())
940
940
if err != nil {
@@ -1768,7 +1768,7 @@ func TestDefaults(t *testing.T) {
1768
1768
}}
1769
1769
for _ , tc := range testCases {
1770
1770
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" )
1772
1772
1773
1773
v = v .Eval ()
1774
1774
d , ok := v .Default ()
@@ -1821,7 +1821,7 @@ func TestLen(t *testing.T) {
1821
1821
}}
1822
1822
for _ , tc := range testCases {
1823
1823
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" )
1825
1825
1826
1826
length := v .Len ()
1827
1827
if got := fmt .Sprint (length ); got != tc .length {
@@ -1870,7 +1870,7 @@ func TestTemplate(t *testing.T) {
1870
1870
}}
1871
1871
for _ , tc := range testCases {
1872
1872
t .Run ("" , func (t * testing.T ) {
1873
- v := getInstance (t , tc .value ). Value ( )
1873
+ v := getValue (t , tc .value )
1874
1874
for _ , p := range tc .path {
1875
1875
if p == "" {
1876
1876
v = v .Template ()("label" )
@@ -1928,7 +1928,7 @@ func TestElem(t *testing.T) {
1928
1928
}}
1929
1929
for _ , tc := range testCases {
1930
1930
t .Run ("" , func (t * testing.T ) {
1931
- v := getInstance (t , tc .value ). Value ( )
1931
+ v := getValue (t , tc .value )
1932
1932
v .v .Finalize (v .ctx ()) // TODO: do in instance.
1933
1933
for _ , p := range tc .path {
1934
1934
if p == "" {
@@ -2057,7 +2057,7 @@ func TestSubsume(t *testing.T) {
2057
2057
}}
2058
2058
for _ , tc := range testCases {
2059
2059
t .Run (tc .value , func (t * testing.T ) {
2060
- v := getInstance (t , tc .value )
2060
+ v := getValue (t , tc .value )
2061
2061
a := v .Value ().LookupPath (tc .pathA )
2062
2062
b := v .Value ().LookupPath (tc .pathB )
2063
2063
got := a .Subsume (b , tc .options ... ) == nil
@@ -2120,7 +2120,7 @@ func TestSubsumes(t *testing.T) {
2120
2120
}}
2121
2121
for _ , tc := range testCases {
2122
2122
t .Run (tc .value , func (t * testing.T ) {
2123
- v := getInstance (t , tc .value )
2123
+ v := getValue (t , tc .value )
2124
2124
a := v .Lookup (tc .pathA ... )
2125
2125
b := v .Lookup (tc .pathB ... )
2126
2126
got := a .Subsumes (b )
@@ -2191,7 +2191,7 @@ func TestUnify(t *testing.T) {
2191
2191
}}
2192
2192
// TODO(tdtest): use cuetest.Run when supported.
2193
2193
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 )
2195
2195
x := v .LookupPath (ParsePath (tc .pathA ))
2196
2196
y := v .LookupPath (ParsePath (tc .pathB ))
2197
2197
b , err := x .Unify (y ).MarshalJSON ()
@@ -2243,7 +2243,7 @@ func TestUnifyAccept(t *testing.T) {
2243
2243
}}
2244
2244
// TODO(tdtest): use cuetest.Run when supported.
2245
2245
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 )
2247
2247
x := v .LookupPath (ParsePath ("#v" ))
2248
2248
y := v .LookupPath (ParsePath ("#w" ))
2249
2249
a := v .LookupPath (ParsePath ("#accept" ))
@@ -2584,7 +2584,7 @@ func TestValueLookup(t *testing.T) {
2584
2584
}}
2585
2585
for _ , tc := range testCases {
2586
2586
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 ... )
2588
2588
if got := ! v .Exists (); got != tc .notExists {
2589
2589
t .Errorf ("exists: got %v; want %v" , got , tc .notExists )
2590
2590
}
@@ -2929,7 +2929,7 @@ func TestMarshalJSON(t *testing.T) {
2929
2929
}}
2930
2930
for i , tc := range testCases {
2931
2931
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 )
2933
2933
b , err := inst .Value ().MarshalJSON ()
2934
2934
checkFatal (t , err , tc .err , "init" )
2935
2935
@@ -3005,7 +3005,7 @@ func TestWalk(t *testing.T) {
3005
3005
}}
3006
3006
for i , tc := range testCases {
3007
3007
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 )
3009
3009
buf := []byte {}
3010
3010
stripComma := func () {
3011
3011
if n := len (buf ) - 1 ; buf [n ] == ',' {
@@ -3749,7 +3749,7 @@ func TestExpr(t *testing.T) {
3749
3749
}}
3750
3750
for _ , tc := range testCases {
3751
3751
t .Run (tc .input , func (t * testing.T ) {
3752
- v := getInstance (t , tc .input ).Lookup ("v" )
3752
+ v := getValue (t , tc .input ).Lookup ("v" )
3753
3753
got := exprStr (v )
3754
3754
if got != tc .want {
3755
3755
t .Errorf ("\n got %v;\n want %v" , got , tc .want )
0 commit comments