Skip to content

Commit

Permalink
cue/format: add test cases for issue 2496
Browse files Browse the repository at this point in the history
Both supplied by Tony Worm; the first indents too much,
and the second inserts a newline where there was none.

While here, I noticed this indenting bug appears with parentheses
and selectors as well, and I also noticed that we sometimes indent
top-level comments, which seems like a bug as well.

For #2496.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I978f8acf5469e255d026f737c9b39d7098fd30b3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196132
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Aram Hăvărneanu <aram@cue.works>
  • Loading branch information
mvdan committed Jun 14, 2024
1 parent 525e18b commit 59e276a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cue/format/testdata/comments.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,27 @@ foo: [

// an ellipsis
}
-- comment_alone.input --
// Just one comment on its own.
-- comment_alone.golden --
// Just one comment on its own.
-- comment_field.input --
// Just one comment on a field. TODO(mvdan): do not indent.
foo: string
-- comment_field.golden --
// Just one comment on a field. TODO(mvdan): do not indent.
foo: string
-- comments_alone.input --
// Just a few comments
// on their own.
-- comments_alone.golden --
// Just a few comments
// on their own.
-- comments_field.input --
// Just a few comments
// on a field.
foo: string
-- comments_field.golden --
// Just a few comments
// on a field.
foo: string
47 changes: 47 additions & 0 deletions cue/format/testdata/expressions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,50 @@ import "list"
s: [string]: [string]: a
s: [string]: {s: string}
}
-- issue2496.input --
// TODO(mvdan): we indent the list elements too much.
machine_type: [
if arch == "amd" {"n2-standard-2"},
if arch == "arm" {"t2a-standard-2"},
"unknown arch",
][0]

long_field_name: ([
"foo"
])

long_field_name: [
"foo"
].bar

// TODO(mvdan): we insert an empty line between the definitions.
_foo: {
#tool: string
#arch: string

// skip_create_image: true
}
-- issue2496.golden --
// TODO(mvdan): we indent the list elements too much.
machine_type: [
if arch == "amd" {"n2-standard-2"},
if arch == "arm" {"t2a-standard-2"},
"unknown arch",
][0]

long_field_name: ([
"foo",
])

long_field_name: [
"foo",
].bar

// TODO(mvdan): we insert an empty line between the definitions.
_foo: {
#tool: string

#arch: string

// skip_create_image: true
}

0 comments on commit 59e276a

Please sign in to comment.