From 996ee0b4336d06f59c029a69039de49b529b257e Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 8 Oct 2020 12:42:11 +0200 Subject: [PATCH] add test for key order --- cmd/read_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/read_test.go b/cmd/read_test.go index a51af624..544fdb89 100644 --- a/cmd/read_test.go +++ b/cmd/read_test.go @@ -1441,3 +1441,23 @@ func TestReadFindValueDeepObjectCmd(t *testing.T) { ` test.AssertResult(t, expectedOutput, result.Output) } + +func TestReadKeepsKeyOrderInJson(t *testing.T) { + const content = `{ + "z": "One", + "a": 1, + "w": ["a", "r"], + "u": {"d": "o", "0": 11.5}, +}` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("r -j %s", filename)) + if result.Error != nil { + t.Error(result.Error) + } + + expectedOutput := `{"z":"One","a":1,"w":["a","r"],"u":{"d":"o","0":11.5}} +` + test.AssertResult(t, expectedOutput, result.Output) +}