Skip to content

Commit ce37bb5

Browse files
committed
cmd/cue: add test case for get go with string escape codes
The added test case fails currently: > exec cue get go --local ./decls [...] > exec cue vet go_marshal.json schema.cue [stderr] #ErrorPrefix: invalid string: invalid syntax: ./decls/p_go_gen.cue:14:15 #ResetColor: invalid string: invalid syntax: ./decls/p_go_gen.cue:16:14 The following commit will include the fix. For #2915. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ib1882499b6c7064ad4fd60d0c1d92cf338c7e901 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211574 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent b75a12c commit ce37bb5

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

cmd/cue/cmd/testdata/script/get_go_json_compat.txtar

+33-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ cmp decls/p_go_gen.cue decls/p_go_gen.cue.golden
88
exec go run ./marshal
99
cp stdout go_marshal.json
1010
cmp go_marshal.json go_marshal.json.golden
11-
exec cue vet go_marshal.json schema.cue
11+
! exec cue vet go_marshal.json schema.cue
1212

1313
# Export from CUE and Unmarshal via Go's encoding/json.
14-
exec cue export ./decls
15-
cmp stdout cue_export.json.golden
16-
stdin stdout
17-
exec go run ./unmarshal
14+
! exec cue export ./decls
15+
# cmp stdout cue_export.json.golden
16+
# stdin stdout
17+
# exec go run ./unmarshal
1818

1919
-- schema.cue --
2020
package schema
@@ -35,12 +35,21 @@ package decls
3535

3636
#Root & {
3737
Duration: #ValueSecond
38+
39+
Strings: [
40+
#ErrorPrefix,
41+
#ResetColor,
42+
]
3843
}
3944
-- go_marshal.json.golden --
40-
{"Duration":3000000000}
45+
{"Duration":3000000000,"Strings":["\u001b[31mError:\u001b[0m","\u001b[0m"]}
4146
-- cue_export.json.golden --
4247
{
43-
"Duration": 3000000000
48+
"Duration": 3000000000,
49+
"Strings": [
50+
"\u001b[31mError:\u001b[0m",
51+
"\u001b[0m"
52+
]
4453
}
4554
-- decls/p.go --
4655
package decls
@@ -49,9 +58,14 @@ import "time"
4958

5059
type Root struct {
5160
Duration time.Duration
61+
62+
Strings []string
5263
}
5364

5465
const ValueSecond = 3 * time.Second
66+
67+
const ErrorPrefix = "\033[31mError:\033[0m"
68+
const ResetColor = "\u001b[0m"
5569
-- decls/p_go_gen.cue.golden --
5670
// Code generated by cue get go. DO NOT EDIT.
5771

@@ -61,9 +75,14 @@ package decls
6175

6276
#Root: {
6377
Duration: int @go(,time.Duration)
78+
Strings: [...string] @go(,[]string)
6479
}
6580

6681
#ValueSecond: int & 3000000000
82+
83+
#ErrorPrefix: "\x1b[31mError:\x1b[0m" // "\033[31mError:\033[0m"
84+
85+
#ResetColor: "\x1b[0m" // "\u001b[0m"
6786
-- marshal/main.go --
6887
package main
6988

@@ -76,7 +95,13 @@ import (
7695
)
7796

7897
func main() {
79-
r := decls.Root{Duration: decls.ValueSecond}
98+
r := decls.Root{
99+
Duration: decls.ValueSecond,
100+
Strings: []string{
101+
decls.ErrorPrefix,
102+
decls.ResetColor,
103+
},
104+
}
80105
data, err := json.Marshal(r)
81106
if err != nil {
82107
log.Fatal(err)

0 commit comments

Comments
 (0)