...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package cuecontext
16
17 import (
18 "fmt"
19 "testing"
20
21 "cuelang.org/go/cue"
22 "cuelang.org/go/cue/ast"
23 )
24
25 func TestAPI(t *testing.T) {
26 testCases := []struct {
27 name string
28 fun func() cue.Value
29 want string
30 }{{
31 name: "issue1204",
32 fun: func() cue.Value {
33 ctx := New()
34 expr := ast.NewCall(ast.NewIdent("close"), ast.NewStruct())
35 return ctx.BuildExpr(expr)
36 },
37 want: `close({})`,
38 }, {
39 name: "issue1131",
40 fun: func() cue.Value {
41 m := make(map[string]interface{})
42 ctx := New()
43 cv := ctx.Encode(m)
44 return cv
45 },
46 want: "",
47 }}
48 for _, tc := range testCases {
49 t.Run(tc.name, func(t *testing.T) {
50 got := fmt.Sprintf("%#v", tc.fun())
51 if got != tc.want {
52 t.Errorf("got:\n%v;\nwant:\n%v", got, tc.want)
53 }
54 })
55 }
56 }
57
58
59
60 func TestConcurrency(t *testing.T) {
61 c := New()
62 go func() {
63 c.CompileString(`
64 package foo
65 a: 1
66 `)
67 }()
68 go func() {
69 c.CompileString(`
70 package bar
71 a: 2
72 `)
73 }()
74 }
75
View as plain text