Skip to content

Commit

Permalink
cmd/cue: add tests for the loss of comments with cue def
Browse files Browse the repository at this point in the history
This adds tests that will be fixed in subsequent CLs.

This change re-applies CL 1204109 as we didn't merge it properly
the first time.

Change-Id: I95baee62032fc65274451bfcbabd6425b5b1e6cd
Signed-off-by: haoqixu <hq.xu0o0@gmail.com>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1204109
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1204839
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
haoqixu authored and mvdan committed Nov 28, 2024
1 parent ede6de0 commit b1f4f09
Showing 1 changed file with 281 additions and 0 deletions.
281 changes: 281 additions & 0 deletions cmd/cue/cmd/testdata/script/def_comments.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
exec cue def 1.cue
cmp stdout stdout-1.cue

exec cue def 2.cue
cmp stdout stdout-2.cue

exec cue def 2.cue -p t
cmp stdout stdout-2-pkg.cue

exec cue def 1.cue 2.cue
cmp stdout stdout-1_2.cue

exec cue def 2.cue 1.cue
cmp stdout stdout-2_1.cue

exec cue def 1.cue 3.cue
cmp stdout stdout-1_3.cue

exec cue def 3.cue 1.cue
cmp stdout stdout-3_1.cue

exec cue def 2.cue 4.cue
cmp stdout stdout-2_4.cue

exec cue def 2.cue 4.cue -p t
cmp stdout stdout-2_4-pkg.cue

# title and top description are lost
exec cue def -l '#top:' jsonschema: schema1.json
cmp stdout stdout1-def

exec cue def jsonschema: schema1.json
cmp stdout stdout1

# title and top description override a description
exec cue def -l '#top:' jsonschema: schema2.json
cmp stdout stdout2-def

exec cue def jsonschema: schema2.json
cmp stdout stdout2

# description of definition is lost
exec cue def -l '#top:' issue3522.json
stdout 'description of a field'
stdout 'overall description'
! stdout 'description of foo'

exec cue def issue3522.json
stdout 'description of a field'
stdout 'overall description'
! stdout 'description of foo'

-- issue3522.json --
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$defs": {
"foo": {
"description": "description of foo",
"properties": {
"a": {
"description": "description of a field",
"type": "number"
}
}
}
},
"description": "overall description",
"$ref": "#/$defs/foo"
}
-- schema1.json --
{
"title": "This is a title",
"description": "top description",
"properties": {
"a": {
"type": "object",
"description": "a description",
"properties": {
"b": {
"description": "b description",
"type": "number"
}
}
}
}
}
-- stdout1 --
null | bool | number | string | [...] | {
// a description
a?: {
// b description
b?: number
...
}
...
}
-- stdout1-def --
#top: null | bool | number | string | [...] | {
// a description
a?: {
// b description
b?: number
...
}
...
}
-- schema2.json --
{
"title": "This is a title",
"description": "top description",
"type": "object",
"properties": {
"a": {
"type": "object",
"description": "a description",
"properties": {
"b": {
"description": "b description",
"type": "number"
}
}
}
}
}
-- stdout2 --
// This is a title
//
// top description
a?: {
// b description
b?: number
...
}
...
-- stdout2-def --
#top: {
// This is a title
//
// top description
a?: {
// b description
b?: number
...
}
...
}
-- 1.cue --
// 1.cue: file comment

// 1.cue: pkg doc comment
package t // 1.cue: pkg comment 1

// 1.cue: pkg comment 2

// 1.cue: d comment
d: 1

// 1.cue: d comment 1

di: 1
dii: 1

-- 2.cue --
// 2.cue: doc comment

// 2.cue: file comment 1

// 2.cue: file comment 2

// 2.cue: d
d: 1
di: 1
dii: 1

-- 3.cue --
// 3.cue: pkg doc comment
package t

// 3.cue: pkg comment 1

// 3.cue: d comment
d: 1
di: 1
dii: 1
-- 4.cue --
// 4.cue: doc comment

// 4.cue: file comment 1

// 4.cue: file comment 2

// 4.cue: d
d: 1
di: 1
dii: 1

-- stdout-1.cue --
// 1.cue: pkg doc comment
package t

// 1.cue: d comment
d: 1
di: 1
dii: 1
-- stdout-2.cue --
// 2.cue: d
d: 1
di: 1
dii: 1
-- stdout-2-pkg.cue --
package t

// 2.cue: d
d: 1
di: 1
dii: 1
-- stdout-3.cue --
-- stdout-1_2.cue --
// 1.cue: pkg doc comment

// 2.cue: file comment 2
package t

// 1.cue: d comment

// 2.cue: d
d: 1
di: 1
dii: 1
-- stdout-2_1.cue --
// 1.cue: pkg doc comment

// 2.cue: file comment 2
package t

// 1.cue: d comment

// 2.cue: d
d: 1
di: 1
dii: 1
-- stdout-1_3.cue --
// 1.cue: pkg doc comment

// 3.cue: pkg doc comment
package t

// 1.cue: d comment

// 3.cue: d comment
d: 1
di: 1
dii: 1
-- stdout-3_1.cue --
// 1.cue: pkg doc comment

// 3.cue: pkg doc comment
package t

// 1.cue: d comment

// 3.cue: d comment
d: 1
di: 1
dii: 1
-- stdout-2_4.cue --
// 2.cue: d

// 4.cue: d
d: 1
di: 1
dii: 1
-- stdout-2_4-pkg.cue --
package t

// 2.cue: d

// 4.cue: d
d: 1
di: 1
dii: 1

0 comments on commit b1f4f09

Please sign in to comment.