Skip to content

Commit

Permalink
cmd/cue: add tests that cover fmt on various filetypes
Browse files Browse the repository at this point in the history
I will soon refactor fmt slightly to no longer use internal/encoding,
so I want to make sure we don't add unintended regressions.
A couple of these are probably not the right behavior, hence the TODOs.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: Ife85cb31a0f2414dca42345d99c6390d748ff3c9
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194199
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Noam Dolovich <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
  • Loading branch information
mvdan committed May 3, 2024
1 parent b2dd75a commit 7e0fbec
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions cmd/cue/cmd/testdata/script/fmt_filetypes.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Verify how fmt behaves with different encodings.

exec cue fmt --diff input.cue
cmp stdout input.cue.diff

# Unknown file extensions fail on their own
! exec cue fmt --diff input.cue-unknown
stderr 'unknown file extension'

# Unknown file extensions work if we specify them as CUE.
cp input.cue input.cue-unknown
exec cue fmt --diff cue: input.cue-unknown
cmp stdout input.cue-unknown.diff

# TODO(mvdan): we should probably fail rather than doing nothing.
exec cue fmt --diff input.json
! stdout .
! stderr .

# JSON is valid CUE syntax, so it can be formatted as CUE, if one wants to.
exec cue fmt --diff cue: input.json
cmp stdout input.json.diff

# TODO(mvdan): we should probably fail rather than doing nothing.
exec cue fmt --diff input.yaml
! stdout .
! stderr .

# YAML in this case is not valid CUE.
! exec cue fmt --diff cue: input.yaml
stderr 'in struct literal'

-- input.cue --
foo: "bar"
-- input.cue.diff --
diff input.cue.orig input.cue
--- input.cue.orig
+++ input.cue
@@ -1,1 +1,1 @@
-foo: "bar"
+foo: "bar"

-- input.cue-unknown.diff --
diff input.cue-unknown.orig input.cue-unknown
--- input.cue-unknown.orig
+++ input.cue-unknown
@@ -1,1 +1,1 @@
-foo: "bar"
+foo: "bar"

-- input.json --
{"foo": "bar"}
-- input.json.diff --
diff input.json.orig input.json
--- input.json.orig
+++ input.json
@@ -1,1 +1,1 @@
-{"foo": "bar"}
+{"foo": "bar"}

-- input.yaml --
foo:
- unquoted bar

0 comments on commit 7e0fbec

Please sign in to comment.